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