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