Skip to content

Commit

Permalink
fix(PeriphDrivers): MSDK-1242: Fix false stop detection in I2C interr…
Browse files Browse the repository at this point in the history
…upt handler (#765)
  • Loading branch information
Jacob-Scheiffler authored and EricB-ADI committed Oct 26, 2023
1 parent 29c1a25 commit 85475bc
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions Libraries/PeriphDrivers/Source/I2C/i2c_reva.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 85475bc

Please sign in to comment.