software/src/ASF/sam0/drivers/sercom/i2c/i2c_sam0/i2c_master.c
/**
 * \internal
 * Address response. Called when address is answered or timed out.
 *
 * \param[in,out] module  Pointer to software module structure
 *
 * \return Status of address response.
 * \retval STATUS_OK                    No error has occurred
 * \retval STATUS_ERR_DENIED            If error on bus
 * \retval STATUS_ERR_PACKET_COLLISION  If arbitration is lost
 * \retval STATUS_ERR_BAD_ADDRESS       If slave is busy, or no slave
 *                                      acknowledged the address
 */
\internal
Address response. Called when address is answered or timed out.

\param[in,out] module  Pointer to software module structure

\return Status of address response.
\retval STATUS_OK                    No error has occurred
\retval STATUS_ERR_DENIED            If error on bus
\retval STATUS_ERR_PACKET_COLLISION  If arbitration is lost
\retval STATUS_ERR_BAD_ADDRESS       If slave is busy, or no slave
acknowledged the address
\ internal Address response . Called when address is answered or timed out . \ param [ in out ] module Pointer to software module structure \ return Status of address response . \ retval STATUS_OK No error has occurred \ retval STATUS_ERR_DENIED If error on bus \ retval STATUS_ERR_PACKET_COLLISION If arbitration is lost \ retval STATUS_ERR_BAD_ADDRESS If slave is busy or no slave acknowledged the address
enum status_code _i2c_master_address_response(
		struct i2c_master_module *const module)
{
	Assert(module);
	Assert(module->hw);
	SercomI2cm *const i2c_module = &(module->hw->I2CM);
	if (i2c_module->INTFLAG.reg & SERCOM_I2CM_INTFLAG_SB) {
		i2c_module->INTFLAG.reg = SERCOM_I2CM_INTFLAG_SB;
		if (i2c_module->STATUS.reg & SERCOM_I2CM_STATUS_ARBLOST) {
			return STATUS_ERR_PACKET_COLLISION;
		}
	} else if (i2c_module->STATUS.reg & SERCOM_I2CM_STATUS_RXNACK) {
		i2c_module->CTRLB.reg |= SERCOM_I2CM_CTRLB_CMD(3);
		return STATUS_ERR_BAD_ADDRESS;
	}
	return STATUS_OK;
}
enum status_code _i2c_master_address_response ( struct i2c_master_module * const module ) { Assert ( module ) ; Assert ( module -> hw ) ; SercomI2cm * const i2c_module = & ( module -> hw -> I2CM ) ; if ( i2c_module -> INTFLAG . reg & SERCOM_I2CM_INTFLAG_SB ) { i2c_module -> INTFLAG . reg = SERCOM_I2CM_INTFLAG_SB ; if ( i2c_module -> STATUS . reg & SERCOM_I2CM_STATUS_ARBLOST ) { return STATUS_ERR_PACKET_COLLISION ; } } else if ( i2c_module -> STATUS . reg & SERCOM_I2CM_STATUS_RXNACK ) { i2c_module -> CTRLB . reg |= SERCOM_I2CM_CTRLB_CMD ( 3 ) ; return STATUS_ERR_BAD_ADDRESS ; } return STATUS_OK ; }
\internal
 Address response.
\ internal Address response .
/* Sanity check arguments */ /* Check for error and ignore bus-error; workaround for BUSSTATE stuck in
	 * BUSY */ /* Clear write interrupt flag */ /* Check arbitration. */ /* Return packet collision. */ /* Check that slave responded with ack. */ /* Slave busy. Issue ack and stop command. */ /* Return bad address value. */