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 or lost arbitration. Check !!CONTROLLER_EVENTS for the
99  * reason. The interrupt will be released when the bits in !!CONTROLLER_EVENTS
100  * are cleared.
101  */
103  /**
104  * Host mode interrupt: raised if the SCL line drops early (not supported
105  * without clock synchronization).
106  */
108  /**
109  * Host mode interrupt: raised if the SDA line goes low when host is trying to
110  * assert high
111  */
113  /**
114  * Host mode interrupt: raised if target stretches the clock beyond the
115  * allowed timeout period
116  */
118  /**
119  * Host mode interrupt: raised if the target does not assert a constant value
120  * of SDA during transmission.
121  */
123  /**
124  * Host and target mode interrupt. In host mode, raised if the host issues a
125  * repeated START or terminates the transaction by issuing STOP. In target
126  * mode, raised if the external host issues a STOP or repeated START.
127  */
129  /**
130  * Target mode interrupt: raised if the target is stretching clocks for a read
131  * command. This is a level status interrupt.
132  */
134  /**
135  * Target mode interrupt: asserted whilst the TX FIFO level is below the low
136  * threshold. This is a level status interrupt.
137  */
139  /**
140  * Target mode interrupt: raised if the target is stretching clocks due to
141  * full ACQ FIFO or zero count in !!TARGET_ACK_CTRL.NBYTES (if enabled). This
142  * is a level status interrupt.
143  */
145  /**
146  * Target mode interrupt: raised if STOP is received without a preceding NACK
147  * during an external host read.
148  */
150  /**
151  * Target mode interrupt: raised if the host stops sending the clock during an
152  * ongoing transaction.
153  */
155 } dif_i2c_irq_t;
156 
157 /**
158  * A snapshot of the state of the interrupts for this IP.
159  *
160  * This is an opaque type, to be used with the `dif_i2c_irq_get_state()`
161  * and `dif_i2c_irq_acknowledge_state()` functions.
162  */
164 
165 /**
166  * Returns the type of a given interrupt (i.e., event or status) for this IP.
167  *
168  * @param i2c A i2c handle.
169  * @param irq An interrupt request.
170  * @param[out] type Out-param for the interrupt type.
171  * @return The result of the operation.
172  */
175  dif_irq_type_t *type);
176 
177 /**
178  * Returns the state of all interrupts (i.e., pending or not) for this IP.
179  *
180  * @param i2c A i2c handle.
181  * @param[out] snapshot Out-param for interrupt state snapshot.
182  * @return The result of the operation.
183  */
186  dif_i2c_irq_state_snapshot_t *snapshot);
187 
188 /**
189  * Returns whether a particular interrupt is currently pending.
190  *
191  * @param i2c A i2c handle.
192  * @param irq An interrupt request.
193  * @param[out] is_pending Out-param for whether the interrupt is pending.
194  * @return The result of the operation.
195  */
198  bool *is_pending);
199 
200 /**
201  * Acknowledges all interrupts that were pending at the time of the state
202  * snapshot.
203  *
204  * @param i2c A i2c handle.
205  * @param snapshot Interrupt state snapshot.
206  * @return The result of the operation.
207  */
210  const dif_i2c_t *i2c, dif_i2c_irq_state_snapshot_t snapshot);
211 
212 /**
213  * Acknowledges all interrupts, indicating to the hardware that all
214  * interrupts have been successfully serviced.
215  *
216  * @param i2c A i2c handle.
217  * @return The result of the operation.
218  */
221 
222 /**
223  * Acknowledges a particular interrupt, indicating to the hardware that it has
224  * been successfully serviced.
225  *
226  * @param i2c A i2c handle.
227  * @param irq An interrupt request.
228  * @return The result of the operation.
229  */
232 
233 /**
234  * Forces a particular interrupt, causing it to be serviced as if hardware had
235  * asserted it.
236  *
237  * @param i2c A i2c handle.
238  * @param irq An interrupt request.
239  * @param val Value to be set.
240  * @return The result of the operation.
241  */
244  const bool val);
245 
246 /**
247  * A snapshot of the enablement state of the interrupts for this IP.
248  *
249  * This is an opaque type, to be used with the
250  * `dif_i2c_irq_disable_all()` and `dif_i2c_irq_restore_all()`
251  * functions.
252  */
254 
255 /**
256  * Checks whether a particular interrupt is currently enabled or disabled.
257  *
258  * @param i2c A i2c handle.
259  * @param irq An interrupt request.
260  * @param[out] state Out-param toggle state of the interrupt.
261  * @return The result of the operation.
262  */
265  dif_toggle_t *state);
266 
267 /**
268  * Sets whether a particular interrupt is currently enabled or disabled.
269  *
270  * @param i2c A i2c handle.
271  * @param irq An interrupt request.
272  * @param state The new toggle state for the interrupt.
273  * @return The result of the operation.
274  */
277  dif_toggle_t state);
278 
279 /**
280  * Disables all interrupts, optionally snapshotting all enable states for later
281  * restoration.
282  *
283  * @param i2c A i2c handle.
284  * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
285  * @return The result of the operation.
286  */
290 
291 /**
292  * Restores interrupts from the given (enable) snapshot.
293  *
294  * @param i2c A i2c handle.
295  * @param snapshot A snapshot to restore from.
296  * @return The result of the operation.
297  */
300  const dif_i2c_t *i2c, const dif_i2c_irq_enable_snapshot_t *snapshot);
301 
302 #ifdef __cplusplus
303 } // extern "C"
304 #endif // __cplusplus
305 
306 #endif // OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_I2C_AUTOGEN_H_