MSS_I2C_register_write_handler

Function MSS_I2C_register_write_handler 

Source
pub unsafe extern "C" fn MSS_I2C_register_write_handler(
    this_i2c: *mut mss_i2c_instance_t,
    handler: mss_i2c_slave_wr_handler_t,
)
Expand description

§I2C write handler registration.

§Register the function that is called to process the data written to this MSS I2C instance when it is the slave in an I2C write transaction. Note: If a write handler is registered, it is called on completion of the write phase of a write-read transaction and responsible for processing the received data in the slave receive buffer and populating the slave transmit buffer with the data that will be transmitted to the I2C master as part of the read phase of the write-read transaction. If a write handler is not registered, the write data of a write read transaction is interpreted as an offset into the slave�s transmit buffer and handled by the driver.

@param this_i2c: The this_i2c parameter is a pointer to an mss_i2c_instance_t structure identifying the MSS I2C hardware block to be initialized. There are four such data structures, g_mss_i2c0_lo and g_mss_i2c1_lo, associated with MSS I2C 0 and MSS I2C 1 when they are connected on the AXI switch slave 5 (main APB bus) and g_mss_i2c0_hi and g_mss_i2c1_hi, associated with MSS I2C 0 to MSS I2C 1 when they are connected on the AXI switch slave 6 (AMP APB bus). This parameter must point to one of these four global data structure defined within I2C driver.

@param handler: Pointer to the function that will process the I2C write request.

@return none.

Example: @code #define SLAVE_SER_ADDR 0x10u #define SLAVE_TX_BUFFER_SIZE 10u

uint8_t g_slave_tx_buffer[SLAVE_TX_BUFFER_SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

local function prototype void slave_write_handler ( mss_i2c_instance_t * this_i2c, uint8_t * p_rx_data, uint16_t rx_size );

void main( void ) { // Initialize the MSS I2C driver with its I2C serial address and serial // clock divider. MSS_I2C_init( &g_mss_i2c0_lo, SLAVE_SER_ADDR, MSS_I2C_PCLK_DIV_256 ); MSS_I2C_set_slave_tx_buffer( &g_mss_i2c0_lo, g_slave_tx_buffer, sizeof(g_slave_tx_buffer) ); MSS_I2C_set_slave_mem_offset_length( &g_mss_i2c0_lo, 1 ); MSS_I2C_register_write_handler( &g_mss_i2c0_lo, slave_write_handler ); } @endcode