Software APIs
sram_program.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 <stdint.h>
6 
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 
17 
18 static dif_uart_t uart0;
19 static dif_pinmux_t pinmux;
20 
21 enum {
25 };
26 
27 bool test_main(void) {
28  if (kDeviceType != kDeviceSimDV) {
29  // Configure the pinmux.
30  CHECK_DIF_OK(dif_pinmux_init(
32  pinmux_testutils_init(&pinmux);
33 
34  // Initialize UART.
35  CHECK_DIF_OK(dif_uart_init(
37  CHECK(kUartBaudrate <= UINT32_MAX, "kUartBaudrate must fit in uint32_t");
38  CHECK(kClockFreqPeripheralHz <= UINT32_MAX,
39  "kClockFreqPeripheralHz must fit in uint32_t");
40  CHECK_DIF_OK(dif_uart_configure(
41  &uart0, (dif_uart_config_t){
42  .baudrate = (uint32_t)kUartBaudrate,
43  .clk_freq_hz = (uint32_t)kClockFreqPeripheralHz,
44  .parity_enable = kDifToggleDisabled,
45  .parity = kDifUartParityEven,
46  .tx_enable = kDifToggleEnabled,
47  .rx_enable = kDifToggleEnabled,
48  }));
49  base_uart_stdout(&uart0);
50  }
51 
52  // Read the program counter and check that we are executing from SRAM.
53  uint32_t pc = 0;
54  asm("auipc %[pc], 0;" : [pc] "=r"(pc));
55  LOG_INFO("PC: %p, SRAM: [%p, %p)", pc, kSramStart, kSramEnd);
56  CHECK(pc >= kSramStart && pc < kSramEnd, "PC is outside the main SRAM");
57  if (kDeviceType == kDeviceSimDV) {
58  test_status_set(kTestStatusPassed);
59  }
60  return true;
61 }
62 
63 // Reference functions that the debugger may wish to call. This prevents the
64 // compiler from dropping them as unused functions and has the side benefit of
65 // preventing their includes from appearing unused.
66 void debugger_support_functions(void) { (void)icache_invalidate; }