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