Просмотр исходного кода

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 лет назад
Родитель
Сommit
271ced7341
2 измененных файлов: 12 добавлений и 1 удалений
  1. 10
    1
      Marlin/temperature.cpp
  2. 2
    0
      Marlin/temperature.h

+ 10
- 1
Marlin/temperature.cpp Просмотреть файл

@@ -1483,8 +1483,15 @@ void Temperature::set_current_temp_raw() {
1483 1483
  */
1484 1484
 ISR(TIMER0_COMPB_vect) { Temperature::isr(); }
1485 1485
 
1486
+volatile bool Temperature::in_temp_isr = false;
1487
+
1486 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 1495
   CBI(TIMSK0, OCIE0B); //Disable Temperature ISR
1489 1496
   sei();
1490 1497
 
@@ -1949,5 +1956,7 @@ void Temperature::isr() {
1949 1956
     }
1950 1957
   #endif
1951 1958
 
1959
+  cli();
1960
+  in_temp_isr = false;
1952 1961
   SBI(TIMSK0, OCIE0B); //re-enable Temperature ISR
1953 1962
 }

+ 2
- 0
Marlin/temperature.h Просмотреть файл

@@ -61,6 +61,8 @@ class Temperature {
61 61
                  current_temperature_bed_raw,
62 62
                  target_temperature_bed;
63 63
 
64
+    static volatile bool in_temp_isr;
65
+
64 66
     #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
65 67
       static float redundant_temperature;
66 68
     #endif

Загрузка…
Отмена
Сохранить