libmaple/i2c.c
static inline int32 wait_for_state_change(i2c_dev *dev,
                                          i2c_state state,
                                          uint32 timeout) {
    i2c_state tmp;

    while (1) {
        tmp = dev->state;

        if (tmp == I2C_STATE_ERROR) {
            return I2C_STATE_ERROR;
        }

        if (tmp == state) {
            return 0;
        }

        if (timeout) {
            if (systick_uptime() > (dev->timestamp + timeout)) {
                /* TODO: overflow? */
                /* TODO: racy? */
                return I2C_ERROR_TIMEOUT;
            }
        }
    }
}
/**
 * @brief Wait for an I2C event, or time out in case of error.
 * @param dev I2C device
 * @param state I2C_state state to wait for
 * @param timeout Timeout, in milliseconds
 * @return 0 if target state is reached, a negative value on error.
 */
@brief Wait for an I2C event, or time out in case of error.
@param dev I2C device
@param state I2C_state state to wait for
@param timeout Timeout, in milliseconds
@return 0 if target state is reached, a negative value on error.
@brief Wait for an I2C event or time out in case of error . @param dev I2C device @param state I2C_state state to wait for @param timeout Timeout in milliseconds @return 0 if target state is reached a negative value on error .
static inline int32 wait_for_state_change(i2c_dev *dev,
                                          i2c_state state,
                                          uint32 timeout) {
    i2c_state tmp;
    while (1) {
        tmp = dev->state;
        if (tmp == I2C_STATE_ERROR) {
            return I2C_STATE_ERROR;
        }
        if (tmp == state) {
            return 0;
        }
        if (timeout) {
            if (systick_uptime() > (dev->timestamp + timeout)) {
                return I2C_ERROR_TIMEOUT;
            }
        }
    }
}
static inline int32 wait_for_state_change ( i2c_dev * dev , i2c_state state , uint32 timeout ) { i2c_state tmp ; while ( 1 ) { tmp = dev -> state ; if ( tmp == I2C_STATE_ERROR ) { return I2C_STATE_ERROR ; } if ( tmp == state ) { return 0 ; } if ( timeout ) { if ( systick_uptime ( ) > ( dev -> timestamp + timeout ) ) { return I2C_ERROR_TIMEOUT ; } } } }
@brief Wait for an I2C event, or time out in case of error.
@brief Wait for an I2C event or time out in case of error .
/* TODO: overflow? */ /* TODO: racy? */