XCORE SDK
XCORE Software Development Kit
Classes | Macros | Typedefs | Enumerations | Functions
hil_i2c_slave

Classes

struct  i2c_callback_group_t
 

Macros

#define I2C_CALLBACK_ATTR   __attribute__((fptrgroup("i2c_callback")))
 

Typedefs

typedef enum i2c_slave_ack i2c_slave_ack_t
 
typedef i2c_slave_ack_t(* ack_read_request_t) (void *app_data)
 
typedef i2c_slave_ack_t(* ack_write_request_t) (void *app_data)
 
typedef uint8_t(* master_requires_data_t) (void *app_data)
 
typedef i2c_slave_ack_t(* master_sent_data_t) (void *app_data, uint8_t data)
 
typedef void(* stop_bit_t) (void *app_data)
 
typedef int(* shutdown_t) (void *app_data)
 

Enumerations

enum  i2c_slave_ack { I2C_SLAVE_ACK , I2C_SLAVE_NACK }
 

Functions

void i2c_slave (const i2c_callback_group_t *const i2c_cbg, port_t p_scl, port_t p_sda, uint8_t device_addr)
 

Detailed Description

The public API for using the HIL I2C slave.

Macro Definition Documentation

◆ I2C_CALLBACK_ATTR

#define I2C_CALLBACK_ATTR   __attribute__((fptrgroup("i2c_callback")))

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

Typedef Documentation

◆ ack_read_request_t

typedef i2c_slave_ack_t(* ack_read_request_t) (void *app_data)

The bus master has requested a read.

This callback function is called if the bus master requests a read from this slave device.

At this point the slave can choose to accept the request (and drive an ACK signal back to the master) or not (and drive a NACK signal).

Parameters
app_dataA pointer to application specific data provided by the application. Used to share data between the callback functions and the application.
Returns
The callback must return either I2C_SLAVE_ACK or I2C_SLAVE_NACK.

◆ ack_write_request_t

typedef i2c_slave_ack_t(* ack_write_request_t) (void *app_data)

The bus master has requested a write.

This callback function is called if the bus master requests a write from this slave device.

At this point the slave can choose to accept the request (and drive an ACK signal back to the master) or not (and drive a NACK signal).

Parameters
app_dataA pointer to application specific data provided by the application. Used to share data between the callback functions and the application.
Returns
The callback must return either I2C_SLAVE_ACK or I2C_SLAVE_NACK.

◆ i2c_slave_ack_t

I2C Slave Response

This type is used to describe the I2C slave response.

◆ master_requires_data_t

typedef uint8_t(* master_requires_data_t) (void *app_data)

The bus master requires data.

This callback function is called when the bus master requires data from this slave device.

Parameters
app_dataA pointer to application specific data provided by the application. Used to share data between the callback functions and the application.
Returns
a byte of data to send to the master.

◆ master_sent_data_t

typedef i2c_slave_ack_t(* master_sent_data_t) (void *app_data, uint8_t data)

The bus master has sent some data.

This callback function is called when the bus master has transferred a byte of data this slave device.

Parameters
app_dataA pointer to application specific data provided by the application. Used to share data between the callback functions and the application.
dataThe byte of data received from the bus master.
Returns
The callback must return either I2C_SLAVE_ACK or I2C_SLAVE_NACK.

◆ shutdown_t

typedef int(* shutdown_t) (void *app_data)

Shuts down the I2C slave device.

This function can be used to stop the I2C slave task. It will disable the SCL and SDA ports and then return.

Parameters
app_dataA pointer to application specific data provided by the application. Used to share data between the callback functions and the application.
Returns
- Non-zero if the I2C slave task should shut down.
  • Zero if the I2C slave task should continue running.

◆ stop_bit_t

typedef void(* stop_bit_t) (void *app_data)

The bus master has sent a stop bit.

This callback function is called when a stop bit is sent by the bus master.

Parameters
app_dataA pointer to application specific data provided by the application. Used to share data between the callback functions and the application.

Enumeration Type Documentation

◆ i2c_slave_ack

I2C Slave Response

This type is used to describe the I2C slave response.

Enumerator
I2C_SLAVE_ACK 

ACK to accept request

I2C_SLAVE_NACK 

NACK to ignore request

Function Documentation

◆ i2c_slave()

void i2c_slave ( const i2c_callback_group_t *const  i2c_cbg,
port_t  p_scl,
port_t  p_sda,
uint8_t  device_addr 
)

I2C slave task.

This function instantiates an I2C slave device.

Parameters
i2c_cbgThe I2C callback group pointing to the application's functions to use for initialization and getting and receiving frames. Also points to application specific data which will be shared between the callbacks.
p_sclThe SCL port of the I2C bus. This should be a 1 bit port. If not, The SCL pin must be at bit 0 and the other bits unused.
p_sdaThe SDA port of the I2C bus. This should be a 1 bit port. If not, The SDA pin must be at bit 0 and the other bits unused.
device_addrThe address of the slave device.