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 englishbreakfast.
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 clock ports.
72 *
73 * Clock ports are guaranteed to be numbered consecutively from 0.
74 */
75typedef enum dt_rv_timer_clock {
76 kDtRvTimerClockClk = 0, /**< Clock port clk_i */
78
79enum {
80 kDtRvTimerClockCount = 1, /**< Number of clock ports */
81};
82
83
84/**
85 * List of reset ports.
86 *
87 * Reset ports are guaranteed to be numbered consecutively from 0.
88 */
89typedef enum dt_rv_timer_reset {
90 kDtRvTimerResetRst = 0, /**< Reset port rst_ni */
92
93enum {
94 kDtRvTimerResetCount = 1, /**< Number of reset ports */
95};
96
97
98/**
99 * List of supported hardware features.
100 */
101#define OPENTITAN_RV_TIMER_HAS_RISCV_CSRS_INTEGRATION 1
102#define OPENTITAN_RV_TIMER_HAS_ENABLE 1
103#define OPENTITAN_RV_TIMER_HAS_DISABLE 1
104#define OPENTITAN_RV_TIMER_HAS_INTERRUPT 1
105#define OPENTITAN_RV_TIMER_HAS_CONFIG 1
106#define OPENTITAN_RV_TIMER_HAS_COUNTER 1
107#define OPENTITAN_RV_TIMER_HAS_COMPARE 1
108
109
110
111/**
112 * Get the rv_timer instance from an instance ID
113 *
114 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
115 *
116 * @param inst_id Instance ID.
117 * @return A rv_timer instance.
118 *
119 * **Note:** This function only makes sense if the instance ID has device type rv_timer,
120 * otherwise the returned value is unspecified.
121 */
123
124/**
125 * Get the instance ID of an instance.
126 *
127 * @param dt Instance of rv_timer.
128 * @return The instance ID of that instance.
129 */
131
132/**
133 * Get the register base address of an instance.
134 *
135 * @param dt Instance of rv_timer.
136 * @param reg_block The register block requested.
137 * @return The register base address of the requested block.
138 */
139uint32_t dt_rv_timer_reg_block(
140 dt_rv_timer_t dt,
141 dt_rv_timer_reg_block_t reg_block);
142
143/**
144 * Get the primary register base address of an instance.
145 *
146 * This is just a convenience function, equivalent to
147 * `dt_rv_timer_reg_block(dt, kDtRvTimerRegBlockCore)`
148 *
149 * @param dt Instance of rv_timer.
150 * @return The register base address of the primary register block.
151 */
152static inline uint32_t dt_rv_timer_primary_reg_block(
153 dt_rv_timer_t dt) {
154 return dt_rv_timer_reg_block(dt, kDtRvTimerRegBlockCore);
155}
156
157/**
158 * Get the PLIC ID of a rv_timer IRQ for a given instance.
159 *
160 * If the instance is not connected to the PLIC, this function
161 * will return `kDtPlicIrqIdNone`.
162 *
163 * @param dt Instance of rv_timer.
164 * @param irq A rv_timer IRQ.
165 * @return The PLIC ID of the IRQ of this instance.
166 */
168 dt_rv_timer_t dt,
170
171/**
172 * Convert a global IRQ ID to a local rv_timer IRQ type.
173 *
174 * @param dt Instance of rv_timer.
175 * @param irq A PLIC ID that belongs to this instance.
176 * @return The rv_timer IRQ, or `kDtRvTimerIrqCount`.
177 *
178 * **Note:** This function assumes that the PLIC ID belongs to the instance
179 * of rv_timer passed in parameter. In other words, it must be the case that
180 * `dt_rv_timer_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
181 * will return `kDtRvTimerIrqCount`.
182 */
184 dt_rv_timer_t dt,
185 dt_plic_irq_id_t irq);
186
187
188
189
190/**
191 * Get the clock signal connected to a clock port of an instance.
192 *
193 * @param dt Instance of rv_timer.
194 * @param clk Clock port.
195 * @return Clock signal.
196 */
198 dt_rv_timer_t dt,
200
201/**
202 * Get the reset signal connected to a reset port of an instance.
203 *
204 * @param dt Instance of rv_timer.
205 * @param rst Reset port.
206 * @return Reset signal.
207 */
209 dt_rv_timer_t dt,
211
212
213
214#ifdef __cplusplus
215} // extern "C"
216#endif // __cplusplus
217
218#endif // OPENTITAN_DT_RV_TIMER_H_