Software APIs
dif_i2c_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_I2C_AUTOGEN_H_
6 #define OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_I2C_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/i2c/">I2C</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 i2c.
29  *
30  * This type should be treated as opaque by users.
31  */
32 typedef struct dif_i2c {
33  /**
34  * The base address for the i2c hardware registers.
35  */
37 } dif_i2c_t;
38 
39 /**
40  * Creates a new handle for a(n) i2c peripheral.
41  *
42  * This function does not actuate the hardware.
43  *
44  * @param base_addr The MMIO base address of the i2c peripheral.
45  * @param[out] i2c Out param for the initialized handle.
46  * @return The result of the operation.
47  */
50 
51 /**
52  * A i2c alert type.
53  */
54 typedef enum dif_i2c_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 i2c A i2c handle.
67  * @param alert The alert to force.
68  * @return The result of the operation.
69  */
72 
73 /**
74  * A i2c interrupt request type.
75  */
76 typedef enum dif_i2c_irq {
77  /**
78  * Host mode interrupt: asserted whilst the FMT FIFO level is below the low
79  * threshold. This is a level status interrupt.
80  */
82  /**
83  * Host mode interrupt: asserted whilst the RX FIFO level is above the high
84  * threshold. This is a level status interrupt.
85  */
87  /**
88  * Target mode interrupt: asserted whilst the ACQ FIFO level is above the high
89  * threshold. This is a level status interrupt.
90  */
92  /**
93  * Host mode interrupt: raised if the RX FIFO has overflowed.
94  */
96  /**
97  * Host mode interrupt: raised if the controller FSM is halted, such as on an
98  * unexpected NACK. Check !!CONTROLLER_EVENTS for the reason. The interrupt
99  * will be released when the bits in !!CONTROLLER_EVENTS are cleared.
100  */
102  /**
103  * Host mode interrupt: raised if the SCL line drops early (not supported
104  * without clock synchronization).
105  */
107  /**
108  * Host mode interrupt: raised if the SDA line goes low when host is trying to
109  * assert high
110  */
112  /**
113  * Host mode interrupt: raised if target stretches the clock beyond the
114  * allowed timeout period
115  */
117  /**
118  * Host mode interrupt: raised if the target does not assert a constant value
119  * of SDA during transmission.
120  */
122  /**
123  * Host and target mode interrupt. In host mode, raised if the host issues a
124  * repeated START or terminates the transaction by issuing STOP. In target
125  * mode, raised if the external host issues a STOP or repeated START.
126  */
128  /**
129  * Target mode interrupt: raised if the target is stretching clocks for a read
130  * command. This is a level status interrupt.
131  */
133  /**
134  * Target mode interrupt: asserted whilst the TX FIFO level is below the low
135  * threshold. This is a level status interrupt.
136  */
138  /**
139  * Target mode interrupt: raised if the target is stretching clocks due to
140  * full ACQ FIFO or zero count in !!TARGET_ACK_CTRL.NBYTES (if enabled). This
141  * is a level status interrupt.
142  */
144  /**
145  * Target mode interrupt: raised if STOP is received without a preceding NACK
146  * during an external host read.
147  */
149  /**
150  * Target mode interrupt: raised if the host stops sending the clock during an
151  * ongoing transaction.
152  */
154 } dif_i2c_irq_t;
155 
156 /**
157  * A snapshot of the state of the interrupts for this IP.
158  *
159  * This is an opaque type, to be used with the `dif_i2c_irq_get_state()`
160  * and `dif_i2c_irq_acknowledge_state()` functions.
161  */
163 
164 /**
165  * Returns the type of a given interrupt (i.e., event or status) for this IP.
166  *
167  * @param i2c A i2c handle.
168  * @param irq An interrupt request.
169  * @param[out] type Out-param for the interrupt type.
170  * @return The result of the operation.
171  */
174  dif_irq_type_t *type);
175 
176 /**
177  * Returns the state of all interrupts (i.e., pending or not) for this IP.
178  *
179  * @param i2c A i2c handle.
180  * @param[out] snapshot Out-param for interrupt state snapshot.
181  * @return The result of the operation.
182  */
185  dif_i2c_irq_state_snapshot_t *snapshot);
186 
187 /**
188  * Returns whether a particular interrupt is currently pending.
189  *
190  * @param i2c A i2c handle.
191  * @param irq An interrupt request.
192  * @param[out] is_pending Out-param for whether the interrupt is pending.
193  * @return The result of the operation.
194  */
197  bool *is_pending);
198 
199 /**
200  * Acknowledges all interrupts that were pending at the time of the state
201  * snapshot.
202  *
203  * @param i2c A i2c handle.
204  * @param snapshot Interrupt state snapshot.
205  * @return The result of the operation.
206  */
209  const dif_i2c_t *i2c, dif_i2c_irq_state_snapshot_t snapshot);
210 
211 /**
212  * Acknowledges all interrupts, indicating to the hardware that all
213  * interrupts have been successfully serviced.
214  *
215  * @param i2c A i2c handle.
216  * @return The result of the operation.
217  */
220 
221 /**
222  * Acknowledges a particular interrupt, indicating to the hardware that it has
223  * been successfully serviced.
224  *
225  * @param i2c A i2c handle.
226  * @param irq An interrupt request.
227  * @return The result of the operation.
228  */
231 
232 /**
233  * Forces a particular interrupt, causing it to be serviced as if hardware had
234  * asserted it.
235  *
236  * @param i2c A i2c handle.
237  * @param irq An interrupt request.
238  * @param val Value to be set.
239  * @return The result of the operation.
240  */
243  const bool val);
244 
245 /**
246  * A snapshot of the enablement state of the interrupts for this IP.
247  *
248  * This is an opaque type, to be used with the
249  * `dif_i2c_irq_disable_all()` and `dif_i2c_irq_restore_all()`
250  * functions.
251  */
253 
254 /**
255  * Checks whether a particular interrupt is currently enabled or disabled.
256  *
257  * @param i2c A i2c handle.
258  * @param irq An interrupt request.
259  * @param[out] state Out-param toggle state of the interrupt.
260  * @return The result of the operation.
261  */
264  dif_toggle_t *state);
265 
266 /**
267  * Sets whether a particular interrupt is currently enabled or disabled.
268  *
269  * @param i2c A i2c handle.
270  * @param irq An interrupt request.
271  * @param state The new toggle state for the interrupt.
272  * @return The result of the operation.
273  */
276  dif_toggle_t state);
277 
278 /**
279  * Disables all interrupts, optionally snapshotting all enable states for later
280  * restoration.
281  *
282  * @param i2c A i2c handle.
283  * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
284  * @return The result of the operation.
285  */
289 
290 /**
291  * Restores interrupts from the given (enable) snapshot.
292  *
293  * @param i2c A i2c handle.
294  * @param snapshot A snapshot to restore from.
295  * @return The result of the operation.
296  */
299  const dif_i2c_t *i2c, const dif_i2c_irq_enable_snapshot_t *snapshot);
300 
301 #ifdef __cplusplus
302 } // extern "C"
303 #endif // __cplusplus
304 
305 #endif // OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_I2C_AUTOGEN_H_