Software APIs
sw
device
lib
dif
autogen
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
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 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
*/
36
mmio_region_t
base_addr
;
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
*/
48
OT_WARN_UNUSED_RESULT
49
dif_result_t
dif_i2c_init
(
mmio_region_t
base_addr,
dif_i2c_t
*i2c);
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
*/
59
kDifI2cAlertFatalFault
= 0,
60
}
dif_i2c_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 i2c A i2c 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_i2c_alert_force
(
const
dif_i2c_t
*i2c,
dif_i2c_alert_t
alert);
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
*/
81
kDifI2cIrqFmtThreshold
= 0,
82
/**
83
* Host mode interrupt: asserted whilst the RX FIFO level is above the high
84
* threshold. This is a level status interrupt.
85
*/
86
kDifI2cIrqRxThreshold
= 1,
87
/**
88
* Target mode interrupt: asserted whilst the ACQ FIFO level is above the high
89
* threshold. This is a level status interrupt.
90
*/
91
kDifI2cIrqAcqThreshold
= 2,
92
/**
93
* Host mode interrupt: raised if the RX FIFO has overflowed.
94
*/
95
kDifI2cIrqRxOverflow
= 3,
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
*/
102
kDifI2cIrqControllerHalt
= 4,
103
/**
104
* Host mode interrupt: raised if the SCL line drops early (not supported
105
* without clock synchronization).
106
*/
107
kDifI2cIrqSclInterference
= 5,
108
/**
109
* Host mode interrupt: raised if the SDA line goes low when host is trying to
110
* assert high
111
*/
112
kDifI2cIrqSdaInterference
= 6,
113
/**
114
* Host mode interrupt: raised if target stretches the clock beyond the
115
* allowed timeout period
116
*/
117
kDifI2cIrqStretchTimeout
= 7,
118
/**
119
* Host mode interrupt: raised if the target does not assert a constant value
120
* of SDA during transmission.
121
*/
122
kDifI2cIrqSdaUnstable
= 8,
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
*/
128
kDifI2cIrqCmdComplete
= 9,
129
/**
130
* Target mode interrupt: raised if the target is stretching clocks for a read
131
* command. This is a level status interrupt.
132
*/
133
kDifI2cIrqTxStretch
= 10,
134
/**
135
* Target mode interrupt: asserted whilst the TX FIFO level is below the low
136
* threshold. This is a level status interrupt.
137
*/
138
kDifI2cIrqTxThreshold
= 11,
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
*/
144
kDifI2cIrqAcqStretch
= 12,
145
/**
146
* Target mode interrupt: raised if STOP is received without a preceding NACK
147
* during an external host read.
148
*/
149
kDifI2cIrqUnexpStop
= 13,
150
/**
151
* Target mode interrupt: raised if the host stops sending the clock during an
152
* ongoing transaction.
153
*/
154
kDifI2cIrqHostTimeout
= 14,
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
*/
163
typedef
uint32_t
dif_i2c_irq_state_snapshot_t
;
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
*/
173
OT_WARN_UNUSED_RESULT
174
dif_result_t
dif_i2c_irq_get_type
(
const
dif_i2c_t
*i2c,
dif_i2c_irq_t
irq,
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
*/
184
OT_WARN_UNUSED_RESULT
185
dif_result_t
dif_i2c_irq_get_state
(
const
dif_i2c_t
*i2c,
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
*/
196
OT_WARN_UNUSED_RESULT
197
dif_result_t
dif_i2c_irq_is_pending
(
const
dif_i2c_t
*i2c,
dif_i2c_irq_t
irq,
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
*/
208
OT_WARN_UNUSED_RESULT
209
dif_result_t
dif_i2c_irq_acknowledge_state
(
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
*/
219
OT_WARN_UNUSED_RESULT
220
dif_result_t
dif_i2c_irq_acknowledge_all
(
const
dif_i2c_t
*i2c);
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
*/
230
OT_WARN_UNUSED_RESULT
231
dif_result_t
dif_i2c_irq_acknowledge
(
const
dif_i2c_t
*i2c,
dif_i2c_irq_t
irq);
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
*/
242
OT_WARN_UNUSED_RESULT
243
dif_result_t
dif_i2c_irq_force
(
const
dif_i2c_t
*i2c,
dif_i2c_irq_t
irq,
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
*/
253
typedef
uint32_t
dif_i2c_irq_enable_snapshot_t
;
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
*/
263
OT_WARN_UNUSED_RESULT
264
dif_result_t
dif_i2c_irq_get_enabled
(
const
dif_i2c_t
*i2c,
dif_i2c_irq_t
irq,
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
*/
275
OT_WARN_UNUSED_RESULT
276
dif_result_t
dif_i2c_irq_set_enabled
(
const
dif_i2c_t
*i2c,
dif_i2c_irq_t
irq,
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
*/
287
OT_WARN_UNUSED_RESULT
288
dif_result_t
dif_i2c_irq_disable_all
(
const
dif_i2c_t
*i2c,
289
dif_i2c_irq_enable_snapshot_t
*snapshot);
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
*/
298
OT_WARN_UNUSED_RESULT
299
dif_result_t
dif_i2c_irq_restore_all
(
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_
Return to
OpenTitan Documentation