Software APIs
dif_uart_autogen.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
6
7#ifndef OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_UART_AUTOGEN_H_
8#define OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_UART_AUTOGEN_H_
9
10// THIS FILE HAS BEEN GENERATED, DO NOT EDIT MANUALLY. COMMAND:
11// util/autogen_dif.py -i hw/ip/uart/data/uart.hjson -o
12// bazel-out/k8-fastbuild/bin/sw/device/lib/dif/autogen
13
14
15/**
16 * @file
17 * @brief <a href="/book/hw/ip/uart/">UART</a> Device Interface Functions
18 */
19
20#include <stdbool.h>
21#include <stdint.h>
22
26#include "hw/top/dt/uart.h" // Generated.
27
28#ifdef __cplusplus
29extern "C" {
30#endif // __cplusplus
31
32/**
33 * A handle to uart.
34 *
35 * This type should be treated as opaque by users.
36 */
37typedef struct dif_uart {
38 /**
39 * The base address for the uart hardware registers.
40 */
42 /**
43 * The instance, set to `kDtUartCount` if not initialized
44 * through `dif_uart_init_from_dt`.
45 */
48
49/**
50 * Creates a new handle for a(n) uart peripheral.
51 *
52 * This function does not actuate the hardware.
53 *
54 * @param base_addr The MMIO base address of the uart peripheral.
55 * @param[out] uart Out param for the initialized handle.
56 * @return The result of the operation.
57 *
58 * DEPRECATED This function exists solely for the transition to
59 * dt-based DIFs and will be removed in the future.
60 */
63 mmio_region_t base_addr,
64 dif_uart_t *uart);
65
66/**
67 * Creates a new handle for a(n) uart peripheral.
68 *
69 * This function does not actuate the hardware.
70 *
71 * @param dt The devicetable description of the device.
72 * @param[out] uart Out param for the initialized handle.
73 * @return The result of the operation.
74 */
77 dt_uart_t dt,
78 dif_uart_t *uart);
79
80/**
81 * Get the DT handle from this DIF.
82 *
83 * If this DIF was initialized by `dif_uart_init_from_dt(dt, ..)`
84 * then this function will return `dt`. Otherwise it will return an error.
85 *
86 * @param uart A uart handle.
87 * @param[out] dt DT handle.
88 * @return `kDifBadArg` if the DIF has no DT information, `kDifOk` otherwise.
89 */
92 const dif_uart_t *uart,
93 dt_uart_t *dt);
94
95 /**
96 * A uart alert type.
97 */
98 typedef enum dif_uart_alert {
99 /**
100 * This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected.
101 */
104
105 /**
106 * Forces a particular alert, causing it to be escalated as if the hardware
107 * had raised it.
108 *
109 * @param uart A uart handle.
110 * @param alert The alert to force.
111 * @return The result of the operation.
112 */
115 const dif_uart_t *uart,
116 dif_uart_alert_t alert);
117
118 // DEPRECATED This typedef exists solely for the transition to
119 // dt-based interrupt numbers and will be removed in the future.
120 typedef dt_uart_irq_t dif_uart_irq_t;
121
122 /**
123 * A uart interrupt request type.
124 *
125 * DEPRECATED Use `dt_uart_irq_t` instead.
126 * This enumeration exists solely for the transition to
127 * dt-based interrupt numbers and will be removed in the future.
128 *
129 * The following are defines to keep the types consistent with DT.
130 */
131 /**
132 * Raised if the transmit FIFO is past the high-water mark.
133 */
134#define kDifUartIrqTxWatermark kDtUartIrqTxWatermark
135 /**
136 * Raised if the receive FIFO is past the high-water mark.
137 */
138#define kDifUartIrqRxWatermark kDtUartIrqRxWatermark
139 /**
140 * Raised if the transmit FIFO has emptied and no transmit is ongoing.
141 */
142#define kDifUartIrqTxDone kDtUartIrqTxDone
143 /**
144 * Raised if the receive FIFO has overflowed.
145 */
146#define kDifUartIrqRxOverflow kDtUartIrqRxOverflow
147 /**
148 * Raised if a framing error has been detected on receive.
149 */
150#define kDifUartIrqRxFrameErr kDtUartIrqRxFrameErr
151 /**
152 * Raised if break condition has been detected on receive.
153 */
154#define kDifUartIrqRxBreakErr kDtUartIrqRxBreakErr
155 /**
156 * Raised if RX FIFO has characters remaining in the FIFO without being retrieved for the programmed time period.
157 */
158#define kDifUartIrqRxTimeout kDtUartIrqRxTimeout
159 /**
160 * Raised if the receiver has detected a parity error.
161 */
162#define kDifUartIrqRxParityErr kDtUartIrqRxParityErr
163 /**
164 * Raised if the transmit FIFO is empty.
165 */
166#define kDifUartIrqTxEmpty kDtUartIrqTxEmpty
167
168 /**
169 * A snapshot of the state of the interrupts for this IP.
170 *
171 * This is an opaque type, to be used with the `dif_uart_irq_get_state()`
172 * and `dif_uart_irq_acknowledge_state()` functions.
173 */
175
176 /**
177 * Returns the type of a given interrupt (i.e., event or status) for this IP.
178 *
179 * @param uart A uart handle.
180 * @param irq An interrupt request.
181 * @param[out] type Out-param for the interrupt type.
182 * @return The result of the operation.
183 */
186 const dif_uart_t *uart,
187 dif_uart_irq_t,
188 dif_irq_type_t *type);
189
190 /**
191 * Returns the state of all interrupts (i.e., pending or not) for this IP.
192 *
193 * @param uart A uart handle.
194 * @param[out] snapshot Out-param for interrupt state snapshot.
195 * @return The result of the operation.
196 */
199 const dif_uart_t *uart,
201
202 /**
203 * Returns whether a particular interrupt is currently pending.
204 *
205 * @param uart A uart handle.
206 * @param irq An interrupt request.
207 * @param[out] is_pending Out-param for whether the interrupt is pending.
208 * @return The result of the operation.
209 */
212 const dif_uart_t *uart,
213 dif_uart_irq_t,
214 bool *is_pending);
215
216 /**
217 * Acknowledges all interrupts that were pending at the time of the state
218 * snapshot.
219 *
220 * @param uart A uart handle.
221 * @param snapshot Interrupt state snapshot.
222 * @return The result of the operation.
223 */
226 const dif_uart_t *uart,
228
229 /**
230 * Acknowledges all interrupts, indicating to the hardware that all
231 * interrupts have been successfully serviced.
232 *
233 * @param uart A uart handle.
234 * @return The result of the operation.
235 */
238 const dif_uart_t *uart
239 );
240
241 /**
242 * Acknowledges a particular interrupt, indicating to the hardware that it has
243 * been successfully serviced.
244 *
245 * @param uart A uart handle.
246 * @param irq An interrupt request.
247 * @return The result of the operation.
248 */
251 const dif_uart_t *uart,
252 dif_uart_irq_t);
253
254 /**
255 * Forces a particular interrupt, causing it to be serviced as if hardware had
256 * asserted it.
257 *
258 * @param uart A uart handle.
259 * @param irq An interrupt request.
260 * @param val Value to be set.
261 * @return The result of the operation.
262 */
265 const dif_uart_t *uart,
266 dif_uart_irq_t,
267 const bool val);
268
269 /**
270 * A snapshot of the enablement state of the interrupts for this IP.
271 *
272 * This is an opaque type, to be used with the
273 * `dif_uart_irq_disable_all()` and `dif_uart_irq_restore_all()`
274 * functions.
275 */
277
278 /**
279 * Checks whether a particular interrupt is currently enabled or disabled.
280 *
281 * @param uart A uart handle.
282 * @param irq An interrupt request.
283 * @param[out] state Out-param toggle state of the interrupt.
284 * @return The result of the operation.
285 */
288 const dif_uart_t *uart,
289 dif_uart_irq_t,
290 dif_toggle_t *state);
291
292 /**
293 * Sets whether a particular interrupt is currently enabled or disabled.
294 *
295 * @param uart A uart handle.
296 * @param irq An interrupt request.
297 * @param state The new toggle state for the interrupt.
298 * @return The result of the operation.
299 */
302 const dif_uart_t *uart,
303 dif_uart_irq_t,
304 dif_toggle_t state);
305
306 /**
307 * Disables all interrupts, optionally snapshotting all enable states for later
308 * restoration.
309 *
310 * @param uart A uart handle.
311 * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
312 * @return The result of the operation.
313 */
316 const dif_uart_t *uart,
318
319 /**
320 * Restores interrupts from the given (enable) snapshot.
321 *
322 * @param uart A uart handle.
323 * @param snapshot A snapshot to restore from.
324 * @return The result of the operation.
325 */
328 const dif_uart_t *uart,
329 const dif_uart_irq_enable_snapshot_t *snapshot);
330
331
332#ifdef __cplusplus
333} // extern "C"
334#endif // __cplusplus
335
336#endif // OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_UART_AUTOGEN_H_