AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/ports/xplained/ASF/xmega/drivers/twi/twis.c
void TWI_SlaveWriteHandler(TWI_Slave_t * twi)
{
    /* If NACK, slave write transaction finished. */
    if ((twi->bytesSent > 0) &&
        (twi->interface->SLAVE.STATUS & TWI_SLAVE_RXACK_bm)) {

        twi->interface->SLAVE.CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc;
        TWI_SlaveTransactionFinished(twi, TWIS_RESULT_OK);
    }
    /* If ACK, master expects more data. */
    else {
        if (twi->bytesSent < TWIS_SEND_BUFFER_SIZE) {
            uint8_t data = twi->sendData[twi->bytesSent];
            twi->interface->SLAVE.DATA = data;
            twi->bytesSent++;

            /* Send data, wait for data interrupt. */
            twi->interface->SLAVE.CTRLB = TWI_SLAVE_CMD_RESPONSE_gc;
        }
        /* If buffer overflow. */
        else {
            twi->interface->SLAVE.CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc;
            TWI_SlaveTransactionFinished(twi, TWIS_RESULT_BUFFER_OVERFLOW);
        }
    }
}
/*! \brief TWI slave write interrupt handler.
 *
 *  Handles TWI slave write transactions and responses.
 *
 *  \param twi The TWI_Slave_t struct instance.
 */
\brief TWI slave write interrupt handler.
Handles TWI slave write transactions and responses.

\param twi The TWI_Slave_t struct instance.
\ brief TWI slave write interrupt handler . Handles TWI slave write transactions and responses . \ param twi The TWI_Slave_t struct instance .
void TWI_SlaveWriteHandler(TWI_Slave_t * twi)
{
    if ((twi->bytesSent > 0) &&
        (twi->interface->SLAVE.STATUS & TWI_SLAVE_RXACK_bm)) {
        twi->interface->SLAVE.CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc;
        TWI_SlaveTransactionFinished(twi, TWIS_RESULT_OK);
    }
    else {
        if (twi->bytesSent < TWIS_SEND_BUFFER_SIZE) {
            uint8_t data = twi->sendData[twi->bytesSent];
            twi->interface->SLAVE.DATA = data;
            twi->bytesSent++;
            twi->interface->SLAVE.CTRLB = TWI_SLAVE_CMD_RESPONSE_gc;
        }
        else {
            twi->interface->SLAVE.CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc;
            TWI_SlaveTransactionFinished(twi, TWIS_RESULT_BUFFER_OVERFLOW);
        }
    }
}
void TWI_SlaveWriteHandler ( TWI_Slave_t * twi ) { if ( ( twi -> bytesSent > 0 ) && ( twi -> interface -> SLAVE . STATUS & TWI_SLAVE_RXACK_bm ) ) { twi -> interface -> SLAVE . CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc ; TWI_SlaveTransactionFinished ( twi , TWIS_RESULT_OK ) ; } else { if ( twi -> bytesSent < TWIS_SEND_BUFFER_SIZE ) { uint8_t data = twi -> sendData [ twi -> bytesSent ] ; twi -> interface -> SLAVE . DATA = data ; twi -> bytesSent ++ ; twi -> interface -> SLAVE . CTRLB = TWI_SLAVE_CMD_RESPONSE_gc ; } else { twi -> interface -> SLAVE . CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc ; TWI_SlaveTransactionFinished ( twi , TWIS_RESULT_BUFFER_OVERFLOW ) ; } } }
\brief TWI slave write interrupt handler.
\ brief TWI slave write interrupt handler .
/* If NACK, slave write transaction finished. */ /* If ACK, master expects more data. */ /* Send data, wait for data interrupt. */ /* If buffer overflow. */