RV32 SoC DS UG
High-Perf RV32 SoC DS UG
RV64 SoC DS UG API and Examples
Embedded IDE UG
Loading...
Searching...
No Matches
i2c.h
Go to the documentation of this file.
1
2// Copyright (C) 2013-2026 Efinix Inc. All rights reserved.
3// Full license header bsp/efinix/EfxSapphireSocRV64/include/LICENSE.MD
5
6#ifndef I2C_H
7#define I2C_H
8
19
20
21#include <stdint.h>
22#include "type.h"
23#include "soc.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
68
69/* ========================================================================== */
70/* SUB-GROUP : REGISTER DEFINITIONS */
71/* ========================================================================== */
72
82 #define I2C_MODE_CPOL (1 << 0)
83 #define I2C_MODE_CPHA (1 << 1)
85
89 #define I2C_TX_VALUE (0xFF)
90 #define I2C_TX_VALID (1 << 8)
91 #define I2C_TX_ENABLE (1 << 9)
92 #define I2C_TX_REPEAT (1 << 10)
93 #define I2C_TX_DISABLE_ON_DATA_CONFLICT (1 << 11)
94 #define I2C_RX_VALUE (0xFF)
95 #define I2C_RX_VALID (1 << 8)
96 #define I2C_RX_LISTEN (1 << 9)
98
102 #define I2C_MASTER_BUSY (1 << 0)
103 #define I2C_MASTER_START (1 << 4)
104 #define I2C_MASTER_STOP (1 << 5)
105 #define I2C_MASTER_DROP (1 << 6)
106 #define I2C_MASTER_RECOVER (1 << 7)
107 #define I2C_MASTER_START_DROPPED (1 << 9)
108 #define I2C_MASTER_STOP_DROPPED (1 << 10)
109 #define I2C_MASTER_RECOVER_DROPPED (1 << 11)
110 #define I2C_SLAVE_STATUS_IN_FRAME (1 << 0)
111 #define I2C_SLAVE_STATUS_SDA (1 << 1)
112 #define I2C_SLAVE_STATUS_SCL (1 << 2)
113 #define I2C_SLAVE_OVERRIDE_SDA (1 << 1)
114 #define I2C_SLAVE_OVERRIDE_SCL (1 << 2)
116
120 #define I2C_FILTER_7_BITS (0)
121 #define I2C_FILTER_10_BITS (1 << 14)
122 #define I2C_FILTER_ENABLE (1 << 15)
124
128 #define I2C_READ 0x01
129 #define I2C_WRITE 0x00
131
132
149 #ifndef TX_AND_CHECK
150 #define TX_AND_CHECK(inst, byte) \
151 do { \
152 i2c_sendTxByte(inst, (byte)); \
153 i2c_sendNackBlocking(inst); \
154 i2c_waitRxAck(inst); \
155 } while(0)
156 #endif
158 // End of I2C_Macros group
160
161/* ========================================================================== */
162/* SUB-GROUP : Data Types */
163/* ========================================================================== */
164
171
176
191
192 // End of I2C_ENUM group
194
195
196/* ========================================================================== */
197/* SUB-GROUP : DATA STRUCTS */
198/* ========================================================================== */
229
235 typedef volatile struct
236 {
239
241
271
300
301
302 // End of I2C_Types group
304
305/* ========================================================================== */
306/* SUB-GROUP: FUNCTIONS */
307/* ========================================================================== */
308
315
325
331 void i2c_setSlaveOverride(i2c_instance_t *inst, u32 value);
332
386
388
393
423 void i2c_stopMaster(i2c_instance_t *inst);
438 void i2c_dropMaster(i2c_instance_t *inst);
444 u32 i2c_checkMasterBusy(i2c_instance_t *inst); //End of I2C Master Functions group
446
447
456 void i2c_listenAck(i2c_instance_t *inst);
462 void i2c_sendTxByte(i2c_instance_t *inst,u8 byte);
467 void i2c_sendTxAck(i2c_instance_t *inst);
472 void i2c_sendTxNack(i2c_instance_t *inst);
477 void i2c_waitTxAck(i2c_instance_t *inst);
482 void i2c_waitRxAck(i2c_instance_t *inst);
513 void i2c_sendTxByteRepeat(i2c_instance_t *inst,u8 byte);
519 //End of I2C Transmit/Receive Functions group
521
532 void i2c_enableFilter(i2c_instance_t *inst, u32 filterId, u32 config);
539 void i2c_setFilterConfig(i2c_instance_t *inst, u32 filterId, u32 value);
558 //End of I2C Control Functions group
560
581 void i2c_writeData_b(i2c_instance_t *inst, u8 regAddr, u8 *data, u32 length);
598 void i2c_writeData_w(i2c_instance_t *inst, u16 regAddr, u8 *data, u32 length);
613 void i2c_readData_b(i2c_instance_t *inst, u8 regAddr, u8 *data , u32 length);
626 void i2c_readData_w(i2c_instance_t *inst, u16 regAddr, u8 *data , u32 length);
633 void i2c_setMux(i2c_instance_t *inst, const uint8_t cr);
634 //End of I2C Read/Write Functions group
636 //End of I2C Funcs group
638#ifdef __cplusplus
639}
640#endif // C_plusplus
641 // End of MAIN I2C Group
643
644#endif // I2C_H
i2c_interrupt_t
I2C Enable Interrupt List.
Definition i2c.h:178
@ I2C_INTERRUPT_FILTER
Trigger Interrupt when controller act as slave and its addres filter is triggered.
Definition i2c.h:189
@ I2C_INTERRUPT_END
Trigger Interrupt when STOP condition is sent.
Definition i2c.h:185
@ I2C_INTERRUPT_TX_ACK
Trigger Interrupt when transmit ACK.
Definition i2c.h:182
@ I2C_INTERRUPT_CLOCK_GEN_EXIT
Trigger Interrupt when Clock Generation is stop.
Definition i2c.h:187
@ I2C_INTERRUPT_TX_DATA
Trigger Interrupt when transmit data.
Definition i2c.h:181
@ I2C_INTERRUPT_RESTART
Trigger Interrupt when RESTART condition is sent.
Definition i2c.h:184
@ I2C_INTERRUPT_RX_DATA
Trigger Interrupt when receive data.
Definition i2c.h:179
@ I2C_INTERRUPT_START
Trigger Interrupt when START condition is sent.
Definition i2c.h:183
@ I2C_INTERRUPT_CLOCK_GEN_ENTER
Trigger Interrupt when Clock Generation is start.
Definition i2c.h:188
@ I2C_INTERRUPT_RX_ACK
Trigger Interrupt when receive ACK.
Definition i2c.h:180
@ I2C_INTERRUPT_DROP
Trigger Interrupt when DROP condition is sent.
Definition i2c.h:186
void i2c_clearInterruptFlag(i2c_instance_t *inst, i2c_interrupt_t value)
Clears specific I2C interrupt flags.
Definition i2c.c:219
void i2c_startMasterBlocking(i2c_instance_t *inst)
Initiate start condition for I2C master mode and waits until the operation is complete.
Definition i2c.c:113
void i2c_sendTxAck(i2c_instance_t *inst)
Transmits an ACK signal over I2C.
Definition i2c.c:183
void i2c_recoverMasterBlocking(i2c_instance_t *inst)
Initiate recover condition for I2C master mode and waits until the operation is complete.
Definition i2c.c:140
void i2c_setMux(i2c_instance_t *inst, const uint8_t cr)
Set I2C MUX control register.
Definition i2c.c:314
void i2c_sendNackBlocking(i2c_instance_t *inst)
Sends an NACK signal over the I2C bus and waits until the transmission is complete.
Definition i2c.c:156
void i2c_readData_w(i2c_instance_t *inst, u16 regAddr, u8 *data, u32 length)
Read data with a 16-bit register address over I2C.
Definition i2c.c:285
void i2c_restartMasterBlocking(i2c_instance_t *inst)
Initiate restart condition for I2C master mode and waits until the operation is complete.
Definition i2c.c:119
void i2c_stopMaster(i2c_instance_t *inst)
Initiate stop condition for I2C master mode and sets the dropped status if necessary.
Definition i2c.c:124
void i2c_sendAckBlocking(i2c_instance_t *inst)
Sends an ACK signal over the I2C bus and waits until the transmission is complete.
Definition i2c.c:162
void i2c_writeData_b(i2c_instance_t *inst, u8 regAddr, u8 *data, u32 length)
Write data with an 8-bit register address over I2C and check rx ack for each transaction.
Definition i2c.c:224
void i2c_applyConfig(i2c_instance_t *inst)
Apply the software configuration to the hardware.
Definition i2c.c:83
void i2c_sendTxByte(i2c_instance_t *inst, u8 byte)
Transmits a byte of data over I2C.
Definition i2c.c:178
void i2c_sendTxNack(i2c_instance_t *inst)
Transmits an NACK signal over I2C.
Definition i2c.c:188
u32 i2c_getRxData(i2c_instance_t *inst)
Reads data from I2C receive data register.
Definition i2c.c:58
void i2c_enableFilter(i2c_instance_t *inst, u32 filterId, u32 config)
Enables and configures an I2C hardware filter.
Definition i2c.c:204
u32 i2c_getFilteringHit(i2c_instance_t *inst)
Get Filtering Hit.
Definition i2c.c:38
u32 i2c_getSlaveOverride(i2c_instance_t *inst)
Get Slave Override.
Definition i2c.c:53
void i2c_disableInterrupt(i2c_instance_t *inst, i2c_interrupt_t value)
Disables specific I2C interrupts.
Definition i2c.c:209
void i2c_sendTxNackRepeat(i2c_instance_t *inst)
Sends a NACK signal over I2C bus with repeat mode enabled.
Definition i2c.c:173
u32 i2c_checkMasterBusy(i2c_instance_t *inst)
Checks if the I2C master is busy.
Definition i2c.c:108
u32 i2c_getSlaveStatus(i2c_instance_t *inst)
Get Slave Status.
Definition i2c.c:48
void i2c_startMaster(i2c_instance_t *inst)
Initiate start condition for I2C master mode and sets the dropped status if necessary.
Definition i2c.c:93
u32 i2c_getRxNack(i2c_instance_t *inst)
Checks if the received ACK signal is detected.
Definition i2c.c:63
void i2c_setFilterConfig(i2c_instance_t *inst, u32 filterId, u32 value)
Sets the configuration for an I2C hardware filter.
Definition i2c.c:78
void i2c_waitTxAck(i2c_instance_t *inst)
Waits until the transmission of an ACK signal is complete over the I2C bus.
Definition i2c.c:193
void i2c_setSlaveOverride(i2c_instance_t *inst, u32 value)
Write values to I2C hardware registers.
Definition i2c.c:73
void i2c_waitRxAck(i2c_instance_t *inst)
Waits until the reception of an ACK signal is complete over the I2C bus.
Definition i2c.c:198
u32 i2c_getMasterStatus(i2c_instance_t *inst)
Get Master Status.
Definition i2c.c:33
void i2c_enableInterrupt(i2c_instance_t *inst, i2c_interrupt_t value)
Enables specific I2C interrupts.
Definition i2c.c:214
void i2c_listenAck(i2c_instance_t *inst)
Configures the I2C controller to listen for ACK signals on the receiver (RX) line.
Definition i2c.c:151
u32 i2c_getInterruptFlag(i2c_instance_t *inst)
Get Interrupt Flag.
Definition i2c.c:23
void i2c_readData_b(i2c_instance_t *inst, u8 regAddr, u8 *data, u32 length)
Read data with an 8-bit register address over I2C.
Definition i2c.c:258
void i2c_dropMaster(i2c_instance_t *inst)
Drops the current I2C master operation.
Definition i2c.c:135
void i2c_restartMaster(i2c_instance_t *inst)
Initiate restart condition for I2C master mode and sets the dropped status if necessary.
Definition i2c.c:98
void i2c_writeData_w(i2c_instance_t *inst, u16 regAddr, u8 *data, u32 length)
Write data with a 16-bit register address over I2C and check rx ack for each transaction.
Definition i2c.c:241
void i2c_sendTxByteRepeat(i2c_instance_t *inst, u8 byte)
Sends a byte over I2C bus with repeat mode enabled.
Definition i2c.c:168
u32 i2c_getFilteringStatus(i2c_instance_t *inst)
Get Filtering Status.
Definition i2c.c:43
void i2c_stopMasterBlocking(i2c_instance_t *inst)
Initiate stop condition for I2C master mode and waits until the operation is complete.
Definition i2c.c:129
void i2c_recoverMaster(i2c_instance_t *inst)
Initiate recover condition for I2C master mode and sets the dropped status if necessary.
Definition i2c.c:103
u32 i2c_getRxAck(i2c_instance_t *inst)
Reads Acknowledge signal from I2C receive data register.
Definition i2c.c:68
u32 i2c_getInterruptEnable(i2c_instance_t *inst)
Get Interrupt Enable.
Definition i2c.c:28
I2C hardware filter configuration map.
Definition i2c.h:236
u32 FILTER_CONFIG_1
Offset +0x04: Secondary Filter Config (Addr/Enable).
Definition i2c.h:238
u32 FILTER_CONFIG_0
Offset +0x00: Primary Filter Config (Addr/Enable).
Definition i2c.h:237
I2C hardware register map.
Definition i2c.h:247
u32 RESERVED2
Address Offset: 0x4C.
Definition i2c.h:262
u32 TSU_DATA
Address Offset: 0x30.
Definition i2c.h:257
u32 SLAVE_OVERRIDE
Address Offset: 0x48.
Definition i2c.h:261
u32 tLOW
Address Offset: 0x50.
Definition i2c.h:263
u32 MASTER_STATUS
Address Offset: 0x40.
Definition i2c.h:259
u32 tHIGH
Address Offset: 0x54.
Definition i2c.h:264
i2c_filter_hwreg_t FILTER[3]
Address Offset: 0x8C.
Definition i2c.h:269
u32 INTERRUPT_CLEAR
Address Offset: 0x24.
Definition i2c.h:254
u32 RESERVED0[4]
Reserved Space (0x0C to 0x16).
Definition i2c.h:252
u32 HIT_CONTEXT
Address Offset: 0x80.
Definition i2c.h:267
u32 RESERVED3[9]
Reserved Space (0x5C to 0x7C).
Definition i2c.h:266
u32 RX_ACK
Address Offset: 0x0C.
Definition i2c.h:251
u32 RESERVED1[3]
Reserved Space (0x34 to 0x3C).
Definition i2c.h:258
u32 TX_DATA
Address Offset: 0x00.
Definition i2c.h:248
u32 TX_ACK
Address Offset: 0x04.
Definition i2c.h:249
u32 SLAVE_STATUS
Address Offset: 0x44.
Definition i2c.h:260
u32 INTERRUPT
Address Offset: 0x20.
Definition i2c.h:253
u32 RX_DATA
Address Offset: 0x08.
Definition i2c.h:250
u32 tBUF
Address Offset: 0x58.
Definition i2c.h:265
u32 SAMPLING_CLOCK_DIVIDER
Address Offset: 0x28.
Definition i2c.h:255
u32 FILTER_STATUS
Address Offset: 0x84.
Definition i2c.h:268
u32 TIMEOUT
Address Offset: 0x2C.
Definition i2c.h:256
I2C instance. Holds the software registers and hardware pointer.
Definition i2c.h:290
u32 tBuf
Bus Free Time between STOP and START.
Definition i2c.h:298
u32 timeout
Timeout Value.
Definition i2c.h:294
u32 tLow
SCL Low Time.
Definition i2c.h:296
i2c_hwreg_t * hwreg
Pointer to Hardware Register Map.
Definition i2c.h:291
u32 tsuDat
Data Setup Time.
Definition i2c.h:295
u32 tHigh
SCL High Time.
Definition i2c.h:297
u32 samplingClockDivider
Sampling Clock Divider.
Definition i2c.h:293
u32 slaveAddress
7-bit Slave Address
Definition i2c.h:292
uint8_t u8
Definition type.h:30
uint16_t u16
Definition type.h:28
uint32_t u32
Definition type.h:26