Browse Source

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 8 years ago
parent
commit
13eebd11cf
2 changed files with 17 additions and 10 deletions
  1. 4
    2
      Marlin/planner.cpp
  2. 13
    8
      Marlin/planner.h

+ 4
- 2
Marlin/planner.cpp View File

146
 #endif
146
 #endif
147
 
147
 
148
 #if ENABLED(ENSURE_SMOOTH_MOVES)
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
 #endif
150
 #endif
151
 
151
 
152
 /**
152
 /**
1007
       segment_time = (MIN_BLOCK_TIME) * 1000UL;
1007
       segment_time = (MIN_BLOCK_TIME) * 1000UL;
1008
     }
1008
     }
1009
     block->segment_time = segment_time;
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
   #endif
1013
   #endif
1012
 
1014
 
1013
   block->nominal_speed = block->millimeters * inverse_mm_s; // (mm/sec) Always > 0
1015
   block->nominal_speed = block->millimeters * inverse_mm_s; // (mm/sec) Always > 0

+ 13
- 8
Marlin/planner.h View File

215
     #endif
215
     #endif
216
 
216
 
217
     #if ENABLED(ENSURE_SMOOTH_MOVES)
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
     #endif
219
     #endif
220
 
220
 
221
   public:
221
   public:
387
         SBI(block->flag, BLOCK_BIT_BUSY);
387
         SBI(block->flag, BLOCK_BIT_BUSY);
388
         return block;
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
         return NULL;
394
         return NULL;
395
+      }
392
     }
396
     }
393
 
397
 
394
     #if ENABLED(ENSURE_SMOOTH_MOVES)
398
     #if ENABLED(ENSURE_SMOOTH_MOVES)
395
       static bool long_move() {
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
       static void clear_block_buffer_runtime(){
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
     #endif
411
     #endif
407
 
412
 

Loading…
Cancel
Save