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 
8 #include "dt/dt_rv_core_ibex.h"
10 
11 #include "rv_core_ibex_regs.h"
12 #include "uart_regs.h"
13 
14 // Use the first dt_rv_core_ibex_t enum, i.e. the first Ibex core instance.
15 static const dt_rv_core_ibex_t kRvCoreIbexDt = (dt_rv_core_ibex_t)0;
16 static_assert(kDtRvCoreIbexCount == 1, "Only single core tops are supported");
17 
18 static inline uintptr_t rv_core_ibex_base(void) {
19  return (uintptr_t)dt_rv_core_ibex_primary_reg_block(kRvCoreIbexDt);
20 }
21 
22 /**
23  * @file
24  * @brief Device-specific symbol definitions for the Verilator device.
25  */
26 
28 
29 // Changes to the clock frequency or UART baud rate must also be reflected at
30 // `hw/top_earlgrey/rtl/chip_earlgrey_verilator.sv` and
31 // `test/systemtest/earlgrey/test_sim_verilator.py`.
32 #define CPU_FREQ_HZ 500 * 1000
33 const uint64_t kClockFreqCpuHz = CPU_FREQ_HZ; // 500kHz
34 
35 // This function is specific for the frequency above. Notice since the cycle
36 // time is 2 us we round up.
37 uint64_t to_cpu_cycles(uint64_t usec) {
38  static_assert(CPU_FREQ_HZ == 500 * 1000,
39  "The verilator to_cpu_cycles function needs refactoring.");
40  return (usec + 1) / 2;
41 }
42 
43 const uint64_t kClockFreqHiSpeedPeripheralHz = 500 * 1000; // 500kHz
44 
45 const uint64_t kClockFreqPeripheralHz = 125 * 1000; // 125kHz
46 
47 const uint64_t kClockFreqUsbHz = 500 * 1000; // 500kHz
48 
49 const uint64_t kClockFreqAonHz = 125 * 1000; // 125kHz
50 
51 const uint64_t kUartBaudrate = 7200;
52 
53 const uint32_t kUartNCOValue =
54  CALCULATE_UART_NCO(kUartBaudrate, kClockFreqPeripheralHz);
55 
56 const uint32_t kUartBaud115K =
57  CALCULATE_UART_NCO(115200, kClockFreqPeripheralHz);
58 const uint32_t kUartBaud230K =
59  CALCULATE_UART_NCO(115200 * 2, kClockFreqPeripheralHz);
60 const uint32_t kUartBaud460K =
61  CALCULATE_UART_NCO(115200 * 4, kClockFreqPeripheralHz);
62 const uint32_t kUartBaud921K =
63  CALCULATE_UART_NCO(115200 * 8, kClockFreqPeripheralHz);
64 const uint32_t kUartBaud1M33 =
65  CALCULATE_UART_NCO(1333333, kClockFreqPeripheralHz);
66 const uint32_t kUartBaud1M50 =
67  CALCULATE_UART_NCO(1500000, kClockFreqPeripheralHz);
68 
70  kUartBaudrate, kClockFreqCpuHz, UART_PARAM_TX_FIFO_DEPTH);
71 
72 const uint32_t kAstCheckPollCpuCycles =
74 
75 uintptr_t device_test_status_address(void) {
76  return rv_core_ibex_base() + RV_CORE_IBEX_DV_SIM_WINDOW_REG_OFFSET;
77 }
78 
79 uintptr_t device_log_bypass_uart_address(void) { return 0; }
80