Skip to content

Commit

Permalink
[sw,ottf] Extract OTTF UART configuration into separate function
Browse files Browse the repository at this point in the history
Signed-off-by: James Wainwright <[email protected]>
  • Loading branch information
jwnrt committed Jan 22, 2024
1 parent 0ba3f23 commit 5c16644
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
44 changes: 24 additions & 20 deletions sw/device/lib/testing/test_framework/ottf_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,8 @@ void ottf_console_init(void) {
CHECK(kOttfTestConfig.console.type == kOttfConsoleUart);
base_addr = TOP_EARLGREY_UART0_BASE_ADDR;
}
CHECK_DIF_OK(
dif_uart_init(mmio_region_from_addr(base_addr), &ottf_console_uart));
CHECK(kUartBaudrate <= UINT32_MAX, "kUartBaudrate must fit in uint32_t");
CHECK(kClockFreqPeripheralHz <= UINT32_MAX,
"kClockFreqPeripheralHz must fit in uint32_t");
CHECK_DIF_OK(dif_uart_configure(
&ottf_console_uart,
(dif_uart_config_t){
.baudrate = (uint32_t)kUartBaudrate,
.clk_freq_hz = (uint32_t)kClockFreqPeripheralHz,
.parity_enable = kDifToggleDisabled,
.parity = kDifUartParityEven,
.tx_enable = kDifToggleEnabled,
.rx_enable = kDifToggleEnabled,
}));
base_uart_stdout(&ottf_console_uart);

// Initialize/Configure console flow control (if requested).
if (kOttfTestConfig.enable_uart_flow_control) {
ottf_console_flow_control_enable();
}
ottf_console_configure_uart(base_addr);
break;
case (kOttfConsoleSpiDevice):
CHECK_DIF_OK(dif_spi_device_init_handle(
Expand Down Expand Up @@ -125,6 +106,29 @@ void ottf_console_init(void) {
}
}

void ottf_console_configure_uart(uintptr_t base_addr) {
CHECK_DIF_OK(
dif_uart_init(mmio_region_from_addr(base_addr), &ottf_console_uart));
CHECK(kUartBaudrate <= UINT32_MAX, "kUartBaudrate must fit in uint32_t");
CHECK(kClockFreqPeripheralHz <= UINT32_MAX,
"kClockFreqPeripheralHz must fit in uint32_t");
CHECK_DIF_OK(dif_uart_configure(
&ottf_console_uart, (dif_uart_config_t){
.baudrate = (uint32_t)kUartBaudrate,
.clk_freq_hz = (uint32_t)kClockFreqPeripheralHz,
.parity_enable = kDifToggleDisabled,
.parity = kDifUartParityEven,
.tx_enable = kDifToggleEnabled,
.rx_enable = kDifToggleEnabled,
}));
base_uart_stdout(&ottf_console_uart);

// Initialize/Configure console flow control (if requested).
if (kOttfTestConfig.enable_uart_flow_control) {
ottf_console_flow_control_enable();
}
}

static uint32_t get_flow_control_watermark_plic_id(void) {
switch (kOttfTestConfig.console.base_addr) {
#if !OT_IS_ENGLISH_BREAKFAST
Expand Down
7 changes: 7 additions & 0 deletions sw/device/lib/testing/test_framework/ottf_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ void *ottf_console_get(void);
*/
void ottf_console_init(void);

/**
* Configures the given UART to be used by the OTTF console.
*
* @param base_addr The base address of the UART to use.
*/
void ottf_console_configure_uart(uintptr_t base_addr);

/**
* Manage flow control by inspecting the OTTF console device's receive FIFO.
*
Expand Down

0 comments on commit 5c16644

Please sign in to comment.