Target transactions

Informative

How a target-mode channel responds to a controller on the bus. Binding rules: CHI-I2C-MUST-02, CHI-I2C-MUST-08, CHI-I2C-MUST-15, CHI-I2C-MUST-16 in I2c — Requirements.

Respond when addressed

When a controller addresses this target, the driver calls the I2c_Callout_OnAddress callout with the transfer direction; you stage the response by starting a transaction with I2C_ADDR_UNSPECIFIED (the address is already fixed by configuration). Fill in its user code block in I2c_Callout_Stubs.c (see The Callout Stub File):

/* in I2c_Callout_Stubs.c */
void I2c_Callout_OnAddress(uint8 channelId, I2c_DirectionType direction)
{
    if (direction == I2C_DIR_CONTROLLER_READ) {
        /* controller wants to read from us — provide the bytes to transmit */
        I2c_StartTxTransaction(channelId, I2C_ADDR_UNSPECIFIED, myResponse, sizeof(myResponse));
    } else { /* I2C_DIR_CONTROLLER_WRITE */
        /* controller will write to us — provide a buffer to receive into */
        I2c_StartRxTransaction(channelId, I2C_ADDR_UNSPECIFIED, myBuffer, sizeof(myBuffer));
    }
}

The staging call must match the reported direction; a mismatch raises I2C_DEVERR_INVALID_DIRECTION (see Errors).

Completion

/* in I2c_Callout_Stubs.c */
void I2c_Callout_OnReception(uint8 channelId, uint16 length)    { /* controller wrote `length` bytes */ }
void I2c_Callout_OnTransmission(uint8 channelId, uint16 length) { /* controller read `length` bytes  */ }

If you do not stage a response in I2c_Callout_OnAddress, the driver transmits the channel’s configured default_data (on a controller read) or accepts and discards the bytes (on a controller write).

Note

Data consistency. Buffers you hand to I2c_StartTxTransaction / I2c_StartRxTransaction must stay valid until the completion callout fires (CHI-I2C-MUST-13).