diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-02-10 12:32:53 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-02-10 12:32:53 +0300 |
commit | b31114bf2d606fb5e4c1e37c0867932c004dd112 (patch) | |
tree | 082eacaa705386ad9c6e776e70e617e7a6f499e3 /src/Hardware/I2C.cpp | |
parent | f7642e6bcb95a32920dde0c787e5462dad2141d9 (diff) |
Ported DueX I2C fixes from release 3.2.2
Diffstat (limited to 'src/Hardware/I2C.cpp')
-rw-r--r-- | src/Hardware/I2C.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/Hardware/I2C.cpp b/src/Hardware/I2C.cpp index c62db5e7..50db157b 100644 --- a/src/Hardware/I2C.cpp +++ b/src/Hardware/I2C.cpp @@ -21,6 +21,7 @@ void I2C::Init() noexcept MutexLocker lock(Tasks::GetI2CMutex()); if (!i2cInitialised) // test it again, now that we own the mutex { + NVIC_SetPriority(I2C_IRQn, NvicPriorityTwi); // we use I2C to talk to the DueX before Platform::InitialiseInterrupts is called, so need to do this here I2C_IFACE.BeginMaster(I2cClockFreq); i2cInitialised = true; } @@ -43,15 +44,19 @@ extern "C" void WIRE_ISR_HANDLER() noexcept uint32_t I2C::statusWaitFunc(Twi *twi, uint32_t bitsToWaitFor) noexcept { + bool ok = true; uint32_t sr = twi->TWI_SR; - if ((sr & bitsToWaitFor) == 0) + while (ok && (sr & bitsToWaitFor) == 0) { // Suspend this task until we get an interrupt indicating that a status bit that we are interested in has been set twiTask = TaskBase::GetCallerTaskHandle(); + twi->TWI_IDR = 0xFFFFFFFF; twi->TWI_IER = bitsToWaitFor; - (void)TaskBase::Take(2); - sr = twi->TWI_SR; + NVIC_EnableIRQ(I2C_IRQn); + ok = TaskBase::Take(2); + twiTask = nullptr; twi->TWI_IDR = 0xFFFFFFFF; + sr = twi->TWI_SR; } return sr; } |