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