// this function waits the end of a tx transfer and return the status of the transaction: // 0: OK ack received // 1: OK ack not received // 2: failure static int i2c_wait_end_tx_transfer(i2c_t *obj) { // wait for the interrupt flag if (timeout_status_poll(obj, I2C_S_IICIF_MASK)) { return 2; } i2c_hal_clear_interrupt(obj->instance); // wait transfer complete if (timeout_status_poll(obj, I2C_S_TCF_MASK)) { return 2; } // check if we received the ACK or not return i2c_hal_get_receive_ack(obj->instance) ? 0 : 1; }
// this function waits the end of a tx transfer and return the status of the transaction: // 0: OK ack received // 1: OK ack not received // 2: failure static int i2c_wait_end_tx_transfer(i2c_t *obj) { // wait for the interrupt flag if (timeout_status_poll(obj, I2C_S_IICIF_MASK)) { return 2; } obj->i2c->S |= I2C_S_IICIF_MASK; // wait transfer complete if (timeout_status_poll(obj, I2C_S_TCF_MASK)) { return 2; } // check if we received the ACK or not return obj->i2c->S & I2C_S_RXAK_MASK ? 1 : 0; }
// this function waits the end of a tx transfer and return the status of the transaction: // 0: OK ack received // 1: OK ack not received // 2: failure static int i2c_wait_end_tx_transfer(i2c_t *obj) { // wait for the interrupt flag uint32_t i2c_addrs[] = I2C_BASE_ADDRS; if (timeout_status_poll(obj, kI2CInterruptPending)) { return 2; } I2C_HAL_ClearInt(i2c_addrs[obj->instance]); // wait transfer complete if (timeout_status_poll(obj, kI2CTransferComplete)) { return 2; } // check if we received the ACK or not return I2C_HAL_GetStatusFlag(i2c_addrs[obj->instance], kI2CReceivedNak) ? 1 : 0; }
// this function waits the end of a rx transfer and return the status of the transaction: // 0: OK // 1: failure static int i2c_wait_end_rx_transfer(i2c_t *obj) { // wait for the end of the rx transfer if (timeout_status_poll(obj, I2C_S_IICIF_MASK)) { return 1; } obj->i2c->S |= I2C_S_IICIF_MASK; return 0; }
// this function waits the end of a rx transfer and return the status of the transaction: // 0: OK // 1: failure static int i2c_wait_end_rx_transfer(i2c_t *obj) { // wait for the end of the rx transfer if (timeout_status_poll(obj, I2C_S_IICIF_MASK)) { return 1; } i2c_hal_clear_interrupt(obj->instance); return 0; }
// this function waits the end of a rx transfer and return the status of the transaction: // 0: OK // 1: failure static int i2c_wait_end_rx_transfer(i2c_t *obj) { // wait for the end of the rx transfer if (timeout_status_poll(obj, kI2CInterruptPending)) { return 1; } uint32_t i2c_addrs[] = I2C_BASE_ADDRS; I2C_HAL_ClearInt(i2c_addrs[obj->instance]); return 0; }