AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/ports/xplained/ASF/xmega/drivers/twi/twis.c
void TWI_SlaveReadHandler(TWI_Slave_t * twi)
{
    /* Enable stop interrupt. */
    uint8_t currentCtrlA = twi->interface->SLAVE.CTRLA;
    twi->interface->SLAVE.CTRLA = currentCtrlA | TWI_SLAVE_PIEN_bm;

    /* If free space in buffer. */
    if (twi->bytesReceived < TWIS_RECEIVE_BUFFER_SIZE) {
        /* Fetch data */
        uint8_t data = twi->interface->SLAVE.DATA;
        twi->receivedData[twi->bytesReceived] = data;

        /* Process data. */
        twi->Process_Data();

        twi->bytesReceived++;

        /* If application signalling need to abort (error occured),
         * complete transaction and wait for next START. Otherwise
         * send ACK and wait for data interrupt.
         */
        if (twi->abort) {
            twi->interface->SLAVE.CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc;
            TWI_SlaveTransactionFinished(twi, TWIS_RESULT_ABORTED);
            twi->abort = false;
        } else {
            twi->interface->SLAVE.CTRLB = TWI_SLAVE_CMD_RESPONSE_gc;
        }
    }
    /* If buffer overflow, send NACK and wait for next START. Set
     * result buffer overflow.
     */
    else {
        twi->interface->SLAVE.CTRLB =
            TWI_SLAVE_ACKACT_bm | TWI_SLAVE_CMD_COMPTRANS_gc;
        TWI_SlaveTransactionFinished(twi, TWIS_RESULT_BUFFER_OVERFLOW);
    }
}
/*! \brief TWI slave read interrupt handler.
 *
 *  Handles TWI slave read transactions and responses.
 *
 *  \param twi The TWI_Slave_t struct instance.
 */
\brief TWI slave read interrupt handler.
Handles TWI slave read transactions and responses.

\param twi The TWI_Slave_t struct instance.
\ brief TWI slave read interrupt handler . Handles TWI slave read transactions and responses . \ param twi The TWI_Slave_t struct instance .
void TWI_SlaveReadHandler(TWI_Slave_t * twi)
{
    uint8_t currentCtrlA = twi->interface->SLAVE.CTRLA;
    twi->interface->SLAVE.CTRLA = currentCtrlA | TWI_SLAVE_PIEN_bm;
    if (twi->bytesReceived < TWIS_RECEIVE_BUFFER_SIZE) {
        uint8_t data = twi->interface->SLAVE.DATA;
        twi->receivedData[twi->bytesReceived] = data;
        twi->Process_Data();
        twi->bytesReceived++;
        if (twi->abort) {
            twi->interface->SLAVE.CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc;
            TWI_SlaveTransactionFinished(twi, TWIS_RESULT_ABORTED);
            twi->abort = false;
        } else {
            twi->interface->SLAVE.CTRLB = TWI_SLAVE_CMD_RESPONSE_gc;
        }
    }
    else {
        twi->interface->SLAVE.CTRLB =
            TWI_SLAVE_ACKACT_bm | TWI_SLAVE_CMD_COMPTRANS_gc;
        TWI_SlaveTransactionFinished(twi, TWIS_RESULT_BUFFER_OVERFLOW);
    }
}
void TWI_SlaveReadHandler ( TWI_Slave_t * twi ) { uint8_t currentCtrlA = twi -> interface -> SLAVE . CTRLA ; twi -> interface -> SLAVE . CTRLA = currentCtrlA | TWI_SLAVE_PIEN_bm ; if ( twi -> bytesReceived < TWIS_RECEIVE_BUFFER_SIZE ) { uint8_t data = twi -> interface -> SLAVE . DATA ; twi -> receivedData [ twi -> bytesReceived ] = data ; twi -> Process_Data ( ) ; twi -> bytesReceived ++ ; if ( twi -> abort ) { twi -> interface -> SLAVE . CTRLB = TWI_SLAVE_CMD_COMPTRANS_gc ; TWI_SlaveTransactionFinished ( twi , TWIS_RESULT_ABORTED ) ; twi -> abort = false ; } else { twi -> interface -> SLAVE . CTRLB = TWI_SLAVE_CMD_RESPONSE_gc ; } } else { twi -> interface -> SLAVE . CTRLB = TWI_SLAVE_ACKACT_bm | TWI_SLAVE_CMD_COMPTRANS_gc ; TWI_SlaveTransactionFinished ( twi , TWIS_RESULT_BUFFER_OVERFLOW ) ; } }
\brief TWI slave read interrupt handler.
\ brief TWI slave read interrupt handler .
/* Enable stop interrupt. */ /* If free space in buffer. */ /* Fetch data */ /* Process data. */ /* If application signalling need to abort (error occured),
         * complete transaction and wait for next START. Otherwise
         * send ACK and wait for data interrupt.
         */ /* If buffer overflow, send NACK and wait for next START. Set
     * result buffer overflow.
     */