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 
12 #include "sw/device/lib/testing/pinmux_testutils.h"
13 #include "sw/device/lib/testing/test_framework/check.h"
14 #include "sw/device/lib/testing/test_framework/status.h"
15 
16 #include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.
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(
27  pinmux_testutils_init(&pinmux);
28 
29  // We need to initialize the UART regardless if we LOG any messages, since
30  // Verilator and FPGA platforms use the UART to communicate the test results.
31  if (kDeviceType != kDeviceSimDV) {
32  CHECK_DIF_OK(dif_uart_init(
34  CHECK(kUartBaudrate <= UINT32_MAX, "kUartBaudrate must fit in uint32_t");
35  CHECK(kClockFreqPeripheralHz <= UINT32_MAX,
36  "kClockFreqPeripheralHz must fit in uint32_t");
37  CHECK_DIF_OK(dif_uart_configure(
38  &uart0, (dif_uart_config_t){
39  .baudrate = (uint32_t)kUartBaudrate,
40  .clk_freq_hz = (uint32_t)kClockFreqPeripheralHz,
41  .parity_enable = kDifToggleDisabled,
42  .parity = kDifUartParityEven,
43  .tx_enable = kDifToggleEnabled,
44  .rx_enable = kDifToggleEnabled,
45  }));
46  base_uart_stdout(&uart0);
47  }
48 
49  /**
50  * Place test code here.
51  */
52 
53  /**
54  * Return true if the test succeeds. Return false if it should fail.
55  */
56  return true;
57 }