Browse Source

Merge pull request #8708 from thinkyhead/bf2_splits_are_expendable

[2.0.x] Discard "continued" blocks on interrupted move
Scott Lahteine 7 years ago
parent
commit
206866ebb3
No account linked to committer's email address
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
   block_t* block = &block_buffer[block_buffer_head];
789
   block_t* block = &block_buffer[block_buffer_head];
790
 
790
 
791
   // Clear all flags, including the "busy" bit
791
   // Clear all flags, including the "busy" bit
792
-  block->flag = 0;
792
+  block->flag = 0x00;
793
 
793
 
794
   // Set direction bits
794
   // Set direction bits
795
   block->direction_bits = dm;
795
   block->direction_bits = dm;
1435
     const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1435
     const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1436
     DISABLE_STEPPER_DRIVER_INTERRUPT();
1436
     DISABLE_STEPPER_DRIVER_INTERRUPT();
1437
     _buffer_steps(between, fr_mm_s, extruder);
1437
     _buffer_steps(between, fr_mm_s, extruder);
1438
+    const uint8_t next = block_buffer_head;
1438
     _buffer_steps(target, fr_mm_s, extruder);
1439
     _buffer_steps(target, fr_mm_s, extruder);
1440
+    SBI(block_buffer[next].flag, BLOCK_BIT_CONTINUED);
1439
     ENABLE_STEPPER_DRIVER_INTERRUPT();
1441
     ENABLE_STEPPER_DRIVER_INTERRUPT();
1440
   }
1442
   }
1441
   else
1443
   else

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

57
   BLOCK_BIT_START_FROM_FULL_HALT,
57
   BLOCK_BIT_START_FROM_FULL_HALT,
58
 
58
 
59
   // The block is busy
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
 enum BlockFlag {
66
 enum BlockFlag {
64
   BLOCK_FLAG_RECALCULATE          = _BV(BLOCK_BIT_RECALCULATE),
67
   BLOCK_FLAG_RECALCULATE          = _BV(BLOCK_BIT_RECALCULATE),
65
   BLOCK_FLAG_NOMINAL_LENGTH       = _BV(BLOCK_BIT_NOMINAL_LENGTH),
68
   BLOCK_FLAG_NOMINAL_LENGTH       = _BV(BLOCK_BIT_NOMINAL_LENGTH),
66
   BLOCK_FLAG_START_FROM_FULL_HALT = _BV(BLOCK_BIT_START_FROM_FULL_HALT),
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
     static bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
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
      * Called when the current block is no longer needed.
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
       if (blocks_queued())
465
       if (blocks_queued())
462
         block_buffer_tail = BLOCK_MOD(block_buffer_tail + 1);
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
      * The current block. NULL if the buffer is empty.
480
      * The current block. NULL if the buffer is empty.
467
      * This also marks the block as busy.
481
      * This also marks the block as busy.
468
      * WARNING: Called from Stepper ISR context!
482
      * WARNING: Called from Stepper ISR context!
469
      */
483
      */
470
     static block_t* get_current_block() {
484
     static block_t* get_current_block() {
471
       if (blocks_queued()) {
485
       if (blocks_queued()) {
472
-        block_t* block = &block_buffer[block_buffer_tail];
486
+        block_t * const block = &block_buffer[block_buffer_tail];
473
         #if ENABLED(ULTRA_LCD)
487
         #if ENABLED(ULTRA_LCD)
474
           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.
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
         #endif
489
         #endif

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

388
   // When cleaning, discard the current block and run fast
388
   // When cleaning, discard the current block and run fast
389
   //
389
   //
390
   if (cleaning_buffer_counter) {
390
   if (cleaning_buffer_counter) {
391
-    if (cleaning_buffer_counter < 0)
391
+    if (cleaning_buffer_counter < 0) {          // Count up for endstop hit
392
-      ++cleaning_buffer_counter;                // 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
     else {
396
     else {
397
+      planner.discard_current_block();
394
       --cleaning_buffer_counter;                // Count down for abort print
398
       --cleaning_buffer_counter;                // Count down for abort print
395
       #ifdef SD_FINISHED_RELEASECOMMAND
399
       #ifdef SD_FINISHED_RELEASECOMMAND
396
         if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
400
         if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
397
       #endif
401
       #endif
398
     }
402
     }
399
-    current_block = NULL;
403
+    current_block = NULL;                       // Prep to get a new block after cleaning
400
-    planner.discard_current_block();
401
     _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 10000);  // Run at max speed - 10 KHz
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
     return;
406
     return;
404
   }
407
   }
405
 
408
 
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
  * Set the stepper positions directly in steps
1130
  * Set the stepper positions directly in steps
1245
   #endif // !COREXY && !COREXZ && !COREYZ
1248
   #endif // !COREXY && !COREXZ && !COREYZ
1246
 
1249
 
1247
   kill_current_block();
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
 void Stepper::report_positions() {
1254
 void Stepper::report_positions() {

Loading…
Cancel
Save