Browse Source

Discard all "continued" blocks on interrupted move

Scott Lahteine 6 years ago
parent
commit
85c6ffbe0d
3 changed files with 33 additions and 14 deletions
  1. 3
    1
      Marlin/src/module/planner.cpp
  2. 19
    5
      Marlin/src/module/planner.h
  3. 11
    8
      Marlin/src/module/stepper.cpp

+ 3
- 1
Marlin/src/module/planner.cpp View File

@@ -789,7 +789,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
789 789
   block_t* block = &block_buffer[block_buffer_head];
790 790
 
791 791
   // Clear all flags, including the "busy" bit
792
-  block->flag = 0;
792
+  block->flag = 0x00;
793 793
 
794 794
   // Set direction bits
795 795
   block->direction_bits = dm;
@@ -1435,7 +1435,9 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1435 1435
     const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1436 1436
     DISABLE_STEPPER_DRIVER_INTERRUPT();
1437 1437
     _buffer_steps(between, fr_mm_s, extruder);
1438
+    const uint8_t next = block_buffer_head;
1438 1439
     _buffer_steps(target, fr_mm_s, extruder);
1440
+    SBI(block_buffer[next].flag, BLOCK_BIT_CONTINUED);
1439 1441
     ENABLE_STEPPER_DRIVER_INTERRUPT();
1440 1442
   }
1441 1443
   else

+ 19
- 5
Marlin/src/module/planner.h View File

@@ -57,14 +57,18 @@ enum BlockFlagBit {
57 57
   BLOCK_BIT_START_FROM_FULL_HALT,
58 58
 
59 59
   // The block is busy
60
-  BLOCK_BIT_BUSY
60
+  BLOCK_BIT_BUSY,
61
+
62
+  // The block is segment 2+ of a longer move
63
+  BLOCK_BIT_CONTINUED
61 64
 };
62 65
 
63 66
 enum BlockFlag {
64 67
   BLOCK_FLAG_RECALCULATE          = _BV(BLOCK_BIT_RECALCULATE),
65 68
   BLOCK_FLAG_NOMINAL_LENGTH       = _BV(BLOCK_BIT_NOMINAL_LENGTH),
66 69
   BLOCK_FLAG_START_FROM_FULL_HALT = _BV(BLOCK_BIT_START_FROM_FULL_HALT),
67
-  BLOCK_FLAG_BUSY                 = _BV(BLOCK_BIT_BUSY)
70
+  BLOCK_FLAG_BUSY                 = _BV(BLOCK_BIT_BUSY),
71
+  BLOCK_FLAG_CONTINUED            = _BV(BLOCK_BIT_CONTINUED)
68 72
 };
69 73
 
70 74
 /**
@@ -454,22 +458,32 @@ class Planner {
454 458
     static bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
455 459
 
456 460
     /**
457
-     * "Discards" the block and "releases" the memory.
461
+     * "Discard" the block and "release" the memory.
458 462
      * Called when the current block is no longer needed.
459 463
      */
460
-    static void discard_current_block() {
464
+    FORCE_INLINE static void discard_current_block() {
461 465
       if (blocks_queued())
462 466
         block_buffer_tail = BLOCK_MOD(block_buffer_tail + 1);
463 467
     }
464 468
 
465 469
     /**
470
+     * "Discard" the next block if it's continued.
471
+     * Called after an interrupted move to throw away the rest of the move.
472
+     */
473
+    FORCE_INLINE static bool discard_continued_block() {
474
+      const bool discard = blocks_queued() && TEST(block_buffer[block_buffer_tail].flag, BLOCK_BIT_CONTINUED);
475
+      if (discard) discard_current_block();
476
+      return discard;
477
+    }
478
+
479
+    /**
466 480
      * The current block. NULL if the buffer is empty.
467 481
      * This also marks the block as busy.
468 482
      * WARNING: Called from Stepper ISR context!
469 483
      */
470 484
     static block_t* get_current_block() {
471 485
       if (blocks_queued()) {
472
-        block_t* block = &block_buffer[block_buffer_tail];
486
+        block_t * const block = &block_buffer[block_buffer_tail];
473 487
         #if ENABLED(ULTRA_LCD)
474 488
           block_buffer_runtime_us -= block->segment_time_us; // We can't be sure how long an active block will take, so don't count it.
475 489
         #endif

+ 11
- 8
Marlin/src/module/stepper.cpp View File

@@ -388,18 +388,21 @@ void Stepper::isr() {
388 388
   // When cleaning, discard the current block and run fast
389 389
   //
390 390
   if (cleaning_buffer_counter) {
391
-    if (cleaning_buffer_counter < 0)
392
-      ++cleaning_buffer_counter;                // Count up for endstop hit
391
+    if (cleaning_buffer_counter < 0) {          // Count up for endstop hit
392
+      if (current_block) planner.discard_current_block(); // Discard the active block that led to the trigger
393
+      if (!planner.discard_continued_block())   // Discard next CONTINUED block
394
+        cleaning_buffer_counter = 0;            // Keep discarding until non-CONTINUED
395
+    }
393 396
     else {
397
+      planner.discard_current_block();
394 398
       --cleaning_buffer_counter;                // Count down for abort print
395 399
       #ifdef SD_FINISHED_RELEASECOMMAND
396 400
         if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
397 401
       #endif
398 402
     }
399
-    current_block = NULL;
400
-    planner.discard_current_block();
403
+    current_block = NULL;                       // Prep to get a new block after cleaning
401 404
     _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 10000);  // Run at max speed - 10 KHz
402
-    HAL_ENABLE_ISRs();                          // Re-enable ISRs
405
+    HAL_ENABLE_ISRs();
403 406
     return;
404 407
   }
405 408
 
@@ -1119,9 +1122,9 @@ void Stepper::init() {
1119 1122
 
1120 1123
 
1121 1124
 /**
1122
- * Block until all buffered steps are executed
1125
+ * Block until all buffered steps are executed / cleaned
1123 1126
  */
1124
-void Stepper::synchronize() { while (planner.blocks_queued()) idle(); }
1127
+void Stepper::synchronize() { while (planner.blocks_queued() || cleaning_buffer_counter) idle(); }
1125 1128
 
1126 1129
 /**
1127 1130
  * Set the stepper positions directly in steps
@@ -1245,7 +1248,7 @@ void Stepper::endstop_triggered(AxisEnum axis) {
1245 1248
   #endif // !COREXY && !COREXZ && !COREYZ
1246 1249
 
1247 1250
   kill_current_block();
1248
-  cleaning_buffer_counter = -(BLOCK_BUFFER_SIZE - 1); // Ignore remaining blocks
1251
+  cleaning_buffer_counter = -1; // Discard the rest of the move
1249 1252
 }
1250 1253
 
1251 1254
 void Stepper::report_positions() {

Loading…
Cancel
Save