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