Error mechanism:
Let's suppose we are in 'Temperature::isr()'.
CBI(TIMSK0, OCIE0B); //Disable Temperature ISR
sei();
The temperature-interrupt is disabled, but all others are enabled.
Now the temp-isr is interrupted by the Stepper::advance_isr_scheduler()
// Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
CBI(TIMSK0, OCIE0B); // Temperature ISR
DISABLE_STEPPER_DRIVER_INTERRUPT();
sei();
temp-isr and stepper-isr are disabled.
When we leave the Stepper::advance_isr_scheduler() we execute
// Restore original ISR settings
cli();
SBI(TIMSK0, OCIE0B);
ENABLE_STEPPER_DRIVER_INTERRUPT();
Enable temp-isr and stepper-isr. In case we interrupted the temp-isr this does not restore the ISR settings, but enables the temp-isr falsely.
If its time for a fresh temp-isr now, this is entered before the still on the stack temp-isr ended - the temp-isr bites its tail.
Problems:
Is temp-isr is entered multiple times the stack may overflow.
temp-isr is not made for reentering.
Symptoms:
Sampling OVERSAMPLENR+1 (or more) instead of OVERSAMPLENR samples.
if the temperature is low (high raw values) this may result in min-temp-error.
if the temperature is high it looks like a sudden, and only one time, drop of temperature by about 1/17 the expected one.
Even worse and unpredictable things when the stack overfolowes
Error mechanism: Let's suppose we are in 'Temperature::isr()'.
The temperature-interrupt is disabled, but all others are enabled.
Now the temp-isr is interrupted by the
Stepper::advance_isr_scheduler()
temp-isr and stepper-isr are disabled. When we leave the
Stepper::advance_isr_scheduler()
we executeEnable temp-isr and stepper-isr. In case we interrupted the temp-isr this does not restore the ISR settings, but enables the temp-isr falsely. If its time for a fresh temp-isr now, this is entered before the still on the stack temp-isr ended - the temp-isr bites its tail.
Problems: Is temp-isr is entered multiple times the stack may overflow. temp-isr is not made for reentering.
Symptoms: Sampling OVERSAMPLENR+1 (or more) instead of OVERSAMPLENR samples.
Even worse and unpredictable things when the stack overfolowes