Software APIs
pattgen.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_PATTGEN_H_
8#define OPENTITAN_DT_PATTGEN_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP pattgen and top earlgrey.
17 *
18 * This file contains the type definitions and global functions of the pattgen.
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_pattgen {
30 kDtPattgenFirst = 0, /**< First instance */
31 kDtPattgen = 0, /**< pattgen */
33
34enum {
35 kDtPattgenCount = 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 kDtPattgenRegBlockCore = 0, /**< */
47
48enum {
49 kDtPattgenRegBlockCount = 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_pattgen_reg_block_t kDtPattgenRegBlockPrimary = kDtPattgenRegBlockCore;
55
56/**
57 * List of IRQs.
58 *
59 * IRQs are guaranteed to be numbered consecutively from 0.
60 */
61typedef enum dt_pattgen_irq {
62 kDtPattgenIrqDoneCh0 = 0, /**< raise if pattern generation on Channel 0 is complete */
63 kDtPattgenIrqDoneCh1 = 1, /**< raise if pattern generation on Channel 1 is complete */
65
66enum {
67 kDtPattgenIrqCount = 2, /**< Number of IRQs */
68};
69
70
71/**
72 * List of Alerts.
73 *
74 * Alerts are guaranteed to be numbered consecutively from 0.
75 */
76typedef enum dt_pattgen_alert {
77 kDtPattgenAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
79
80enum {
81 kDtPattgenAlertCount = 1, /**< Number of Alerts */
82};
83
84
85/**
86 * List of clock ports.
87 *
88 * Clock ports are guaranteed to be numbered consecutively from 0.
89 */
90typedef enum dt_pattgen_clock {
91 kDtPattgenClockClk = 0, /**< Clock port clk_i */
93
94enum {
95 kDtPattgenClockCount = 1, /**< Number of clock ports */
96};
97
98
99/**
100 * List of reset ports.
101 *
102 * Reset ports are guaranteed to be numbered consecutively from 0.
103 */
104typedef enum dt_pattgen_reset {
105 kDtPattgenResetRst = 0, /**< Reset port rst_ni */
107
108enum {
109 kDtPattgenResetCount = 1, /**< Number of reset ports */
110};
111
112
113/**
114 * List of peripheral I/O.
115 *
116 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
117 */
119 kDtPattgenPeriphIoPda0Tx = 0, /**< */
120 kDtPattgenPeriphIoPcl0Tx = 1, /**< */
121 kDtPattgenPeriphIoPda1Tx = 2, /**< */
122 kDtPattgenPeriphIoPcl1Tx = 3, /**< */
124
125enum {
126 kDtPattgenPeriphIoCount = 4, /**< Number of peripheral I/O */
127};
128
129
130/**
131 * List of supported hardware features.
132 */
133#define OPENTITAN_PATTGEN_HAS_CHANNEL_ONE 1
134#define OPENTITAN_PATTGEN_HAS_CHANNEL_TWO 1
135#define OPENTITAN_PATTGEN_HAS_CONFIG_PATTERN 1
136#define OPENTITAN_PATTGEN_HAS_CONFIG_DIVIDER 1
137#define OPENTITAN_PATTGEN_HAS_CONFIG_REPEAT 1
138#define OPENTITAN_PATTGEN_HAS_CONFIG_POLARITY 1
139#define OPENTITAN_PATTGEN_HAS_CONFIG_INACTIVE_LEVEL 1
140#define OPENTITAN_PATTGEN_HAS_COMPLETE 1
141
142
143
144/**
145 * Get the pattgen instance from an instance ID
146 *
147 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
148 *
149 * @param inst_id Instance ID.
150 * @return A pattgen instance.
151 *
152 * **Note:** This function only makes sense if the instance ID has device type pattgen,
153 * otherwise the returned value is unspecified.
154 */
156
157/**
158 * Get the instance ID of an instance.
159 *
160 * @param dt Instance of pattgen.
161 * @return The instance ID of that instance.
162 */
164
165/**
166 * Get the register base address of an instance.
167 *
168 * @param dt Instance of pattgen.
169 * @param reg_block The register block requested.
170 * @return The register base address of the requested block.
171 */
172uint32_t dt_pattgen_reg_block(
173 dt_pattgen_t dt,
174 dt_pattgen_reg_block_t reg_block);
175
176/**
177 * Get the primary register base address of an instance.
178 *
179 * This is just a convenience function, equivalent to
180 * `dt_pattgen_reg_block(dt, kDtPattgenRegBlockCore)`
181 *
182 * @param dt Instance of pattgen.
183 * @return The register base address of the primary register block.
184 */
185static inline uint32_t dt_pattgen_primary_reg_block(
186 dt_pattgen_t dt) {
187 return dt_pattgen_reg_block(dt, kDtPattgenRegBlockCore);
188}
189
190/**
191 * Get the PLIC ID of a pattgen IRQ for a given instance.
192 *
193 * If the instance is not connected to the PLIC, this function
194 * will return `kDtPlicIrqIdNone`.
195 *
196 * @param dt Instance of pattgen.
197 * @param irq A pattgen IRQ.
198 * @return The PLIC ID of the IRQ of this instance.
199 */
201 dt_pattgen_t dt,
202 dt_pattgen_irq_t irq);
203
204/**
205 * Convert a global IRQ ID to a local pattgen IRQ type.
206 *
207 * @param dt Instance of pattgen.
208 * @param irq A PLIC ID that belongs to this instance.
209 * @return The pattgen IRQ, or `kDtPattgenIrqCount`.
210 *
211 * **Note:** This function assumes that the PLIC ID belongs to the instance
212 * of pattgen passed in parameter. In other words, it must be the case that
213 * `dt_pattgen_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
214 * will return `kDtPattgenIrqCount`.
215 */
217 dt_pattgen_t dt,
218 dt_plic_irq_id_t irq);
219
220
221/**
222 * Get the alert ID of a pattgen alert for a given instance.
223 *
224 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
225 * instances where the instance is not connected, the return value is unspecified.
226 *
227 * @param dt Instance of pattgen.
228 * @param alert A pattgen alert.
229 * @return The Alert Handler alert ID of the alert of this instance.
230 */
232 dt_pattgen_t dt,
233 dt_pattgen_alert_t alert);
234
235/**
236 * Convert a global alert ID to a local pattgen alert type.
237 *
238 * @param dt Instance of pattgen.
239 * @param alert A global alert ID that belongs to this instance.
240 * @return The pattgen alert, or `kDtPattgenAlertCount`.
241 *
242 * **Note:** This function assumes that the global alert ID belongs to the
243 * instance of pattgen passed in parameter. In other words, it must be the case
244 * that `dt_pattgen_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
245 * this function will return `kDtPattgenAlertCount`.
246 */
248 dt_pattgen_t dt,
249 dt_alert_id_t alert);
250
251
252/**
253 * Get the peripheral I/O description of an instance.
254 *
255 * @param dt Instance of pattgen.
256 * @param sig Requested peripheral I/O.
257 * @return Description of the requested peripheral I/O for this instance.
258 */
260 dt_pattgen_t dt,
262
263/**
264 * Get the clock signal connected to a clock port of an instance.
265 *
266 * @param dt Instance of pattgen.
267 * @param clk Clock port.
268 * @return Clock signal.
269 */
271 dt_pattgen_t dt,
273
274/**
275 * Get the reset signal connected to a reset port of an instance.
276 *
277 * @param dt Instance of pattgen.
278 * @param rst Reset port.
279 * @return Reset signal.
280 */
282 dt_pattgen_t dt,
284
285
286
287#ifdef __cplusplus
288} // extern "C"
289#endif // __cplusplus
290
291#endif // OPENTITAN_DT_PATTGEN_H_