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