Software APIs
dt_uart.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_UART_H_
8#define OPENTITAN_DT_UART_H_
9
10/**
11 * @file
12 * @brief Device Tables (DT) for IP uart and top earlgrey.
13 *
14 * This file contains the type definitions and global functions of the uart.
15 */
16
17#include "dt_api.h"
18#include <stdint.h>
19
20/**
21 * List of instances.
22 */
23typedef enum dt_uart {
24 kDtUart0 = 0, /**< uart0 */
25 kDtUart1 = 1, /**< uart1 */
26 kDtUart2 = 2, /**< uart2 */
27 kDtUart3 = 3, /**< uart3 */
28 kDtUartFirst = 0, /**< \internal First instance */
29 kDtUartCount = 4, /**< \internal Number of instances */
31
32/**
33 * List of register blocks.
34 *
35 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
36 */
37typedef enum dt_uart_reg_block {
38 kDtUartRegBlockCore = 0, /**< */
39 kDtUartRegBlockCount = 1, /**< \internal Number of register blocks */
41
42/** Primary register block (associated with the "primary" set of registers that control the IP). */
43static const dt_uart_reg_block_t kDtUartRegBlockPrimary = kDtUartRegBlockCore;
44
45/**
46 * List of IRQs.
47 *
48 * IRQs are guaranteed to be numbered consecutively from 0.
49 */
50typedef enum dt_uart_irq {
51 kDtUartIrqTxWatermark = 0, /**< raised if the transmit FIFO is past the high-water mark. */
52 kDtUartIrqRxWatermark = 1, /**< raised if the receive FIFO is past the high-water mark. */
53 kDtUartIrqTxDone = 2, /**< raised if the transmit FIFO has emptied and no transmit is ongoing. */
54 kDtUartIrqRxOverflow = 3, /**< raised if the receive FIFO has overflowed. */
55 kDtUartIrqRxFrameErr = 4, /**< raised if a framing error has been detected on receive. */
56 kDtUartIrqRxBreakErr = 5, /**< raised if break condition has been detected on receive. */
57 kDtUartIrqRxTimeout = 6, /**< raised if RX FIFO has characters remaining in the FIFO without being
58retrieved for the programmed time period. */
59 kDtUartIrqRxParityErr = 7, /**< raised if the receiver has detected a parity error. */
60 kDtUartIrqTxEmpty = 8, /**< raised if the transmit FIFO is empty. */
61 kDtUartIrqCount = 9, /**< \internal Number of IRQs */
63
64/**
65 * List of Alerts.
66 *
67 * Alerts are guaranteed to be numbered consecutively from 0.
68 */
69typedef enum dt_uart_alert {
70 kDtUartAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
71 kDtUartAlertCount = 1, /**< \internal Number of Alerts */
73
74/**
75 * List of clock ports.
76 *
77 * Clock ports are guaranteed to be numbered consecutively from 0.
78 */
79typedef enum dt_uart_clock {
80 kDtUartClockClk = 0, /**< Clock port clk_i */
81 kDtUartClockCount = 1, /**< \internal Number of clock ports */
83
84/**
85 * List of reset ports.
86 *
87 * Reset ports are guaranteed to be numbered consecutively from 0.
88 */
89typedef enum dt_uart_reset {
90 kDtUartResetRst = 0, /**< Reset port rst_ni */
91 kDtUartResetCount = 1, /**< \internal Number of reset ports */
93
94/**
95 * List of peripheral I/O.
96 *
97 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
98 */
99typedef enum dt_uart_periph_io {
100 kDtUartPeriphIoRx = 0, /**< */
101 kDtUartPeriphIoTx = 1, /**< */
102 kDtUartPeriphIoCount = 2, /**< \internal Number of peripheral I/O */
104
105/**
106 * List of supported hardware features.
107 */
108#define OPENTITAN_UART_HAS_PARITY 1
109#define OPENTITAN_UART_HAS_LINE_LOOPBACK 1
110#define OPENTITAN_UART_HAS_SYSTEM_LOOPBACK 1
111#define OPENTITAN_UART_HAS_BAUD_RATE_CONTROL 1
112#define OPENTITAN_UART_HAS_LINE_BREAK 1
113#define OPENTITAN_UART_HAS_FIFO_INTERRUPTS 1
114
115
116
117/**
118 * Get the uart instance from an instance ID
119 *
120 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
121 *
122 * @param inst_id Instance ID.
123 * @return A uart instance.
124 *
125 * **Note:** This function only makes sense if the instance ID has device type uart,
126 * otherwise the returned value is unspecified.
127 */
129
130/**
131 * Get the instance ID of an instance.
132 *
133 * @param dt Instance of uart.
134 * @return The instance ID of that instance.
135 */
137
138/**
139 * Get the register base address of an instance.
140 *
141 * @param dt Instance of uart.
142 * @param reg_block The register block requested.
143 * @return The register base address of the requested block.
144 */
145uint32_t dt_uart_reg_block(
146 dt_uart_t dt,
147 dt_uart_reg_block_t reg_block);
148
149/**
150 * Get the primary register base address of an instance.
151 *
152 * This is just a convenience function, equivalent to
153 * `dt_uart_reg_block(dt, kDtUartRegBlockCore)`
154 *
155 * @param dt Instance of uart.
156 * @return The register base address of the primary register block.
157 */
158static inline uint32_t dt_uart_primary_reg_block(
159 dt_uart_t dt) {
160 return dt_uart_reg_block(dt, kDtUartRegBlockCore);
161}
162
163/**
164 * Get the PLIC ID of a uart IRQ for a given instance.
165 *
166 * If the instance is not connected to the PLIC, this function
167 * will return `kDtPlicIrqIdNone`.
168 *
169 * @param dt Instance of uart.
170 * @param irq A uart IRQ.
171 * @return The PLIC ID of the IRQ of this instance.
172 */
174 dt_uart_t dt,
175 dt_uart_irq_t irq);
176
177/**
178 * Convert a global IRQ ID to a local uart IRQ type.
179 *
180 * @param dt Instance of uart.
181 * @param irq A PLIC ID that belongs to this instance.
182 * @return The uart IRQ, or `kDtUartIrqCount`.
183 *
184 * **Note:** This function assumes that the PLIC ID belongs to the instance
185 * of uart passed in parameter. In other words, it must be the case that
186 * `dt_uart_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
187 * will return `kDtUartIrqCount`.
188 */
190 dt_uart_t dt,
191 dt_plic_irq_id_t irq);
192
193
194/**
195 * Get the alert ID of a uart alert for a given instance.
196 *
197 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
198 * instances where the instance is not connected, the return value is unspecified.
199 *
200 * @param dt Instance of uart.
201 * @param alert A uart alert.
202 * @return The Alert Handler alert ID of the alert of this instance.
203 */
205 dt_uart_t dt,
206 dt_uart_alert_t alert);
207
208/**
209 * Convert a global alert ID to a local uart alert type.
210 *
211 * @param dt Instance of uart.
212 * @param alert A global alert ID that belongs to this instance.
213 * @return The uart alert, or `kDtUartAlertCount`.
214 *
215 * **Note:** This function assumes that the global alert ID belongs to the
216 * instance of uart passed in parameter. In other words, it must be the case
217 * that `dt_uart_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
218 * this function will return `kDtUartAlertCount`.
219 */
221 dt_uart_t dt,
222 dt_alert_id_t alert);
223
224
225/**
226 * Get the peripheral I/O description of an instance.
227 *
228 * @param dt Instance of uart.
229 * @param sig Requested peripheral I/O.
230 * @return Description of the requested peripheral I/O for this instance.
231 */
233 dt_uart_t dt,
235
236/**
237 * Get the clock signal connected to a clock port of an instance.
238 *
239 * @param dt Instance of uart.
240 * @param clk Clock port.
241 * @return Clock signal.
242 */
244 dt_uart_t dt,
245 dt_uart_clock_t clk);
246
247/**
248 * Get the reset signal connected to a reset port of an instance.
249 *
250 * @param dt Instance of uart.
251 * @param rst Reset port.
252 * @return Reset signal.
253 */
255 dt_uart_t dt,
256 dt_uart_reset_t rst);
257
258
259
260#endif // OPENTITAN_DT_UART_H_