From 9a72f1c6a2d903a5691c39d47f30bd86202655e2 Mon Sep 17 00:00:00 2001 From: Jacob Scheiffler <86001820+Jacob-Scheiffler@users.noreply.github.com> Date: Thu, 12 Oct 2023 13:15:44 -0500 Subject: [PATCH] fix(PeriphDrivers): MSDK-1242: Fix false stop detection in I2C interrupt handler (#765) --- Libraries/PeriphDrivers/Source/I2C/i2c_reva.c | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/I2C/i2c_reva.c b/Libraries/PeriphDrivers/Source/I2C/i2c_reva.c index 55554a788b..c9b3d0c615 100644 --- a/Libraries/PeriphDrivers/Source/I2C/i2c_reva.c +++ b/Libraries/PeriphDrivers/Source/I2C/i2c_reva.c @@ -1531,9 +1531,36 @@ void MXC_I2C_RevA_SlaveAsyncHandler(mxc_i2c_reva_regs_t *i2c, mxc_i2c_reva_slave } } + // Check if transaction completed or restart occurred + if (int_en[0] & MXC_F_I2C_REVA_INTFL0_DONE) { + if (tFlags & MXC_F_I2C_REVA_INTFL0_STOP) { + // Stop/NACK condition occurred, transaction complete + *retVal = E_NO_ERROR; + + if (callback != NULL) { + callback(i2c, MXC_I2C_REVA_EVT_TRANS_COMP, retVal); + } + + i2c->intfl0 = MXC_F_I2C_REVA_INTFL0_STOP; + int_en[0] = 0; + int_en[1] = 0; + AsyncRequests[MXC_I2C_GET_IDX((mxc_i2c_regs_t *)i2c)] = NULL; + } else if (tFlags & MXC_F_I2C_REVA_INTFL0_DONE) { + // Restart detected, re-arm address match interrupt + i2c->intfl0 = MXC_F_I2C_REVA_INTFL0_DONE; + int_en[0] = MXC_F_I2C_REVA_INTFL0_ADDR_MATCH; + } + } + // Check for address match interrupt if (int_en[0] & MXC_F_I2C_REVA_INTFL0_ADDR_MATCH) { if (tFlags & MXC_F_I2C_REVA_INTFL0_ADDR_MATCH) { + // Address match occurred, prepare for transaction + if (tFlags & MXC_F_I2C_REVA_INTFL0_STOP && !(tFlags & MXC_F_I2C_REVA_INTFL0_DONE)) { + // Clear stop flag if it was asserted in a previous transaction + i2c->intfl0 = MXC_F_I2C_REVA_INTFL0_STOP; + } + if (i2c->ctrl & MXC_F_I2C_REVA_CTRL_READ) { // Read request received from the master if (callback != NULL) { @@ -1561,27 +1588,6 @@ void MXC_I2C_RevA_SlaveAsyncHandler(mxc_i2c_reva_regs_t *i2c, mxc_i2c_reva_slave } } } - - // Check if transaction completed or restart occurred - if (int_en[0] & MXC_F_I2C_REVA_INTFL0_DONE) { - if (tFlags & MXC_F_I2C_REVA_INTFL0_STOP) { - // Stop/NACK condition occurred, transaction complete - *retVal = E_NO_ERROR; - - if (callback != NULL) { - callback(i2c, MXC_I2C_REVA_EVT_TRANS_COMP, retVal); - } - - i2c->intfl0 = MXC_F_I2C_REVA_INTFL0_STOP; - int_en[0] = 0; - int_en[1] = 0; - AsyncRequests[MXC_I2C_GET_IDX((mxc_i2c_regs_t *)i2c)] = NULL; - } else if (tFlags & MXC_F_I2C_REVA_INTFL0_DONE) { - // Restart detected, re-arm address match interrupt - i2c->intfl0 = MXC_F_I2C_REVA_INTFL0_DONE; - int_en[0] = MXC_F_I2C_REVA_INTFL0_ADDR_MATCH; - } - } } void MXC_I2C_RevA_AsyncHandler(mxc_i2c_reva_regs_t *i2c, uint32_t interruptCheck)