/* This function handles I2C Communication timeout for Master addressing phase.  */
static ald_status_t i2c_wait_master_addr_to_timeout(ald_i2c_handle_t *hperh, uint32_t flag, uint32_t timeout)
/* This function handles I2C Communication timeout for Master addressing phase.  */
static ald_status_t i2c_wait_master_addr_to_timeout(ald_i2c_handle_t *hperh, uint32_t flag, uint32_t timeout)
{
    uint32_t tickstart = ald_get_tick();
    while (ALD_I2C_GET_IT_FLAG(hperh, flag) == RESET)
    {
        if ((timeout == 0) || ((ald_get_tick() - tickstart ) > timeout))
        {
            hperh->error_code = ALD_I2C_ERROR_TIMEOUT;
            return ALD_ERROR;
        }
    }
    return ALD_OK;
}