Software APIs
sw
device
lib
dif
autogen
dif_usbdev_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_USBDEV_AUTOGEN_H_
6
#define OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_USBDEV_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/usbdev/">USBDEV</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 usbdev.
29
*
30
* This type should be treated as opaque by users.
31
*/
32
typedef
struct
dif_usbdev
{
33
/**
34
* The base address for the usbdev hardware registers.
35
*/
36
mmio_region_t
base_addr
;
37
}
dif_usbdev_t
;
38
39
/**
40
* Creates a new handle for a(n) usbdev peripheral.
41
*
42
* This function does not actuate the hardware.
43
*
44
* @param base_addr The MMIO base address of the usbdev peripheral.
45
* @param[out] usbdev Out param for the initialized handle.
46
* @return The result of the operation.
47
*/
48
OT_WARN_UNUSED_RESULT
49
dif_result_t
dif_usbdev_init
(
mmio_region_t
base_addr,
dif_usbdev_t
*usbdev);
50
51
/**
52
* A usbdev alert type.
53
*/
54
typedef
enum
dif_usbdev_alert
{
55
/**
56
* This fatal alert is triggered when a fatal TL-UL bus integrity fault is
57
* detected.
58
*/
59
kDifUsbdevAlertFatalFault
= 0,
60
}
dif_usbdev_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 usbdev A usbdev 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_usbdev_alert_force
(
const
dif_usbdev_t
*usbdev,
72
dif_usbdev_alert_t
alert);
73
74
/**
75
* A usbdev interrupt request type.
76
*/
77
typedef
enum
dif_usbdev_irq
{
78
/**
79
* Raised if a packet was received using an OUT or SETUP transaction. This
80
* interrupt is directly tied to whether the RX FIFO is empty, so it should be
81
* cleared only after handling the FIFO entry.
82
*/
83
kDifUsbdevIrqPktReceived
= 0,
84
/**
85
* Raised if a packet was sent as part of an IN transaction. This interrupt is
86
* directly tied to whether a sent packet has not been acknowledged in the
87
* !!in_sent register. It should be cleared only after clearing all bits in
88
* the !!in_sent register.
89
*/
90
kDifUsbdevIrqPktSent
= 1,
91
/**
92
* Raised if VBUS is lost, thus the link is disconnected.
93
*/
94
kDifUsbdevIrqDisconnected
= 2,
95
/**
96
* Raised if link is active but SOF was not received from host for 4.096 ms.
97
* The SOF should be every 1 ms.
98
*/
99
kDifUsbdevIrqHostLost
= 3,
100
/**
101
* Raised if the link is at SE0 longer than 3 us indicating a link reset (host
102
* asserts for min 10 ms, device can react after 2.5 us).
103
*/
104
kDifUsbdevIrqLinkReset
= 4,
105
/**
106
* Raised if the line has signaled J for longer than 3ms and is therefore in
107
* suspend state.
108
*/
109
kDifUsbdevIrqLinkSuspend
= 5,
110
/**
111
* Raised when the link becomes active again after being suspended.
112
*/
113
kDifUsbdevIrqLinkResume
= 6,
114
/**
115
* Raised when the Available OUT Buffer FIFO is empty and the device interface
116
* is enabled. This interrupt is directly tied to the FIFO status, so the
117
* Available OUT Buffer FIFO must be provided with a free buffer before the
118
* interrupt can be cleared.
119
*/
120
kDifUsbdevIrqAvOutEmpty
= 7,
121
/**
122
* Raised when the RX FIFO is full and the device interface is enabled. This
123
* interrupt is directly tied to the FIFO status, so the RX FIFO must have an
124
* entry removed before the interrupt is cleared. If the condition is not
125
* cleared, the interrupt can re-assert.
126
*/
127
kDifUsbdevIrqRxFull
= 8,
128
/**
129
* Raised if a write was done to either the Available OUT Buffer FIFO or the
130
* Available SETUP Buffer FIFO when the FIFO was full.
131
*/
132
kDifUsbdevIrqAvOverflow
= 9,
133
/**
134
* Raised if a packet to an IN endpoint started to be received but was then
135
* dropped due to an error. After transmitting the IN payload, the USB device
136
* expects a valid ACK handshake packet. This error is raised if either the
137
* packet or CRC is invalid, leading to a NAK instead, or if a different token
138
* was received.
139
*/
140
kDifUsbdevIrqLinkInErr
= 10,
141
/**
142
* Raised if a CRC error occurred on a received packet.
143
*/
144
kDifUsbdevIrqRxCrcErr
= 11,
145
/**
146
* Raised if an invalid Packet IDentifier (PID) was received.
147
*/
148
kDifUsbdevIrqRxPidErr
= 12,
149
/**
150
* Raised if an invalid bitstuffing was received.
151
*/
152
kDifUsbdevIrqRxBitstuffErr
= 13,
153
/**
154
* Raised when the USB frame number is updated with a valid SOF.
155
*/
156
kDifUsbdevIrqFrame
= 14,
157
/**
158
* Raised if VBUS is applied.
159
*/
160
kDifUsbdevIrqPowered
= 15,
161
/**
162
* Raised if a packet to an OUT endpoint started to be received but was then
163
* dropped due to an error. This error is raised if the data toggle, token,
164
* packet and/or CRC are invalid, or if the appropriate Available OUT Buffer
165
* FIFO is empty and/or the Received Buffer FIFO is full when a packet should
166
* have been received.
167
*/
168
kDifUsbdevIrqLinkOutErr
= 16,
169
/**
170
* Raised when the Available SETUP Buffer FIFO is empty and the device
171
* interface is enabled. This interrupt is directly tied to the FIFO status,
172
* so the Available SETUP Buffer FIFO must be provided with a free buffer
173
* before the interrupt can be cleared.
174
*/
175
kDifUsbdevIrqAvSetupEmpty
= 17,
176
}
dif_usbdev_irq_t
;
177
178
/**
179
* A snapshot of the state of the interrupts for this IP.
180
*
181
* This is an opaque type, to be used with the `dif_usbdev_irq_get_state()`
182
* and `dif_usbdev_irq_acknowledge_state()` functions.
183
*/
184
typedef
uint32_t
dif_usbdev_irq_state_snapshot_t
;
185
186
/**
187
* Returns the type of a given interrupt (i.e., event or status) for this IP.
188
*
189
* @param usbdev A usbdev handle.
190
* @param irq An interrupt request.
191
* @param[out] type Out-param for the interrupt type.
192
* @return The result of the operation.
193
*/
194
OT_WARN_UNUSED_RESULT
195
dif_result_t
dif_usbdev_irq_get_type
(
const
dif_usbdev_t
*usbdev,
196
dif_usbdev_irq_t
irq,
197
dif_irq_type_t
*type);
198
199
/**
200
* Returns the state of all interrupts (i.e., pending or not) for this IP.
201
*
202
* @param usbdev A usbdev handle.
203
* @param[out] snapshot Out-param for interrupt state snapshot.
204
* @return The result of the operation.
205
*/
206
OT_WARN_UNUSED_RESULT
207
dif_result_t
dif_usbdev_irq_get_state
(
208
const
dif_usbdev_t
*usbdev,
dif_usbdev_irq_state_snapshot_t
*snapshot);
209
210
/**
211
* Returns whether a particular interrupt is currently pending.
212
*
213
* @param usbdev A usbdev handle.
214
* @param irq An interrupt request.
215
* @param[out] is_pending Out-param for whether the interrupt is pending.
216
* @return The result of the operation.
217
*/
218
OT_WARN_UNUSED_RESULT
219
dif_result_t
dif_usbdev_irq_is_pending
(
const
dif_usbdev_t
*usbdev,
220
dif_usbdev_irq_t
irq,
bool
*is_pending);
221
222
/**
223
* Acknowledges all interrupts that were pending at the time of the state
224
* snapshot.
225
*
226
* @param usbdev A usbdev handle.
227
* @param snapshot Interrupt state snapshot.
228
* @return The result of the operation.
229
*/
230
OT_WARN_UNUSED_RESULT
231
dif_result_t
dif_usbdev_irq_acknowledge_state
(
232
const
dif_usbdev_t
*usbdev,
dif_usbdev_irq_state_snapshot_t
snapshot);
233
234
/**
235
* Acknowledges all interrupts, indicating to the hardware that all
236
* interrupts have been successfully serviced.
237
*
238
* @param usbdev A usbdev handle.
239
* @return The result of the operation.
240
*/
241
OT_WARN_UNUSED_RESULT
242
dif_result_t
dif_usbdev_irq_acknowledge_all
(
const
dif_usbdev_t
*usbdev);
243
244
/**
245
* Acknowledges a particular interrupt, indicating to the hardware that it has
246
* been successfully serviced.
247
*
248
* @param usbdev A usbdev handle.
249
* @param irq An interrupt request.
250
* @return The result of the operation.
251
*/
252
OT_WARN_UNUSED_RESULT
253
dif_result_t
dif_usbdev_irq_acknowledge
(
const
dif_usbdev_t
*usbdev,
254
dif_usbdev_irq_t
irq);
255
256
/**
257
* Forces a particular interrupt, causing it to be serviced as if hardware had
258
* asserted it.
259
*
260
* @param usbdev A usbdev handle.
261
* @param irq An interrupt request.
262
* @param val Value to be set.
263
* @return The result of the operation.
264
*/
265
OT_WARN_UNUSED_RESULT
266
dif_result_t
dif_usbdev_irq_force
(
const
dif_usbdev_t
*usbdev,
267
dif_usbdev_irq_t
irq,
const
bool
val);
268
269
/**
270
* A snapshot of the enablement state of the interrupts for this IP.
271
*
272
* This is an opaque type, to be used with the
273
* `dif_usbdev_irq_disable_all()` and `dif_usbdev_irq_restore_all()`
274
* functions.
275
*/
276
typedef
uint32_t
dif_usbdev_irq_enable_snapshot_t
;
277
278
/**
279
* Checks whether a particular interrupt is currently enabled or disabled.
280
*
281
* @param usbdev A usbdev handle.
282
* @param irq An interrupt request.
283
* @param[out] state Out-param toggle state of the interrupt.
284
* @return The result of the operation.
285
*/
286
OT_WARN_UNUSED_RESULT
287
dif_result_t
dif_usbdev_irq_get_enabled
(
const
dif_usbdev_t
*usbdev,
288
dif_usbdev_irq_t
irq,
289
dif_toggle_t
*state);
290
291
/**
292
* Sets whether a particular interrupt is currently enabled or disabled.
293
*
294
* @param usbdev A usbdev handle.
295
* @param irq An interrupt request.
296
* @param state The new toggle state for the interrupt.
297
* @return The result of the operation.
298
*/
299
OT_WARN_UNUSED_RESULT
300
dif_result_t
dif_usbdev_irq_set_enabled
(
const
dif_usbdev_t
*usbdev,
301
dif_usbdev_irq_t
irq,
302
dif_toggle_t
state);
303
304
/**
305
* Disables all interrupts, optionally snapshotting all enable states for later
306
* restoration.
307
*
308
* @param usbdev A usbdev handle.
309
* @param[out] snapshot Out-param for the snapshot; may be `NULL`.
310
* @return The result of the operation.
311
*/
312
OT_WARN_UNUSED_RESULT
313
dif_result_t
dif_usbdev_irq_disable_all
(
314
const
dif_usbdev_t
*usbdev,
dif_usbdev_irq_enable_snapshot_t
*snapshot);
315
316
/**
317
* Restores interrupts from the given (enable) snapshot.
318
*
319
* @param usbdev A usbdev handle.
320
* @param snapshot A snapshot to restore from.
321
* @return The result of the operation.
322
*/
323
OT_WARN_UNUSED_RESULT
324
dif_result_t
dif_usbdev_irq_restore_all
(
325
const
dif_usbdev_t
*usbdev,
326
const
dif_usbdev_irq_enable_snapshot_t
*snapshot);
327
328
#ifdef __cplusplus
329
}
// extern "C"
330
#endif
// __cplusplus
331
332
#endif
// OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_USBDEV_AUTOGEN_H_
Return to
OpenTitan Documentation