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