mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-01-23 19:18:51 +01:00
Ack read outside interrupt
This commit is contained in:
parent
696d12fc5e
commit
a194b8965c
@ -53,9 +53,22 @@ void DCCWaveform::begin(MotorDriver * mainDriver, MotorDriver * progDriver) {
|
|||||||
DCCTimer::begin(DCCWaveform::interruptHandler);
|
DCCTimer::begin(DCCWaveform::interruptHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SLOW_ANALOG_READ
|
||||||
|
#ifdef SLOW_ANALOG_READ
|
||||||
|
// Flag to hold if we need to run ack checking in loop
|
||||||
|
static bool ackflag = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
void IRAM_ATTR DCCWaveform::loop(bool ackManagerActive) {
|
void IRAM_ATTR DCCWaveform::loop(bool ackManagerActive) {
|
||||||
mainTrack.checkPowerOverload(false);
|
mainTrack.checkPowerOverload(false);
|
||||||
progTrack.checkPowerOverload(ackManagerActive);
|
progTrack.checkPowerOverload(ackManagerActive);
|
||||||
|
#ifdef SLOW_ANALOG_READ
|
||||||
|
if (ackflag) {
|
||||||
|
progTrack.checkAck();
|
||||||
|
// reset flag AFTER check is done
|
||||||
|
ackflag = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR DCCWaveform::interruptHandler() {
|
void IRAM_ATTR DCCWaveform::interruptHandler() {
|
||||||
@ -70,9 +83,17 @@ void IRAM_ATTR DCCWaveform::interruptHandler() {
|
|||||||
mainTrack.state=stateTransform[mainTrack.state];
|
mainTrack.state=stateTransform[mainTrack.state];
|
||||||
progTrack.state=stateTransform[progTrack.state];
|
progTrack.state=stateTransform[progTrack.state];
|
||||||
// WAVE_PENDING means we dont yet know what the next bit is
|
// WAVE_PENDING means we dont yet know what the next bit is
|
||||||
if (mainTrack.state==WAVE_PENDING) mainTrack.interrupt2();
|
if (mainTrack.state==WAVE_PENDING)
|
||||||
if (progTrack.state==WAVE_PENDING) progTrack.interrupt2();
|
mainTrack.interrupt2();
|
||||||
else if (progTrack.ackPending) progTrack.checkAck();
|
if (progTrack.state==WAVE_PENDING)
|
||||||
|
progTrack.interrupt2();
|
||||||
|
#ifdef SLOW_ANALOG_READ
|
||||||
|
else if (progTrack.ackPending && ackflag == 0) // We need AND we are not already checking
|
||||||
|
ackflag = 1;
|
||||||
|
#else
|
||||||
|
else if (progTrack.ackPending)
|
||||||
|
progTrack.checkAck();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -308,7 +329,7 @@ void ICACHE_RAM_ATTR DCCWaveform::checkAck() {
|
|||||||
ackPending = false;
|
ackPending = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int current=motorDriver->getCurrentRaw();
|
int current=motorDriver->getCurrentRaw();
|
||||||
numAckSamples++;
|
numAckSamples++;
|
||||||
if (current > ackMaxCurrent) ackMaxCurrent=current;
|
if (current > ackMaxCurrent) ackMaxCurrent=current;
|
||||||
|
Loading…
Reference in New Issue
Block a user