Software APIs
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 
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  */
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  */
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  */
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  */
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  */
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  */
91  /**
92  * Raised if VBUS is lost, thus the link is disconnected.
93  */
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  */
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  */
105  /**
106  * Raised if the line has signaled J for longer than 3ms and is therefore in
107  * suspend state.
108  */
110  /**
111  * Raised when the link becomes active again after being suspended.
112  */
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  */
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  */
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  */
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  */
141  /**
142  * Raised if a CRC error occurred on a received packet.
143  */
145  /**
146  * Raised if an invalid Packet IDentifier (PID) was received.
147  */
149  /**
150  * Raised if an invalid bitstuffing was received.
151  */
153  /**
154  * Raised when the USB frame number is updated with a valid SOF.
155  */
157  /**
158  * Raised if VBUS is applied.
159  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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_