AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/ports/xplained/ASF/xmega/drivers/twi/twim.c
static inline void twim_read_handler(void)
{
    TWI_t *const bus = transfer.bus;
    twi_package_t *const pkg = transfer.pkg;

    if (transfer.data_count < pkg->length) {

        uint8_t *const data = pkg->buffer;
        data[transfer.data_count++] = bus->MASTER.DATA;

        /* If there is more to read, issue ACK and start a byte read.
         * Otherwise, issue NACK and STOP to complete the transaction.
         */
        if (transfer.data_count < pkg->length) {

            bus->MASTER.CTRLC = TWI_MASTER_CMD_RECVTRANS_gc;

        } else {

            bus->MASTER.CTRLC = TWI_MASTER_ACKACT_bm | TWI_MASTER_CMD_STOP_gc;
            transfer.status = STATUS_OK;
        }

    } else {

        /* Issue STOP and buffer overflow condition. */

        bus->MASTER.CTRLC = TWI_MASTER_CMD_STOP_gc;
        transfer.status = ERR_NO_MEMORY;
    }
}
/**
 * \internal
 *
 * \brief TWI master read interrupt handler.
 *
 *  This is the master read interrupt handler that takes care of
 *  reading bytes from the TWI slave.
 */
\internal
\brief TWI master read interrupt handler.

This is the master read interrupt handler that takes care of
reading bytes from the TWI slave.
\ internal \ brief TWI master read interrupt handler . This is the master read interrupt handler that takes care of reading bytes from the TWI slave .
static inline void twim_read_handler(void)
{
    TWI_t *const bus = transfer.bus;
    twi_package_t *const pkg = transfer.pkg;
    if (transfer.data_count < pkg->length) {
        uint8_t *const data = pkg->buffer;
        data[transfer.data_count++] = bus->MASTER.DATA;
        if (transfer.data_count < pkg->length) {
            bus->MASTER.CTRLC = TWI_MASTER_CMD_RECVTRANS_gc;
        } else {
            bus->MASTER.CTRLC = TWI_MASTER_ACKACT_bm | TWI_MASTER_CMD_STOP_gc;
            transfer.status = STATUS_OK;
        }
    } else {
        bus->MASTER.CTRLC = TWI_MASTER_CMD_STOP_gc;
        transfer.status = ERR_NO_MEMORY;
    }
}
static inline void twim_read_handler ( void ) { TWI_t * const bus = transfer . bus ; twi_package_t * const pkg = transfer . pkg ; if ( transfer . data_count < pkg -> length ) { uint8_t * const data = pkg -> buffer ; data [ transfer . data_count ++ ] = bus -> MASTER . DATA ; if ( transfer . data_count < pkg -> length ) { bus -> MASTER . CTRLC = TWI_MASTER_CMD_RECVTRANS_gc ; } else { bus -> MASTER . CTRLC = TWI_MASTER_ACKACT_bm | TWI_MASTER_CMD_STOP_gc ; transfer . status = STATUS_OK ; } } else { bus -> MASTER . CTRLC = TWI_MASTER_CMD_STOP_gc ; transfer . status = ERR_NO_MEMORY ; } }
\internal
 \brief TWI master read interrupt handler.
\ internal \ brief TWI master read interrupt handler .
/* If there is more to read, issue ACK and start a byte read.
         * Otherwise, issue NACK and STOP to complete the transaction.
         */ /* Issue STOP and buffer overflow condition. */