Hi Kan,
Thank you for more comment.
It makes me more clear to undstand the whole thing.
As my understanding,
Once the master transfer done, the status shoud be set as "I2C_STATUS_DONE". Am I right?
And I see it would happen in two cases as below:
1. -# Interrupt based handling makes use of #Chip_I2C_EventHandler handler.
I2C0_IRQHandler => Chip_I2C_MasterStateHandler => handleMasterXferState => change "xfer->status" to “I2C_STATUS_DONE” once master transfer done;
2. -# Polling based handling makes use of #Chip_I2C_EventHandlerPolling handler.
Chip_I2C_EventHandlerPolling => Chip_I2C_MasterStateHandler => handleMasterXferState => change "xfer->status" to “I2C_STATUS_DONE” once master transfer done.
Is it right?
And if the stat is always I2C_STATUS_BUSY, the while condition is always met and the function is never return.
So I am confused why the stat was not changed.
------
/* Chip event handler interrupt based */
void Chip_I2C_EventHandler(I2C_ID_T id, I2C_EVENT_T event)
{
struct i2c_interface *iic = &i2c[id];
volatile I2C_STATUS_T *stat;
/* Only WAIT event needs to be handled */
if (event != I2C_EVENT_WAIT) {
return;
}
stat = &iic->mXfer->status;
/* Wait for the status to change */
while (*stat == I2C_STATUS_BUSY) {
}
}
/* Chip polling event handler */
void Chip_I2C_EventHandlerPolling(I2C_ID_T id, I2C_EVENT_T event)
{
struct i2c_interface *iic = &i2c[id];
volatile I2C_STATUS_T *stat;
/* Only WAIT event needs to be handled */
if (event != I2C_EVENT_WAIT) {
return;
}
stat = &iic->mXfer->status;
/* Call the state change handler till xfer is done */
while (*stat == I2C_STATUS_BUSY) {
if (Chip_I2C_IsStateChanged(id)) {
Chip_I2C_MasterStateHandler(id);
}
}
}
------
Thanks,
Arna