IICMB IRQ driver
Interrupt driven dataflow for IICMB.
To interact with HDL IICMB can following API used.
Initializes the IICMB driver.
- *self : common storage handle
- iicmbAdr: base address pointer to IICMB
- bus: selected I2C channel
int iicmb_init(t_iicmb *self, void* iicmbAdr, uint8_t bus);
Waits until IICMB reaches busy state. This would allow to run this driver in a poll loop.
- *self : common storage handle
int iicmb_busy_wait(t_iicmb *self);
IICMB fsm. This function needs to be called by the processors Interrupt handler.
- *self : common storage handle
void iicmb_fsm(t_iicmb *self);
Checks if the IICMB is ready for new requests.
- *self : common storage handle
int iicmb_busy(t_iicmb *self);
Checks if the last transfer ended with an error.
- *self : common storage handle
int iicmb_is_error(t_iicmb *self);
Writes data packet to I2C slave.
- *self : common storage handle
- adr7: 7bit slave address
- *data: pointer to write data
- len: number of bytes in *data
int iicmb_write(t_iicmb *self, uint8_t adr7, void* data, uint16_t len);
Reads data packet from I2C slave.
- *self : common storage handle
- adr7: 7bit slave address
- *data: pointer to read data
- len: number of bytes in *data
int iicmb_read(t_iicmb *self, uint8_t adr7, void* data, uint16_t len);
Writes to I2C slave, sends a repeated start condition and starts with read. Read and write data takes place in the same buffer. That means the read data will overwrite the write data.
- *self : common storage handle
- adr7: 7bit slave address
- *data: pointer to read data
- wrLen: number of write bytes in *data
- rdLen: number of read bytes to capture in *data
int iicmb_wr_rd(t_iicmb *self, uint8_t adr7, void* data, uint16_t wrLen, uint16_t rdLen);
The code snippet below shows the integration of the driver into a user application.
#include <stdlib.h> // EXIT codes, malloc
#include <stdio.h> // f.e. printf
#include <stdint.h> // defines fixed data types: int8_t...
#include "iicmb.h" // IICMB driver
t_iicmb g_iicmb; // handle for IICMB driver
/**
* isr
* ISR IICMB Macro
*/
void processors_isr(void)
{
iicmb_fsm(&g_iicmb);
}
/**
* main
*/
int main ()
{
/* variables */
uint8_t i2c[10]; // I2C packet to interact
/* init IICMB
* base address 'NULL', change to physical address of IICMB
* traffic on I2C channel 0
*/
iicmb_init(&g_iicmb, (void*) NULL, 0);
/* issue transfer
* access I2C slave with address 0x12
* write 5 bytes to slave
* read 8 bytes from slave
*/
iicmb_wr_rd(&g_iicmb, 0x12, &i2c, 5, 8);
/* wait for transfer */
while ( iicmb_busy(&g_iicmb) ) {
__asm("nop");
}
/* normal end */
exit(0);
}
For exemplary compile:
gcc -c -O iicmb.c -o iicmb.o
gcc -c -O main.c -o main.o
gcc iicmb.o main.o -lm -o main
Githubs CI/CD executes the Makefile and performs some simple tests.