From 73d53e1deb017645023400e9f3a83b6d8b6a3281 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Thu, 18 Jan 2024 14:53:19 +0000 Subject: [PATCH] [sw,ottf] Extract OTTF UART configuration into separate function Signed-off-by: James Wainwright --- .../lib/testing/test_framework/ottf_console.c | 44 ++++++++++--------- .../lib/testing/test_framework/ottf_console.h | 7 +++ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/sw/device/lib/testing/test_framework/ottf_console.c b/sw/device/lib/testing/test_framework/ottf_console.c index afa28e88ede46..a06cd325061fb 100644 --- a/sw/device/lib/testing/test_framework/ottf_console.c +++ b/sw/device/lib/testing/test_framework/ottf_console.c @@ -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( @@ -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 diff --git a/sw/device/lib/testing/test_framework/ottf_console.h b/sw/device/lib/testing/test_framework/ottf_console.h index f6b5ede2b0adf..e1702ea6f1c89 100644 --- a/sw/device/lib/testing/test_framework/ottf_console.h +++ b/sw/device/lib/testing/test_framework/ottf_console.h @@ -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. *