Software APIs
device_sim_verilator.c
Go to the documentation of this file.
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 <assert.h>
6 #include <stdbool.h>
7 
9 
11 #include "rv_core_ibex_regs.h"
12 #include "uart_regs.h"
13 
14 /**
15  * @file
16  * @brief Device-specific symbol definitions for the Verilator device.
17  */
18 
20 
21 // Changes to the clock frequency or UART baud rate must also be reflected at
22 // `hw/top_earlgrey/rtl/chip_earlgrey_verilator.sv` and
23 // `test/systemtest/earlgrey/test_sim_verilator.py`.
24 #define CPU_FREQ_HZ 500 * 1000
25 const uint64_t kClockFreqCpuHz = CPU_FREQ_HZ; // 500kHz
26 
27 // This function is specific for the frequency above. Notice since the cycle
28 // time is 2 us we round up.
29 uint64_t to_cpu_cycles(uint64_t usec) {
30  static_assert(CPU_FREQ_HZ == 500 * 1000,
31  "The verilator to_cpu_cycles function needs refactoring.");
32  return (usec + 1) / 2;
33 }
34 
35 const uint64_t kClockFreqHiSpeedPeripheralHz = 500 * 1000; // 500kHz
36 
37 const uint64_t kClockFreqPeripheralHz = 125 * 1000; // 125kHz
38 
39 const uint64_t kClockFreqUsbHz = 500 * 1000; // 500kHz
40 
41 const uint64_t kClockFreqAonHz = 125 * 1000; // 125kHz
42 
43 const uint64_t kUartBaudrate = 7200;
44 
45 const uint32_t kUartNCOValue =
46  CALCULATE_UART_NCO(kUartBaudrate, kClockFreqPeripheralHz);
47 
48 const uint32_t kUartBaud115K =
49  CALCULATE_UART_NCO(115200, kClockFreqPeripheralHz);
50 const uint32_t kUartBaud230K =
51  CALCULATE_UART_NCO(115200 * 2, kClockFreqPeripheralHz);
52 const uint32_t kUartBaud460K =
53  CALCULATE_UART_NCO(115200 * 4, kClockFreqPeripheralHz);
54 const uint32_t kUartBaud921K =
55  CALCULATE_UART_NCO(115200 * 8, kClockFreqPeripheralHz);
56 const uint32_t kUartBaud1M33 =
57  CALCULATE_UART_NCO(1333333, kClockFreqPeripheralHz);
58 const uint32_t kUartBaud1M50 =
59  CALCULATE_UART_NCO(1500000, kClockFreqPeripheralHz);
60 
62  kUartBaudrate, kClockFreqCpuHz, UART_PARAM_TX_FIFO_DEPTH);
63 
64 const uint32_t kAstCheckPollCpuCycles =
66 
67 const uintptr_t kDeviceTestStatusAddress =
69  RV_CORE_IBEX_DV_SIM_WINDOW_REG_OFFSET;
70 
71 const uintptr_t kDeviceLogBypassUartAddress = 0;
72