Software APIs
rv_timer.h
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// Device table API auto-generated by `dtgen`
6
7#ifndef OPENTITAN_DT_RV_TIMER_H_
8#define OPENTITAN_DT_RV_TIMER_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP rv_timer and top darjeeling.
17 *
18 * This file contains the type definitions and global functions of the rv_timer.
19 */
20
21#include "hw/top/dt/api.h"
22#include <stdint.h>
23
24
25
26/**
27 * List of instances.
28 */
29typedef enum dt_rv_timer {
30 kDtRvTimerFirst = 0, /**< First instance */
31 kDtRvTimer = 0, /**< rv_timer */
33
34enum {
35 kDtRvTimerCount = 1, /**< Number of instances */
36};
37
38
39/**
40 * List of register blocks.
41 *
42 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
43 */
45 kDtRvTimerRegBlockCore = 0, /**< */
47
48enum {
49 kDtRvTimerRegBlockCount = 1, /**< Number of register blocks */
50};
51
52
53/** Primary register block (associated with the "primary" set of registers that control the IP). */
54static const dt_rv_timer_reg_block_t kDtRvTimerRegBlockPrimary = kDtRvTimerRegBlockCore;
55
56/**
57 * List of IRQs.
58 *
59 * IRQs are guaranteed to be numbered consecutively from 0.
60 */
61typedef enum dt_rv_timer_irq {
62 kDtRvTimerIrqTimerExpiredHart0Timer0 = 0, /**< raised if hart0's timer0 expired (mtimecmp >= mtime) */
64
65enum {
66 kDtRvTimerIrqCount = 1, /**< Number of IRQs */
67};
68
69
70/**
71 * List of Alerts.
72 *
73 * Alerts are guaranteed to be numbered consecutively from 0.
74 */
75typedef enum dt_rv_timer_alert {
76 kDtRvTimerAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected inside the RV_TIMER unit. */
78
79enum {
80 kDtRvTimerAlertCount = 1, /**< Number of Alerts */
81};
82
83
84/**
85 * List of clock ports.
86 *
87 * Clock ports are guaranteed to be numbered consecutively from 0.
88 */
89typedef enum dt_rv_timer_clock {
90 kDtRvTimerClockClk = 0, /**< Clock port clk_i */
92
93enum {
94 kDtRvTimerClockCount = 1, /**< Number of clock ports */
95};
96
97
98/**
99 * List of reset ports.
100 *
101 * Reset ports are guaranteed to be numbered consecutively from 0.
102 */
103typedef enum dt_rv_timer_reset {
104 kDtRvTimerResetRst = 0, /**< Reset port rst_ni */
106
107enum {
108 kDtRvTimerResetCount = 1, /**< Number of reset ports */
109};
110
111
112/**
113 * List of supported hardware features.
114 */
115#define OPENTITAN_RV_TIMER_HAS_RISCV_CSRS_INTEGRATION 1
116#define OPENTITAN_RV_TIMER_HAS_ENABLE 1
117#define OPENTITAN_RV_TIMER_HAS_DISABLE 1
118#define OPENTITAN_RV_TIMER_HAS_INTERRUPT 1
119#define OPENTITAN_RV_TIMER_HAS_CONFIG 1
120#define OPENTITAN_RV_TIMER_HAS_COUNTER 1
121#define OPENTITAN_RV_TIMER_HAS_COMPARE 1
122
123
124
125/**
126 * Get the rv_timer instance from an instance ID
127 *
128 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
129 *
130 * @param inst_id Instance ID.
131 * @return A rv_timer instance.
132 *
133 * **Note:** This function only makes sense if the instance ID has device type rv_timer,
134 * otherwise the returned value is unspecified.
135 */
137
138/**
139 * Get the instance ID of an instance.
140 *
141 * @param dt Instance of rv_timer.
142 * @return The instance ID of that instance.
143 */
145
146/**
147 * Get the register base address of an instance.
148 *
149 * @param dt Instance of rv_timer.
150 * @param reg_block The register block requested.
151 * @return The register base address of the requested block.
152 */
153uint32_t dt_rv_timer_reg_block(
154 dt_rv_timer_t dt,
155 dt_rv_timer_reg_block_t reg_block);
156
157/**
158 * Get the primary register base address of an instance.
159 *
160 * This is just a convenience function, equivalent to
161 * `dt_rv_timer_reg_block(dt, kDtRvTimerRegBlockCore)`
162 *
163 * @param dt Instance of rv_timer.
164 * @return The register base address of the primary register block.
165 */
166static inline uint32_t dt_rv_timer_primary_reg_block(
167 dt_rv_timer_t dt) {
168 return dt_rv_timer_reg_block(dt, kDtRvTimerRegBlockCore);
169}
170
171/**
172 * Get the PLIC ID of a rv_timer IRQ for a given instance.
173 *
174 * If the instance is not connected to the PLIC, this function
175 * will return `kDtPlicIrqIdNone`.
176 *
177 * @param dt Instance of rv_timer.
178 * @param irq A rv_timer IRQ.
179 * @return The PLIC ID of the IRQ of this instance.
180 */
182 dt_rv_timer_t dt,
184
185/**
186 * Convert a global IRQ ID to a local rv_timer IRQ type.
187 *
188 * @param dt Instance of rv_timer.
189 * @param irq A PLIC ID that belongs to this instance.
190 * @return The rv_timer IRQ, or `kDtRvTimerIrqCount`.
191 *
192 * **Note:** This function assumes that the PLIC ID belongs to the instance
193 * of rv_timer passed in parameter. In other words, it must be the case that
194 * `dt_rv_timer_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
195 * will return `kDtRvTimerIrqCount`.
196 */
198 dt_rv_timer_t dt,
199 dt_plic_irq_id_t irq);
200
201
202/**
203 * Get the alert ID of a rv_timer alert for a given instance.
204 *
205 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
206 * instances where the instance is not connected, the return value is unspecified.
207 *
208 * @param dt Instance of rv_timer.
209 * @param alert A rv_timer alert.
210 * @return The Alert Handler alert ID of the alert of this instance.
211 */
213 dt_rv_timer_t dt,
214 dt_rv_timer_alert_t alert);
215
216/**
217 * Convert a global alert ID to a local rv_timer alert type.
218 *
219 * @param dt Instance of rv_timer.
220 * @param alert A global alert ID that belongs to this instance.
221 * @return The rv_timer alert, or `kDtRvTimerAlertCount`.
222 *
223 * **Note:** This function assumes that the global alert ID belongs to the
224 * instance of rv_timer passed in parameter. In other words, it must be the case
225 * that `dt_rv_timer_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
226 * this function will return `kDtRvTimerAlertCount`.
227 */
229 dt_rv_timer_t dt,
230 dt_alert_id_t alert);
231
232
233
234/**
235 * Get the clock signal connected to a clock port of an instance.
236 *
237 * @param dt Instance of rv_timer.
238 * @param clk Clock port.
239 * @return Clock signal.
240 */
242 dt_rv_timer_t dt,
244
245/**
246 * Get the reset signal connected to a reset port of an instance.
247 *
248 * @param dt Instance of rv_timer.
249 * @param rst Reset port.
250 * @return Reset signal.
251 */
253 dt_rv_timer_t dt,
255
256
257
258#ifdef __cplusplus
259} // extern "C"
260#endif // __cplusplus
261
262#endif // OPENTITAN_DT_RV_TIMER_H_