Software APIs
sw
device
tests
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 "
sw/device/lib/arch/device.h
"
6
#include "
sw/device/lib/base/mmio.h
"
7
#include "
sw/device/lib/dif/dif_pinmux.h
"
8
#include "
sw/device/lib/dif/dif_uart.h
"
9
#include "
sw/device/lib/runtime/hart.h
"
10
#include "
sw/device/lib/runtime/log.h
"
11
#include "
sw/device/lib/runtime/print.h
"
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(
26
mmio_region_from_addr
(
TOP_EARLGREY_PINMUX_AON_BASE_ADDR
), &pinmux));
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(
33
mmio_region_from_addr
(
TOP_EARLGREY_UART0_BASE_ADDR
), &uart0));
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
}
Return to
OpenTitan Documentation