Software APIs
example_test_from_rom.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #include "dt/dt_api.h"
6 #include "dt/dt_uart.h"
14 #include "sw/device/lib/testing/pinmux_testutils.h"
15 #include "sw/device/lib/testing/test_framework/check.h"
16 #include "sw/device/lib/testing/test_framework/status.h"
17 
18 static dif_pinmux_t pinmux;
19 static dif_uart_t uart0;
20 
21 bool rom_test_main(void) {
22  // We need to set the test status as "in test" to indicate to the test code
23  // has been reached, even though this test is also in the "boot ROM".
24  test_status_set(kTestStatusInTest);
25  CHECK_DIF_OK(dif_pinmux_init_from_dt(kDtPinmuxAon, &pinmux));
26  pinmux_testutils_init(&pinmux);
27 
28  // We need to initialize the UART regardless if we LOG any messages, since
29  // Verilator and FPGA platforms use the UART to communicate the test results.
30  if (kDeviceType != kDeviceSimDV) {
31  CHECK_DIF_OK(dif_uart_init_from_dt(kDtUartFirst, &uart0));
32  CHECK(kUartBaudrate <= UINT32_MAX, "kUartBaudrate must fit in uint32_t");
33  CHECK(kClockFreqPeripheralHz <= UINT32_MAX,
34  "kClockFreqPeripheralHz must fit in uint32_t");
35  CHECK_DIF_OK(dif_uart_configure(
36  &uart0, (dif_uart_config_t){
37  .baudrate = (uint32_t)kUartBaudrate,
38  .clk_freq_hz = dt_clock_frequency(
39  dt_uart_clock(kDtUartFirst, kDtUartClockClk)),
40  .parity_enable = kDifToggleDisabled,
41  .parity = kDifUartParityEven,
42  .tx_enable = kDifToggleEnabled,
43  .rx_enable = kDifToggleEnabled,
44  }));
45  base_uart_stdout(&uart0);
46  }
47 
48  /**
49  * Place test code here.
50  */
51 
52  /**
53  * Return true if the test succeeds. Return false if it should fail.
54  */
55  return true;
56 }