Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/DuetNG/DueXn.cpp8
-rw-r--r--src/DuetNG/SX1509.cpp2
-rw-r--r--src/Hardware/I2C.cpp11
-rw-r--r--src/Hardware/I2C.h2
4 files changed, 12 insertions, 11 deletions
diff --git a/src/DuetNG/DueXn.cpp b/src/DuetNG/DueXn.cpp
index c73cdb24..fd902e8f 100644
--- a/src/DuetNG/DueXn.cpp
+++ b/src/DuetNG/DueXn.cpp
@@ -33,7 +33,6 @@ namespace DuetExpansion
static volatile uint32_t dueXnReadCount = 0;
static uint32_t dueXnReadCountResetMillis = 0;
static volatile bool taskWaiting = false;
- static volatile bool inputsChanged = false;
Task<DueXTaskStackWords> *dueXTask = nullptr;
@@ -71,7 +70,6 @@ namespace DuetExpansion
// Otherwise we might wake it prematurely when it is waiting for an I2C transaction to be completed.
static void DueXIrq(CallbackParameter p) noexcept
{
- inputsChanged = true;
if (taskWaiting)
{
taskWaiting = false;
@@ -84,14 +82,12 @@ namespace DuetExpansion
{
for (;;)
{
- inputsChanged = false;
- taskWaiting = false;
+ taskWaiting = false; // make sure we are not notified while we do the I2C transaction
TaskBase::ClearNotifyCount();
dueXnInputBits = dueXnExpander.digitalReadAll();
taskWaiting = true;
++dueXnReadCount;
- __DSB();
- if (!inputsChanged)
+ if (digitalRead(DueX_INT))
{
(void)TaskBase::Take();
}
diff --git a/src/DuetNG/SX1509.cpp b/src/DuetNG/SX1509.cpp
index ffbd8744..208cf35b 100644
--- a/src/DuetNG/SX1509.cpp
+++ b/src/DuetNG/SX1509.cpp
@@ -55,7 +55,7 @@ bool SX1509::begin(uint8_t address) noexcept
{
clock(DefaultOscDivider);
writeWord(REG_HIGH_INPUT_B, 0xFFFF); // set all inputs to be 5V-tolerant
- writeByte(REG_DEBOUNCE_CONFIG, 0); // debounce time set to minimum (0.5ms)
+ writeByte(REG_DEBOUNCE_CONFIG, 1); // debounce time set to 1ms
}
return ok;
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;
}
diff --git a/src/Hardware/I2C.h b/src/Hardware/I2C.h
index 414a403c..12a57799 100644
--- a/src/Hardware/I2C.h
+++ b/src/Hardware/I2C.h
@@ -25,7 +25,7 @@ namespace I2C
// Transfer data to/from an I2C peripheral.
// If the caller needs to do multiple I2C transactions without being interrupted, it should own the i2C mutex before calling this.
- // Otherwise the caller need nort own the mutex because it will be acquired here.
+ // Otherwise the caller need not own the mutex because it will be acquired here.
inline size_t Transfer(uint16_t address, uint8_t *buffer, size_t numToWrite, size_t numToRead) noexcept
{
MutexLocker Lock(Tasks::GetI2CMutex());