Procházet zdrojové kódy

volatile_block_buffer_runtime_us

`block_buffer_runtime_us` is mangled in the planner and in the stepper-ISR.
So it needs to be volatile and interrupt protected.
AnHardt před 8 roky
rodič
revize
13eebd11cf
2 změnil soubory, kde provedl 17 přidání a 10 odebrání
  1. 4
    2
      Marlin/planner.cpp
  2. 13
    8
      Marlin/planner.h

+ 4
- 2
Marlin/planner.cpp Zobrazit soubor

@@ -146,7 +146,7 @@ float Planner::previous_speed[NUM_AXIS],
146 146
 #endif
147 147
 
148 148
 #if ENABLED(ENSURE_SMOOTH_MOVES)
149
-  uint32_t Planner::block_buffer_runtime_us = 0;
149
+  volatile uint32_t Planner::block_buffer_runtime_us = 0;
150 150
 #endif
151 151
 
152 152
 /**
@@ -1007,7 +1007,9 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1007 1007
       segment_time = (MIN_BLOCK_TIME) * 1000UL;
1008 1008
     }
1009 1009
     block->segment_time = segment_time;
1010
-    block_buffer_runtime_us += segment_time;
1010
+    CRITICAL_SECTION_START
1011
+      block_buffer_runtime_us += segment_time;
1012
+    CRITICAL_SECTION_END
1011 1013
   #endif
1012 1014
 
1013 1015
   block->nominal_speed = block->millimeters * inverse_mm_s; // (mm/sec) Always > 0

+ 13
- 8
Marlin/planner.h Zobrazit soubor

@@ -215,7 +215,7 @@ class Planner {
215 215
     #endif
216 216
 
217 217
     #if ENABLED(ENSURE_SMOOTH_MOVES)
218
-      static uint32_t block_buffer_runtime_us; //Theoretical block buffer runtime in µs
218
+      volatile static uint32_t block_buffer_runtime_us; //Theoretical block buffer runtime in µs
219 219
     #endif
220 220
 
221 221
   public:
@@ -387,21 +387,26 @@ class Planner {
387 387
         SBI(block->flag, BLOCK_BIT_BUSY);
388 388
         return block;
389 389
       }
390
-      else
390
+      else {
391
+        #if ENABLED(ENSURE_SMOOTH_MOVES)
392
+          clear_block_buffer_runtime(); // paranoia. Buffer is empty now - so reset accumulated time to zero.
393
+        #endif
391 394
         return NULL;
395
+      }
392 396
     }
393 397
 
394 398
     #if ENABLED(ENSURE_SMOOTH_MOVES)
395 399
       static bool long_move() {
396
-        if (block_buffer_runtime_us) {
397
-          return block_buffer_runtime_us > (LCD_UPDATE_THRESHOLD) * 1000UL + (MIN_BLOCK_TIME) * 3000UL;
398
-        }
399
-        else
400
-          return true;
400
+        CRITICAL_SECTION_START
401
+          uint32_t bbru = block_buffer_runtime_us;
402
+        CRITICAL_SECTION_END
403
+        return !bbru || bbru > (LCD_UPDATE_THRESHOLD) * 1000UL + (MIN_BLOCK_TIME) * 3000UL;
401 404
       }
402 405
       
403 406
       static void clear_block_buffer_runtime(){
404
-        block_buffer_runtime_us = 0;
407
+        CRITICAL_SECTION_START
408
+          block_buffer_runtime_us = 0;
409
+        CRITICAL_SECTION_END
405 410
       }
406 411
     #endif
407 412
 

Loading…
Zrušit
Uložit