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
11
extern
"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
*/
29
typedef
enum
dt_rv_timer
{
30
kDtRvTimerFirst
= 0,
/**< First instance */
31
kDtRvTimer
= 0,
/**< rv_timer */
32
}
dt_rv_timer_t
;
33
34
enum
{
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
*/
44
typedef
enum
dt_rv_timer_reg_block
{
45
kDtRvTimerRegBlockCore = 0,
/**< */
46
}
dt_rv_timer_reg_block_t
;
47
48
enum
{
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). */
54
static
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
*/
61
typedef
enum
dt_rv_timer_irq
{
62
kDtRvTimerIrqTimerExpiredHart0Timer0
= 0,
/**< raised if hart0's timer0 expired (mtimecmp >= mtime) */
63
}
dt_rv_timer_irq_t
;
64
65
enum
{
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
*/
75
typedef
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. */
77
}
dt_rv_timer_alert_t
;
78
79
enum
{
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
*/
89
typedef
enum
dt_rv_timer_clock
{
90
kDtRvTimerClockClk
= 0,
/**< Clock port clk_i */
91
}
dt_rv_timer_clock_t
;
92
93
enum
{
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
*/
103
typedef
enum
dt_rv_timer_reset
{
104
kDtRvTimerResetRst
= 0,
/**< Reset port rst_ni */
105
}
dt_rv_timer_reset_t
;
106
107
enum
{
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
*/
136
dt_rv_timer_t
dt_rv_timer_from_instance_id
(
dt_instance_id_t
inst_id);
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
*/
144
dt_instance_id_t
dt_rv_timer_instance_id
(
dt_rv_timer_t
dt);
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
*/
153
uint32_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
*/
166
static
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
*/
181
dt_plic_irq_id_t
dt_rv_timer_irq_to_plic_id
(
182
dt_rv_timer_t
dt,
183
dt_rv_timer_irq_t
irq);
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
*/
197
dt_rv_timer_irq_t
dt_rv_timer_irq_from_plic_id
(
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
*/
212
dt_alert_id_t
dt_rv_timer_alert_to_alert_id
(
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
*/
228
dt_rv_timer_alert_t
dt_rv_timer_alert_from_alert_id
(
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
*/
241
dt_clock_t
dt_rv_timer_clock
(
242
dt_rv_timer_t
dt,
243
dt_rv_timer_clock_t
clk);
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
*/
252
dt_reset_t
dt_rv_timer_reset
(
253
dt_rv_timer_t
dt,
254
dt_rv_timer_reset_t
rst);
255
256
257
258
#ifdef __cplusplus
259
}
// extern "C"
260
#endif
// __cplusplus
261
262
#endif
// OPENTITAN_DT_RV_TIMER_H_
(darjeeling)
hw
top
dt
rv_timer.h
Return to
OpenTitan Documentation