Software APIs
dt_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 "dt_api.h"
22#include <stdint.h>
23
24
25
26/**
27 * List of instances.
28 */
29typedef enum dt_pattgen {
30 kDtPattgen = 0, /**< pattgen */
31 kDtPattgenFirst = 0, /**< \internal First instance */
32 kDtPattgenCount = 1, /**< \internal Number of instances */
34
35/**
36 * List of register blocks.
37 *
38 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
39 */
41 kDtPattgenRegBlockCore = 0, /**< */
42 kDtPattgenRegBlockCount = 1, /**< \internal Number of register blocks */
44
45/** Primary register block (associated with the "primary" set of registers that control the IP). */
46static const dt_pattgen_reg_block_t kDtPattgenRegBlockPrimary = kDtPattgenRegBlockCore;
47
48/**
49 * List of IRQs.
50 *
51 * IRQs are guaranteed to be numbered consecutively from 0.
52 */
53typedef enum dt_pattgen_irq {
54 kDtPattgenIrqDoneCh0 = 0, /**< raise if pattern generation on Channel 0 is complete */
55 kDtPattgenIrqDoneCh1 = 1, /**< raise if pattern generation on Channel 1 is complete */
56 kDtPattgenIrqCount = 2, /**< \internal Number of IRQs */
58
59/**
60 * List of Alerts.
61 *
62 * Alerts are guaranteed to be numbered consecutively from 0.
63 */
64typedef enum dt_pattgen_alert {
65 kDtPattgenAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
66 kDtPattgenAlertCount = 1, /**< \internal Number of Alerts */
68
69/**
70 * List of clock ports.
71 *
72 * Clock ports are guaranteed to be numbered consecutively from 0.
73 */
74typedef enum dt_pattgen_clock {
75 kDtPattgenClockClk = 0, /**< Clock port clk_i */
76 kDtPattgenClockCount = 1, /**< \internal Number of clock ports */
78
79/**
80 * List of reset ports.
81 *
82 * Reset ports are guaranteed to be numbered consecutively from 0.
83 */
84typedef enum dt_pattgen_reset {
85 kDtPattgenResetRst = 0, /**< Reset port rst_ni */
86 kDtPattgenResetCount = 1, /**< \internal Number of reset ports */
88
89/**
90 * List of peripheral I/O.
91 *
92 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
93 */
95 kDtPattgenPeriphIoPda0Tx = 0, /**< */
96 kDtPattgenPeriphIoPcl0Tx = 1, /**< */
97 kDtPattgenPeriphIoPda1Tx = 2, /**< */
98 kDtPattgenPeriphIoPcl1Tx = 3, /**< */
99 kDtPattgenPeriphIoCount = 4, /**< \internal Number of peripheral I/O */
101
102/**
103 * List of supported hardware features.
104 */
105#define OPENTITAN_PATTGEN_HAS_CHANNEL_ONE 1
106#define OPENTITAN_PATTGEN_HAS_CHANNEL_TWO 1
107#define OPENTITAN_PATTGEN_HAS_CONFIG_PATTERN 1
108#define OPENTITAN_PATTGEN_HAS_CONFIG_DIVIDER 1
109#define OPENTITAN_PATTGEN_HAS_CONFIG_REPEAT 1
110#define OPENTITAN_PATTGEN_HAS_CONFIG_POLARITY 1
111#define OPENTITAN_PATTGEN_HAS_CONFIG_INACTIVE_LEVEL 1
112#define OPENTITAN_PATTGEN_HAS_COMPLETE 1
113
114
115
116/**
117 * Get the pattgen instance from an instance ID
118 *
119 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
120 *
121 * @param inst_id Instance ID.
122 * @return A pattgen instance.
123 *
124 * **Note:** This function only makes sense if the instance ID has device type pattgen,
125 * otherwise the returned value is unspecified.
126 */
128
129/**
130 * Get the instance ID of an instance.
131 *
132 * @param dt Instance of pattgen.
133 * @return The instance ID of that instance.
134 */
136
137/**
138 * Get the register base address of an instance.
139 *
140 * @param dt Instance of pattgen.
141 * @param reg_block The register block requested.
142 * @return The register base address of the requested block.
143 */
144uint32_t dt_pattgen_reg_block(
145 dt_pattgen_t dt,
146 dt_pattgen_reg_block_t reg_block);
147
148/**
149 * Get the primary register base address of an instance.
150 *
151 * This is just a convenience function, equivalent to
152 * `dt_pattgen_reg_block(dt, kDtPattgenRegBlockCore)`
153 *
154 * @param dt Instance of pattgen.
155 * @return The register base address of the primary register block.
156 */
157static inline uint32_t dt_pattgen_primary_reg_block(
158 dt_pattgen_t dt) {
159 return dt_pattgen_reg_block(dt, kDtPattgenRegBlockCore);
160}
161
162/**
163 * Get the PLIC ID of a pattgen IRQ for a given instance.
164 *
165 * If the instance is not connected to the PLIC, this function
166 * will return `kDtPlicIrqIdNone`.
167 *
168 * @param dt Instance of pattgen.
169 * @param irq A pattgen IRQ.
170 * @return The PLIC ID of the IRQ of this instance.
171 */
173 dt_pattgen_t dt,
174 dt_pattgen_irq_t irq);
175
176/**
177 * Convert a global IRQ ID to a local pattgen IRQ type.
178 *
179 * @param dt Instance of pattgen.
180 * @param irq A PLIC ID that belongs to this instance.
181 * @return The pattgen IRQ, or `kDtPattgenIrqCount`.
182 *
183 * **Note:** This function assumes that the PLIC ID belongs to the instance
184 * of pattgen passed in parameter. In other words, it must be the case that
185 * `dt_pattgen_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
186 * will return `kDtPattgenIrqCount`.
187 */
189 dt_pattgen_t dt,
190 dt_plic_irq_id_t irq);
191
192
193/**
194 * Get the alert ID of a pattgen alert for a given instance.
195 *
196 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
197 * instances where the instance is not connected, the return value is unspecified.
198 *
199 * @param dt Instance of pattgen.
200 * @param alert A pattgen alert.
201 * @return The Alert Handler alert ID of the alert of this instance.
202 */
204 dt_pattgen_t dt,
205 dt_pattgen_alert_t alert);
206
207/**
208 * Convert a global alert ID to a local pattgen alert type.
209 *
210 * @param dt Instance of pattgen.
211 * @param alert A global alert ID that belongs to this instance.
212 * @return The pattgen alert, or `kDtPattgenAlertCount`.
213 *
214 * **Note:** This function assumes that the global alert ID belongs to the
215 * instance of pattgen passed in parameter. In other words, it must be the case
216 * that `dt_pattgen_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
217 * this function will return `kDtPattgenAlertCount`.
218 */
220 dt_pattgen_t dt,
221 dt_alert_id_t alert);
222
223
224/**
225 * Get the peripheral I/O description of an instance.
226 *
227 * @param dt Instance of pattgen.
228 * @param sig Requested peripheral I/O.
229 * @return Description of the requested peripheral I/O for this instance.
230 */
232 dt_pattgen_t dt,
234
235/**
236 * Get the clock signal connected to a clock port of an instance.
237 *
238 * @param dt Instance of pattgen.
239 * @param clk Clock port.
240 * @return Clock signal.
241 */
243 dt_pattgen_t dt,
245
246/**
247 * Get the reset signal connected to a reset port of an instance.
248 *
249 * @param dt Instance of pattgen.
250 * @param rst Reset port.
251 * @return Reset signal.
252 */
254 dt_pattgen_t dt,
256
257
258
259#ifdef __cplusplus
260} // extern "C"
261#endif // __cplusplus
262
263#endif // OPENTITAN_DT_PATTGEN_H_