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 a free buffer before the
118  * interrupt is cleared. If the condition is not cleared, the interrupt can
119  * re-assert.
120  */
122  /**
123  * Raised when the RX FIFO is full and the device interface is enabled. This
124  * interrupt is directly tied to the FIFO status, so the RX FIFO must have an
125  * entry removed before the interrupt is cleared. If the condition is not
126  * cleared, the interrupt can re-assert.
127  */
129  /**
130  * Raised if a write was done to either the Available OUT Buffer FIFO or the
131  * Available SETUP Buffer FIFO when the FIFO was full.
132  */
134  /**
135  * Raised if a packet to an IN endpoint started to be received but was then
136  * dropped due to an error. After transmitting the IN payload, the USB device
137  * expects a valid ACK handshake packet. This error is raised if either the
138  * packet or CRC is invalid, leading to a NAK instead, or if a different token
139  * was received.
140  */
142  /**
143  * Raised if a CRC error occurred on a received packet.
144  */
146  /**
147  * Raised if an invalid Packet IDentifier (PID) was received.
148  */
150  /**
151  * Raised if an invalid bitstuffing was received.
152  */
154  /**
155  * Raised when the USB frame number is updated with a valid SOF.
156  */
158  /**
159  * Raised if VBUS is applied.
160  */
162  /**
163  * Raised if a packet to an OUT endpoint started to be received but was then
164  * dropped due to an error. This error is raised if the data toggle, token,
165  * packet and/or CRC are invalid, or if the appropriate Available OUT Buffer
166  * FIFO is empty and/or the Received Buffer FIFO is full when a packet should
167  * have been received.
168  */
170  /**
171  * Raised when the Available SETUP Buffer FIFO is empty and the device
172  * interface is enabled. This interrupt is directly tied to the FIFO status,
173  * so the Available SETUP Buffer FIFO must be provided a free buffer before
174  * the interrupt is cleared. If the condition is not cleared, the interrupt
175  * can re-assert.
176  */
179 
180 /**
181  * A snapshot of the state of the interrupts for this IP.
182  *
183  * This is an opaque type, to be used with the `dif_usbdev_irq_get_state()`
184  * and `dif_usbdev_irq_acknowledge_state()` functions.
185  */
187 
188 /**
189  * Returns the type of a given interrupt (i.e., event or status) for this IP.
190  *
191  * @param usbdev A usbdev handle.
192  * @param irq An interrupt request.
193  * @param[out] type Out-param for the interrupt type.
194  * @return The result of the operation.
195  */
198  dif_usbdev_irq_t irq,
199  dif_irq_type_t *type);
200 
201 /**
202  * Returns the state of all interrupts (i.e., pending or not) for this IP.
203  *
204  * @param usbdev A usbdev handle.
205  * @param[out] snapshot Out-param for interrupt state snapshot.
206  * @return The result of the operation.
207  */
210  const dif_usbdev_t *usbdev, dif_usbdev_irq_state_snapshot_t *snapshot);
211 
212 /**
213  * Returns whether a particular interrupt is currently pending.
214  *
215  * @param usbdev A usbdev handle.
216  * @param irq An interrupt request.
217  * @param[out] is_pending Out-param for whether the interrupt is pending.
218  * @return The result of the operation.
219  */
222  dif_usbdev_irq_t irq, bool *is_pending);
223 
224 /**
225  * Acknowledges all interrupts that were pending at the time of the state
226  * snapshot.
227  *
228  * @param usbdev A usbdev handle.
229  * @param snapshot Interrupt state snapshot.
230  * @return The result of the operation.
231  */
234  const dif_usbdev_t *usbdev, dif_usbdev_irq_state_snapshot_t snapshot);
235 
236 /**
237  * Acknowledges all interrupts, indicating to the hardware that all
238  * interrupts have been successfully serviced.
239  *
240  * @param usbdev A usbdev handle.
241  * @return The result of the operation.
242  */
245 
246 /**
247  * Acknowledges a particular interrupt, indicating to the hardware that it has
248  * been successfully serviced.
249  *
250  * @param usbdev A usbdev handle.
251  * @param irq An interrupt request.
252  * @return The result of the operation.
253  */
256  dif_usbdev_irq_t irq);
257 
258 /**
259  * Forces a particular interrupt, causing it to be serviced as if hardware had
260  * asserted it.
261  *
262  * @param usbdev A usbdev handle.
263  * @param irq An interrupt request.
264  * @param val Value to be set.
265  * @return The result of the operation.
266  */
269  dif_usbdev_irq_t irq, const bool val);
270 
271 /**
272  * A snapshot of the enablement state of the interrupts for this IP.
273  *
274  * This is an opaque type, to be used with the
275  * `dif_usbdev_irq_disable_all()` and `dif_usbdev_irq_restore_all()`
276  * functions.
277  */
279 
280 /**
281  * Checks whether a particular interrupt is currently enabled or disabled.
282  *
283  * @param usbdev A usbdev handle.
284  * @param irq An interrupt request.
285  * @param[out] state Out-param toggle state of the interrupt.
286  * @return The result of the operation.
287  */
290  dif_usbdev_irq_t irq,
291  dif_toggle_t *state);
292 
293 /**
294  * Sets whether a particular interrupt is currently enabled or disabled.
295  *
296  * @param usbdev A usbdev handle.
297  * @param irq An interrupt request.
298  * @param state The new toggle state for the interrupt.
299  * @return The result of the operation.
300  */
303  dif_usbdev_irq_t irq,
304  dif_toggle_t state);
305 
306 /**
307  * Disables all interrupts, optionally snapshotting all enable states for later
308  * restoration.
309  *
310  * @param usbdev A usbdev handle.
311  * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
312  * @return The result of the operation.
313  */
316  const dif_usbdev_t *usbdev, dif_usbdev_irq_enable_snapshot_t *snapshot);
317 
318 /**
319  * Restores interrupts from the given (enable) snapshot.
320  *
321  * @param usbdev A usbdev handle.
322  * @param snapshot A snapshot to restore from.
323  * @return The result of the operation.
324  */
327  const dif_usbdev_t *usbdev,
328  const dif_usbdev_irq_enable_snapshot_t *snapshot);
329 
330 #ifdef __cplusplus
331 } // extern "C"
332 #endif // __cplusplus
333 
334 #endif // OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_USBDEV_AUTOGEN_H_