Browse Source

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.
Sebastianv650 7 years ago
parent
commit
271ced7341
2 changed files with 12 additions and 1 deletions
  1. 10
    1
      Marlin/temperature.cpp
  2. 2
    0
      Marlin/temperature.h

+ 10
- 1
Marlin/temperature.cpp View File

1483
  */
1483
  */
1484
 ISR(TIMER0_COMPB_vect) { Temperature::isr(); }
1484
 ISR(TIMER0_COMPB_vect) { Temperature::isr(); }
1485
 
1485
 
1486
+volatile bool Temperature::in_temp_isr = false;
1487
+
1486
 void Temperature::isr() {
1488
 void Temperature::isr() {
1487
-  //Allow UART and stepper ISRs
1489
+  // The stepper ISR can interrupt this ISR. When it does it re-enables this ISR
1490
+  // at the end of its run, potentially causing re-entry. This flag prevents it.
1491
+  if (in_temp_isr) return;
1492
+  in_temp_isr = true;
1493
+  
1494
+  // Allow UART and stepper ISRs
1488
   CBI(TIMSK0, OCIE0B); //Disable Temperature ISR
1495
   CBI(TIMSK0, OCIE0B); //Disable Temperature ISR
1489
   sei();
1496
   sei();
1490
 
1497
 
1949
     }
1956
     }
1950
   #endif
1957
   #endif
1951
 
1958
 
1959
+  cli();
1960
+  in_temp_isr = false;
1952
   SBI(TIMSK0, OCIE0B); //re-enable Temperature ISR
1961
   SBI(TIMSK0, OCIE0B); //re-enable Temperature ISR
1953
 }
1962
 }

+ 2
- 0
Marlin/temperature.h View File

61
                  current_temperature_bed_raw,
61
                  current_temperature_bed_raw,
62
                  target_temperature_bed;
62
                  target_temperature_bed;
63
 
63
 
64
+    static volatile bool in_temp_isr;
65
+
64
     #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
66
     #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
65
       static float redundant_temperature;
67
       static float redundant_temperature;
66
     #endif
68
     #endif

Loading…
Cancel
Save