XCORE SDK
XCORE Software Development Kit
Classes | Macros | Typedefs | Functions
rtos_i2c_slave_driver

Classes

struct  rtos_i2c_slave_struct
 

Macros

#define RTOS_I2C_SLAVE_BUF_LEN   256
 
#define RTOS_I2C_SLAVE_CALLBACK_ATTR   __attribute__((fptrgroup("rtos_i2c_slave_cb_fptr_grp")))
 

Typedefs

typedef struct rtos_i2c_slave_struct rtos_i2c_slave_t
 
typedef void(* rtos_i2c_slave_start_cb_t) (rtos_i2c_slave_t *ctx, void *app_data)
 
typedef void(* rtos_i2c_slave_rx_cb_t) (rtos_i2c_slave_t *ctx, void *app_data, uint8_t *data, size_t len)
 
typedef size_t(* rtos_i2c_slave_tx_start_cb_t) (rtos_i2c_slave_t *ctx, void *app_data, uint8_t **data)
 
typedef void(* rtos_i2c_slave_tx_done_cb_t) (rtos_i2c_slave_t *ctx, void *app_data, uint8_t *data, size_t len)
 

Functions

void rtos_i2c_slave_start (rtos_i2c_slave_t *i2c_slave_ctx, void *app_data, rtos_i2c_slave_start_cb_t start, rtos_i2c_slave_rx_cb_t rx, rtos_i2c_slave_tx_start_cb_t tx_start, rtos_i2c_slave_tx_done_cb_t tx_done, unsigned interrupt_core_id, unsigned priority)
 
void rtos_i2c_slave_init (rtos_i2c_slave_t *i2c_slave_ctx, uint32_t io_core_mask, const port_t p_scl, const port_t p_sda, uint8_t device_addr)
 

Detailed Description

The public API for using the RTOS I2C slave driver.

Macro Definition Documentation

◆ RTOS_I2C_SLAVE_BUF_LEN

#define RTOS_I2C_SLAVE_BUF_LEN   256

The maximum number of bytes that a the RTOS I2C slave driver can receive from a master in a single write transaction.

◆ RTOS_I2C_SLAVE_CALLBACK_ATTR

#define RTOS_I2C_SLAVE_CALLBACK_ATTR   __attribute__((fptrgroup("rtos_i2c_slave_cb_fptr_grp")))

This attribute must be specified on all RTOS I2C slave callback functions provided by the application.

Typedef Documentation

◆ rtos_i2c_slave_rx_cb_t

typedef void(* rtos_i2c_slave_rx_cb_t) (rtos_i2c_slave_t *ctx, void *app_data, uint8_t *data, size_t len)

Function pointer type for application provided RTOS I2C slave receive callback functions.

These callback functions are called when an I2C slave driver instance has received data from a master device.

Parameters
ctxA pointer to the associated I2C slave driver instance.
app_dataA pointer to application specific data provided by the application. Used to share data between this callback function and the application.
dataA pointer to the data received from the master.
lenThe number of valid bytes in data.

◆ rtos_i2c_slave_start_cb_t

typedef void(* rtos_i2c_slave_start_cb_t) (rtos_i2c_slave_t *ctx, void *app_data)

Function pointer type for application provided RTOS I2C slave start callback functions.

These callback functions are optionally called by an I2C slave driver's thread when it is first started. This gives the application a chance to perform startup initialization from within the driver's thread.

Parameters
ctxA pointer to the associated I2C slave driver instance.
app_dataA pointer to application specific data provided by the application. Used to share data between this callback function and the application.

◆ rtos_i2c_slave_t

Typedef to the RTOS I2C slave driver instance struct.

◆ rtos_i2c_slave_tx_done_cb_t

typedef void(* rtos_i2c_slave_tx_done_cb_t) (rtos_i2c_slave_t *ctx, void *app_data, uint8_t *data, size_t len)

Function pointer type for application provided RTOS I2C slave transmit done callback functions.

These callback functions are optionally called when an I2C slave driver instance is done transmitting data to a master device. A buffer to the data sent and the actual number of bytes sent are provided to the callback.

The application may want to use this, for example, if the buffer that was sent was malloc'd. This callback can be used to free the buffer.

Parameters
ctxA pointer to the associated I2C slave driver instance.
app_dataA pointer to application specific data provided by the application. Used to share data between this callback function and the application.
dataA pointer to the data transmitted to the master.
lenThe number of bytes transmitted to the master from data.

◆ rtos_i2c_slave_tx_start_cb_t

typedef size_t(* rtos_i2c_slave_tx_start_cb_t) (rtos_i2c_slave_t *ctx, void *app_data, uint8_t **data)

Function pointer type for application provided RTOS I2C slave transmit start callback functions.

These callback functions are called when an I2C slave driver instance needs to transmit data to a master device. This callback must provide the data to transmit and the length.

Parameters
ctxA pointer to the associated I2C slave driver instance.
app_dataA pointer to application specific data provided by the application. Used to share data between this callback function and the application.
dataA pointer to the data buffer to transmit to the master. The driver sets this to its internal data buffer, which has a size of RTOS_I2C_SLAVE_BUF_LEN, prior to calling this callback. This may be set to a different buffer by the callback. The callback must fill this buffer with the data to send to the master.
Returns
The number of bytes to transmit to the master from data. If the master reads more bytes than this, the driver will wrap around to the start of the buffer and send it again.

Function Documentation

◆ rtos_i2c_slave_init()

void rtos_i2c_slave_init ( rtos_i2c_slave_t i2c_slave_ctx,
uint32_t  io_core_mask,
const port_t  p_scl,
const port_t  p_sda,
uint8_t  device_addr 
)

Initializes an RTOS I2C slave driver instance. This must only be called by the tile that owns the driver instance. It should be called before starting the RTOS, and must be called before calling rtos_i2c_slave_start().

Parameters
i2c_slave_ctxA pointer to the I2C slave driver instance to initialize.
io_core_maskA bitmask representing the cores on which the low level I2C I/O thread created by the driver is allowed to run. Bit 0 is core 0, bit 1 is core 1, etc.
p_sclThe port containing SCL. This must be a 1-bit port and different than p_sda.
p_sdaThe port containing SDA. This must be a 1-bit port and different than p_scl.
device_addrThe 7-bit address of the slave device.

◆ rtos_i2c_slave_start()

void rtos_i2c_slave_start ( rtos_i2c_slave_t i2c_slave_ctx,
void *  app_data,
rtos_i2c_slave_start_cb_t  start,
rtos_i2c_slave_rx_cb_t  rx,
rtos_i2c_slave_tx_start_cb_t  tx_start,
rtos_i2c_slave_tx_done_cb_t  tx_done,
unsigned  interrupt_core_id,
unsigned  priority 
)

Starts an RTOS I2C slave driver instance. This must only be called by the tile that owns the driver instance. It must be called after starting the RTOS from an RTOS thread.

rtos_i2c_slave_init() must be called on this I2C slave driver instance prior to calling this.

Parameters
i2c_slave_ctxA pointer to the I2C slave driver instance to start.
app_dataA pointer to application specific data to pass to the callback functions.
startThe callback function that is called when the driver's thread starts. This is optional and may be NULL.
rxThe callback function to receive data from the bus master.
tx_startThe callback function to transmit data to the bus master.
tx_doneThe callback function that is notified when transmits are complete. This is optional and may be NULL.
interrupt_core_idThe ID of the core on which to enable the I2C interrupt.
priorityThe priority of the task that gets created by the driver to call the callback functions.