Software APIs
sw
device
lib
dif
autogen
dif_uart_autogen.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
#ifndef OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_UART_AUTOGEN_H_
6
#define OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_UART_AUTOGEN_H_
7
8
// THIS FILE HAS BEEN GENERATED, DO NOT EDIT MANUALLY. COMMAND:
9
// util/make_new_dif.py --mode=regen --only=autogen
10
11
/**
12
* @file
13
* @brief <a href="/book/hw/ip/uart/">UART</a> Device Interface Functions
14
*/
15
16
#include <
stdbool.h
>
17
#include <
stdint.h
>
18
19
#include "
sw/device/lib/base/macros.h
"
20
#include "
sw/device/lib/base/mmio.h
"
21
#include "
sw/device/lib/dif/dif_base.h
"
22
23
#ifdef __cplusplus
24
extern
"C"
{
25
#endif
// __cplusplus
26
27
/**
28
* A handle to uart.
29
*
30
* This type should be treated as opaque by users.
31
*/
32
typedef
struct
dif_uart
{
33
/**
34
* The base address for the uart hardware registers.
35
*/
36
mmio_region_t
base_addr
;
37
}
dif_uart_t
;
38
39
/**
40
* Creates a new handle for a(n) uart peripheral.
41
*
42
* This function does not actuate the hardware.
43
*
44
* @param base_addr The MMIO base address of the uart peripheral.
45
* @param[out] uart Out param for the initialized handle.
46
* @return The result of the operation.
47
*/
48
OT_WARN_UNUSED_RESULT
49
dif_result_t
dif_uart_init
(
mmio_region_t
base_addr,
dif_uart_t
*uart);
50
51
/**
52
* A uart alert type.
53
*/
54
typedef
enum
dif_uart_alert
{
55
/**
56
* This fatal alert is triggered when a fatal TL-UL bus integrity fault is
57
* detected.
58
*/
59
kDifUartAlertFatalFault
= 0,
60
}
dif_uart_alert_t
;
61
62
/**
63
* Forces a particular alert, causing it to be escalated as if the hardware
64
* had raised it.
65
*
66
* @param uart A uart handle.
67
* @param alert The alert to force.
68
* @return The result of the operation.
69
*/
70
OT_WARN_UNUSED_RESULT
71
dif_result_t
dif_uart_alert_force
(
const
dif_uart_t
*uart,
72
dif_uart_alert_t
alert);
73
74
/**
75
* A uart interrupt request type.
76
*/
77
typedef
enum
dif_uart_irq
{
78
/**
79
* Raised if the transmit FIFO is past the high-water mark.
80
*/
81
kDifUartIrqTxWatermark
= 0,
82
/**
83
* Raised if the receive FIFO is past the high-water mark.
84
*/
85
kDifUartIrqRxWatermark
= 1,
86
/**
87
* Raised if the transmit FIFO has emptied and no transmit is ongoing.
88
*/
89
kDifUartIrqTxDone
= 2,
90
/**
91
* Raised if the receive FIFO has overflowed.
92
*/
93
kDifUartIrqRxOverflow
= 3,
94
/**
95
* Raised if a framing error has been detected on receive.
96
*/
97
kDifUartIrqRxFrameErr
= 4,
98
/**
99
* Raised if break condition has been detected on receive.
100
*/
101
kDifUartIrqRxBreakErr
= 5,
102
/**
103
* Raised if RX FIFO has characters remaining in the FIFO without being
104
* retrieved for the programmed time period.
105
*/
106
kDifUartIrqRxTimeout
= 6,
107
/**
108
* Raised if the receiver has detected a parity error.
109
*/
110
kDifUartIrqRxParityErr
= 7,
111
/**
112
* Raised if the transmit FIFO is empty.
113
*/
114
kDifUartIrqTxEmpty
= 8,
115
}
dif_uart_irq_t
;
116
117
/**
118
* A snapshot of the state of the interrupts for this IP.
119
*
120
* This is an opaque type, to be used with the `dif_uart_irq_get_state()`
121
* and `dif_uart_irq_acknowledge_state()` functions.
122
*/
123
typedef
uint32_t
dif_uart_irq_state_snapshot_t
;
124
125
/**
126
* Returns the type of a given interrupt (i.e., event or status) for this IP.
127
*
128
* @param uart A uart handle.
129
* @param irq An interrupt request.
130
* @param[out] type Out-param for the interrupt type.
131
* @return The result of the operation.
132
*/
133
OT_WARN_UNUSED_RESULT
134
dif_result_t
dif_uart_irq_get_type
(
const
dif_uart_t
*uart,
dif_uart_irq_t
irq,
135
dif_irq_type_t
*type);
136
137
/**
138
* Returns the state of all interrupts (i.e., pending or not) for this IP.
139
*
140
* @param uart A uart handle.
141
* @param[out] snapshot Out-param for interrupt state snapshot.
142
* @return The result of the operation.
143
*/
144
OT_WARN_UNUSED_RESULT
145
dif_result_t
dif_uart_irq_get_state
(
const
dif_uart_t
*uart,
146
dif_uart_irq_state_snapshot_t
*snapshot);
147
148
/**
149
* Returns whether a particular interrupt is currently pending.
150
*
151
* @param uart A uart handle.
152
* @param irq An interrupt request.
153
* @param[out] is_pending Out-param for whether the interrupt is pending.
154
* @return The result of the operation.
155
*/
156
OT_WARN_UNUSED_RESULT
157
dif_result_t
dif_uart_irq_is_pending
(
const
dif_uart_t
*uart,
dif_uart_irq_t
irq,
158
bool
*is_pending);
159
160
/**
161
* Acknowledges all interrupts that were pending at the time of the state
162
* snapshot.
163
*
164
* @param uart A uart handle.
165
* @param snapshot Interrupt state snapshot.
166
* @return The result of the operation.
167
*/
168
OT_WARN_UNUSED_RESULT
169
dif_result_t
dif_uart_irq_acknowledge_state
(
170
const
dif_uart_t
*uart,
dif_uart_irq_state_snapshot_t
snapshot);
171
172
/**
173
* Acknowledges all interrupts, indicating to the hardware that all
174
* interrupts have been successfully serviced.
175
*
176
* @param uart A uart handle.
177
* @return The result of the operation.
178
*/
179
OT_WARN_UNUSED_RESULT
180
dif_result_t
dif_uart_irq_acknowledge_all
(
const
dif_uart_t
*uart);
181
182
/**
183
* Acknowledges a particular interrupt, indicating to the hardware that it has
184
* been successfully serviced.
185
*
186
* @param uart A uart handle.
187
* @param irq An interrupt request.
188
* @return The result of the operation.
189
*/
190
OT_WARN_UNUSED_RESULT
191
dif_result_t
dif_uart_irq_acknowledge
(
const
dif_uart_t
*uart,
192
dif_uart_irq_t
irq);
193
194
/**
195
* Forces a particular interrupt, causing it to be serviced as if hardware had
196
* asserted it.
197
*
198
* @param uart A uart handle.
199
* @param irq An interrupt request.
200
* @param val Value to be set.
201
* @return The result of the operation.
202
*/
203
OT_WARN_UNUSED_RESULT
204
dif_result_t
dif_uart_irq_force
(
const
dif_uart_t
*uart,
dif_uart_irq_t
irq,
205
const
bool
val);
206
207
/**
208
* A snapshot of the enablement state of the interrupts for this IP.
209
*
210
* This is an opaque type, to be used with the
211
* `dif_uart_irq_disable_all()` and `dif_uart_irq_restore_all()`
212
* functions.
213
*/
214
typedef
uint32_t
dif_uart_irq_enable_snapshot_t
;
215
216
/**
217
* Checks whether a particular interrupt is currently enabled or disabled.
218
*
219
* @param uart A uart handle.
220
* @param irq An interrupt request.
221
* @param[out] state Out-param toggle state of the interrupt.
222
* @return The result of the operation.
223
*/
224
OT_WARN_UNUSED_RESULT
225
dif_result_t
dif_uart_irq_get_enabled
(
const
dif_uart_t
*uart,
226
dif_uart_irq_t
irq,
dif_toggle_t
*state);
227
228
/**
229
* Sets whether a particular interrupt is currently enabled or disabled.
230
*
231
* @param uart A uart handle.
232
* @param irq An interrupt request.
233
* @param state The new toggle state for the interrupt.
234
* @return The result of the operation.
235
*/
236
OT_WARN_UNUSED_RESULT
237
dif_result_t
dif_uart_irq_set_enabled
(
const
dif_uart_t
*uart,
238
dif_uart_irq_t
irq,
dif_toggle_t
state);
239
240
/**
241
* Disables all interrupts, optionally snapshotting all enable states for later
242
* restoration.
243
*
244
* @param uart A uart handle.
245
* @param[out] snapshot Out-param for the snapshot; may be `NULL`.
246
* @return The result of the operation.
247
*/
248
OT_WARN_UNUSED_RESULT
249
dif_result_t
dif_uart_irq_disable_all
(
const
dif_uart_t
*uart,
250
dif_uart_irq_enable_snapshot_t
*snapshot);
251
252
/**
253
* Restores interrupts from the given (enable) snapshot.
254
*
255
* @param uart A uart handle.
256
* @param snapshot A snapshot to restore from.
257
* @return The result of the operation.
258
*/
259
OT_WARN_UNUSED_RESULT
260
dif_result_t
dif_uart_irq_restore_all
(
261
const
dif_uart_t
*uart,
const
dif_uart_irq_enable_snapshot_t
*snapshot);
262
263
#ifdef __cplusplus
264
}
// extern "C"
265
#endif
// __cplusplus
266
267
#endif
// OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_UART_AUTOGEN_H_
Return to
OpenTitan Documentation