Skip to content

Commit

Permalink
[test,uart] Simplify UART pinmux to two external channels
Browse files Browse the repository at this point in the history
Signed-off-by: James Wainwright <[email protected]>
  • Loading branch information
jwnrt committed Jan 18, 2024
1 parent ffe3a9d commit 2d119a1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 67 deletions.
122 changes: 57 additions & 65 deletions sw/device/lib/testing/uart_testutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 12 additions & 1 deletion sw/device/lib/testing/uart_testutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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_
3 changes: 2 additions & 1 deletion sw/device/tests/uart_tx_rx_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2d119a1

Please sign in to comment.