From 2d119a1b6e9c7cfa2a899fd11724a97e9861503c Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Wed, 17 Jan 2024 10:33:09 +0000 Subject: [PATCH] [test,uart] Simplify UART pinmux to two external channels Signed-off-by: James Wainwright --- sw/device/lib/testing/uart_testutils.c | 122 ++++++++++++------------- sw/device/lib/testing/uart_testutils.h | 13 ++- sw/device/tests/uart_tx_rx_test.c | 3 +- 3 files changed, 71 insertions(+), 67 deletions(-) diff --git a/sw/device/lib/testing/uart_testutils.c b/sw/device/lib/testing/uart_testutils.c index 5f0aec25a3169..e5661c7b7049e 100644 --- a/sw/device/lib/testing/uart_testutils.c +++ b/sw/device/lib/testing/uart_testutils.c @@ -53,85 +53,77 @@ static const pinmux_testutils_peripheral_pin_t kUartPinmuxPins[] = { * This is used to connect UART instances to mio pins based on the platform. */ static const pinmux_testutils_mio_pin_t - kUartPlatformPins[UartPinmuxPlatformIdCount][4] = { + kUartPlatformPins[UartPinmuxPlatformIdCount][UartPinmuxChannelCount] = { // Hyper310 bitstream. [UartPinmuxPlatformIdHyper310] = - {// UART0. - { - .mio_out = kTopEarlgreyPinmuxMioOutIoc4, - .insel = kTopEarlgreyPinmuxInselIoc3, - }, - // UART1. - { - .mio_out = kTopEarlgreyPinmuxMioOutIoc4, - .insel = kTopEarlgreyPinmuxInselIoc3, - }, - // UART2. - { - .mio_out = kTopEarlgreyPinmuxMioOutIoc4, - .insel = kTopEarlgreyPinmuxInselIoc3, - }, - // UART3. - { - .mio_out = kTopEarlgreyPinmuxMioOutIoc4, - .insel = kTopEarlgreyPinmuxInselIoc3, - }}, + {[UartPinmuxChannelConsole] = + { + .mio_out = kTopEarlgreyPinmuxMioOutIoc4, + .insel = kTopEarlgreyPinmuxInselIoc3, + }, + // FIXME: select the other available pins. + [UartPinmuxChannelDut] = + { + .mio_out = kTopEarlgreyPinmuxMioOutIob5, + .insel = kTopEarlgreyPinmuxInselIob4, + }}, // Silicon. - [UartPinmuxPlatformIdSilicon] = - {// UART0. - { - .mio_out = kTopEarlgreyPinmuxMioOutIoc4, - .insel = kTopEarlgreyPinmuxInselIoc3, - }, - // UART1. - { - .mio_out = kTopEarlgreyPinmuxMioOutIoc4, - .insel = kTopEarlgreyPinmuxInselIoc3, - }, - // UART2. - { - .mio_out = kTopEarlgreyPinmuxMioOutIoc4, - .insel = kTopEarlgreyPinmuxInselIoc3, - }, - // UART3. - { - .mio_out = kTopEarlgreyPinmuxMioOutIoc4, - .insel = kTopEarlgreyPinmuxInselIoc3, - }}, - // DV. - [UartPinmuxPlatformIdDvsim] = { - // UART0. - { - .mio_out = kTopEarlgreyPinmuxMioOutIoc4, - .insel = kTopEarlgreyPinmuxInselIoc3, - }, - // UART1. - { + [UartPinmuxPlatformIdSilicon] = { + [UartPinmuxChannelConsole] = + { + .mio_out = kTopEarlgreyPinmuxMioOutIoc4, + .insel = kTopEarlgreyPinmuxInselIoc3, + }, + // FIXME: select the other available pins. + [UartPinmuxChannelDut] = { .mio_out = kTopEarlgreyPinmuxMioOutIob5, .insel = kTopEarlgreyPinmuxInselIob4, - }, - // UART2. - { - .mio_out = kTopEarlgreyPinmuxMioOutIoa5, - .insel = kTopEarlgreyPinmuxInselIoa4, - }, - // UART3. - { - .mio_out = kTopEarlgreyPinmuxMioOutIoa1, - .insel = kTopEarlgreyPinmuxInselIoa0, }}}; +/** + * The DV platform is handled separately at the moment: all four UARTs have + * their own channels that they map to rather than using one channel for the + * console and second for the DUT. + */ +static const pinmux_testutils_mio_pin_t kUartDvPins[4] = { + // UART0. + { + .mio_out = kTopEarlgreyPinmuxMioOutIoc4, + .insel = kTopEarlgreyPinmuxInselIoc3, + }, + // UART1. + { + .mio_out = kTopEarlgreyPinmuxMioOutIob5, + .insel = kTopEarlgreyPinmuxInselIob4, + }, + // UART2. + { + .mio_out = kTopEarlgreyPinmuxMioOutIoa5, + .insel = kTopEarlgreyPinmuxInselIoa4, + }, + // UART3. + { + .mio_out = kTopEarlgreyPinmuxMioOutIoa1, + .insel = kTopEarlgreyPinmuxInselIoa0, + }}; + status_t uart_testutils_select_pinmux(const dif_pinmux_t *pinmux, uint8_t uart_id, - uart_pinmux_platform_id_t platform) { + uart_pinmux_platform_id_t platform, + uart_pinmux_channel_t channel) { TRY_CHECK(platform < UartPinmuxPlatformIdCount && + channel < UartPinmuxChannelCount && uart_id < ARRAYSIZE(kUartPinmuxPins), "Index out of bounds"); + pinmux_testutils_mio_pin_t mio_pin = + platform == UartPinmuxPlatformIdDvsim + ? kUartDvPins[uart_id] + : kUartPlatformPins[platform][channel]; + TRY(dif_pinmux_input_select(pinmux, kUartPinmuxPins[uart_id].peripheral_in, - kUartPlatformPins[platform][uart_id].insel)); - TRY(dif_pinmux_output_select(pinmux, - kUartPlatformPins[platform][uart_id].mio_out, + mio_pin.insel)); + TRY(dif_pinmux_output_select(pinmux, mio_pin.mio_out, kUartPinmuxPins[uart_id].outsel)); return OK_STATUS(); diff --git a/sw/device/lib/testing/uart_testutils.h b/sw/device/lib/testing/uart_testutils.h index 0effc0a4f3aa9..405ace531dbe2 100644 --- a/sw/device/lib/testing/uart_testutils.h +++ b/sw/device/lib/testing/uart_testutils.h @@ -21,6 +21,15 @@ typedef enum uart_pinmux_platform_id { UartPinmuxPlatformIdCount, } uart_pinmux_platform_id_t; +/** + * Define the available external channels that a UART could be connected to. + */ +typedef enum uart_pinmux_channel { + UartPinmuxChannelConsole, + UartPinmuxChannelDut, + UartPinmuxChannelCount, +} uart_pinmux_channel_t; + /** * Connect the uart pins to mio pins via pinmux based on the platform the test * is running. @@ -33,7 +42,8 @@ typedef enum uart_pinmux_platform_id { OT_WARN_UNUSED_RESULT status_t uart_testutils_select_pinmux(const dif_pinmux_t *pinmux, uint8_t kUartIdx, - uart_pinmux_platform_id_t platform); + uart_pinmux_platform_id_t platform, + uart_pinmux_channel_t channel); /** * Disconnect the uart input pins from mio pads and wire it to zero. @@ -45,4 +55,5 @@ status_t uart_testutils_select_pinmux(const dif_pinmux_t *pinmux, OT_WARN_UNUSED_RESULT status_t uart_testutils_detach_pinmux(const dif_pinmux_t *pinmux, uint8_t uart_id); + #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_UART_TESTUTILS_H_ diff --git a/sw/device/tests/uart_tx_rx_test.c b/sw/device/tests/uart_tx_rx_test.c index c29fab614d240..4374f27a0b7e0 100644 --- a/sw/device/tests/uart_tx_rx_test.c +++ b/sw/device/tests/uart_tx_rx_test.c @@ -525,7 +525,8 @@ bool test_main(void) { } // Attach the UART under test. - CHECK_STATUS_OK(uart_testutils_select_pinmux(&pinmux, kUartIdx, platform_id)); + CHECK_STATUS_OK(uart_testutils_select_pinmux(&pinmux, kUartIdx, platform_id, + UartPinmuxChannelDut)); if (kUseExtClk) { config_external_clock(&clkmgr);