Prevent re-entering of temperature ISR

If Marlin is inside the temperature ISR, the stepper ISR is enabled. If
a stepper event is now happening Marlin will proceed with the stepper
ISR. Now, at the end of the stepper ISR, the temperatre ISR gets enabled
again. While Marlin proceed the rest of the temperature ISR, it's now
vulnerable to a second ISR call.
2.0.x
Sebastianv650 8 years ago committed by Scott Lahteine
parent 1b59766fcb
commit 271ced7341

@ -1483,8 +1483,15 @@ void Temperature::set_current_temp_raw() {
*/
ISR(TIMER0_COMPB_vect) { Temperature::isr(); }
volatile bool Temperature::in_temp_isr = false;
void Temperature::isr() {
//Allow UART and stepper ISRs
// The stepper ISR can interrupt this ISR. When it does it re-enables this ISR
// at the end of its run, potentially causing re-entry. This flag prevents it.
if (in_temp_isr) return;
in_temp_isr = true;
// Allow UART and stepper ISRs
CBI(TIMSK0, OCIE0B); //Disable Temperature ISR
sei();
@ -1949,5 +1956,7 @@ void Temperature::isr() {
}
#endif
cli();
in_temp_isr = false;
SBI(TIMSK0, OCIE0B); //re-enable Temperature ISR
}

@ -61,6 +61,8 @@ class Temperature {
current_temperature_bed_raw,
target_temperature_bed;
static volatile bool in_temp_isr;
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
static float redundant_temperature;
#endif

Loading…
Cancel
Save