Browse Source

Replace block.busy with a block.flag bit

Scott Lahteine 7 years ago
parent
commit
75dbb71dd7
3 changed files with 34 additions and 29 deletions
  1. 13
    16
      Marlin/planner.cpp
  2. 20
    12
      Marlin/planner.h
  3. 1
    1
      Marlin/stepper.cpp

+ 13
- 16
Marlin/planner.cpp View File

@@ -180,7 +180,7 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e
180 180
   // block->decelerate_after = accelerate_steps+plateau_steps;
181 181
 
182 182
   CRITICAL_SECTION_START;  // Fill variables used by the stepper in a critical section
183
-  if (!block->busy) { // Don't update variables if block is busy.
183
+  if (!TEST(block->flag, BLOCK_BIT_BUSY)) { // Don't update variables if block is busy.
184 184
     block->accelerate_until = accelerate_steps;
185 185
     block->decelerate_after = accelerate_steps + plateau_steps;
186 186
     block->initial_rate = initial_rate;
@@ -212,10 +212,10 @@ void Planner::reverse_pass_kernel(block_t* const current, const block_t *next) {
212 212
   if (current->entry_speed != max_entry_speed) {
213 213
     // If nominal length true, max junction speed is guaranteed to be reached. Only compute
214 214
     // for max allowable speed if block is decelerating and nominal length is false.
215
-    current->entry_speed = ((current->flag & BLOCK_FLAG_NOMINAL_LENGTH) || max_entry_speed <= next->entry_speed)
215
+    current->entry_speed = (TEST(current->flag, BLOCK_BIT_NOMINAL_LENGTH) || max_entry_speed <= next->entry_speed)
216 216
       ? max_entry_speed
217 217
       : min(max_entry_speed, max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters));
218
-    current->flag |= BLOCK_FLAG_RECALCULATE;
218
+    SBI(current->flag, BLOCK_BIT_RECALCULATE);
219 219
   }
220 220
 }
221 221
 
@@ -237,7 +237,7 @@ void Planner::reverse_pass() {
237 237
 
238 238
     uint8_t b = BLOCK_MOD(block_buffer_head - 3);
239 239
     while (b != tail) {
240
-      if (block[0] && (block[0]->flag & BLOCK_FLAG_START_FROM_FULL_HALT)) break;
240
+      if (block[0] && TEST(block[0]->flag, BLOCK_BIT_START_FROM_FULL_HALT)) break;
241 241
       b = prev_block_index(b);
242 242
       block[2] = block[1];
243 243
       block[1] = block[0];
@@ -255,14 +255,14 @@ void Planner::forward_pass_kernel(const block_t* previous, block_t* const curren
255 255
   // full speed change within the block, we need to adjust the entry speed accordingly. Entry
256 256
   // speeds have already been reset, maximized, and reverse planned by reverse planner.
257 257
   // If nominal length is true, max junction speed is guaranteed to be reached. No need to recheck.
258
-  if (!(previous->flag & BLOCK_FLAG_NOMINAL_LENGTH)) {
258
+  if (!TEST(previous->flag, BLOCK_BIT_NOMINAL_LENGTH)) {
259 259
     if (previous->entry_speed < current->entry_speed) {
260 260
       float entry_speed = min(current->entry_speed,
261 261
                                max_allowable_speed(-previous->acceleration, previous->entry_speed, previous->millimeters));
262 262
       // Check for junction speed change
263 263
       if (current->entry_speed != entry_speed) {
264 264
         current->entry_speed = entry_speed;
265
-        current->flag |= BLOCK_FLAG_RECALCULATE;
265
+        SBI(current->flag, BLOCK_BIT_RECALCULATE);
266 266
       }
267 267
     }
268 268
   }
@@ -298,11 +298,11 @@ void Planner::recalculate_trapezoids() {
298 298
     next = &block_buffer[block_index];
299 299
     if (current) {
300 300
       // Recalculate if current block entry or exit junction speed has changed.
301
-      if ((current->flag & BLOCK_FLAG_RECALCULATE) || (next->flag & BLOCK_FLAG_RECALCULATE)) {
301
+      if (TEST(current->flag, BLOCK_BIT_RECALCULATE) || TEST(next->flag, BLOCK_BIT_RECALCULATE)) {
302 302
         // NOTE: Entry and exit factors always > 0 by all previous logic operations.
303 303
         float nom = current->nominal_speed;
304 304
         calculate_trapezoid_for_block(current, current->entry_speed / nom, next->entry_speed / nom);
305
-        current->flag &= ~BLOCK_FLAG_RECALCULATE; // Reset current only to ensure next trapezoid is computed
305
+        CBI(current->flag, BLOCK_BIT_RECALCULATE); // Reset current only to ensure next trapezoid is computed
306 306
       }
307 307
     }
308 308
     block_index = next_block_index(block_index);
@@ -311,7 +311,7 @@ void Planner::recalculate_trapezoids() {
311 311
   if (next) {
312 312
     float nom = next->nominal_speed;
313 313
     calculate_trapezoid_for_block(next, next->entry_speed / nom, (MINIMUM_PLANNER_SPEED) / nom);
314
-    next->flag &= ~BLOCK_FLAG_RECALCULATE;
314
+    CBI(next->flag, BLOCK_BIT_RECALCULATE);
315 315
   }
316 316
 }
317 317
 
@@ -666,8 +666,8 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
666 666
   // Prepare to set up new block
667 667
   block_t* block = &block_buffer[block_buffer_head];
668 668
 
669
-  // Mark block as not busy (Not executed by the stepper interrupt)
670
-  block->busy = false;
669
+  // Clear all flags, including the "busy" bit
670
+  block->flag = 0;
671 671
 
672 672
   // Number of steps for each axis
673 673
   #if ENABLED(COREXY)
@@ -699,9 +699,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
699 699
   // Bail if this is a zero-length block
700 700
   if (block->step_event_count < MIN_STEPS_PER_SEGMENT) return;
701 701
 
702
-  // Clear the block flags
703
-  block->flag = 0;
704
-
705 702
   // For a mixing extruder, get a magnified step_event_count for each
706 703
   #if ENABLED(MIXING_EXTRUDER)
707 704
     for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
@@ -1187,12 +1184,12 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1187 1184
     if (previous_safe_speed > vmax_junction_threshold && safe_speed > vmax_junction_threshold) {
1188 1185
       // Not coasting. The machine will stop and start the movements anyway,
1189 1186
       // better to start the segment from start.
1190
-      block->flag |= BLOCK_FLAG_START_FROM_FULL_HALT;
1187
+      SBI(block->flag, BLOCK_BIT_START_FROM_FULL_HALT);
1191 1188
       vmax_junction = safe_speed;
1192 1189
     }
1193 1190
   }
1194 1191
   else {
1195
-    block->flag |= BLOCK_FLAG_START_FROM_FULL_HALT;
1192
+    SBI(block->flag, BLOCK_BIT_START_FROM_FULL_HALT);
1196 1193
     vmax_junction = safe_speed;
1197 1194
   }
1198 1195
 

+ 20
- 12
Marlin/planner.h View File

@@ -40,17 +40,27 @@
40 40
   #include "vector_3.h"
41 41
 #endif
42 42
 
43
-enum BlockFlag {
44
-    // Recalculate trapezoids on entry junction. For optimization.
45
-    BLOCK_FLAG_RECALCULATE          = _BV(0),
43
+enum BlockFlagBit {
44
+  // Recalculate trapezoids on entry junction. For optimization.
45
+  BLOCK_BIT_RECALCULATE,
46
+
47
+  // Nominal speed always reached.
48
+  // i.e., The segment is long enough, so the nominal speed is reachable if accelerating
49
+  // from a safe speed (in consideration of jerking from zero speed).
50
+  BLOCK_BIT_NOMINAL_LENGTH,
51
+
52
+  // Start from a halt at the start of this block, respecting the maximum allowed jerk.
53
+  BLOCK_BIT_START_FROM_FULL_HALT,
46 54
 
47
-    // Nominal speed always reached.
48
-    // i.e., The segment is long enough, so the nominal speed is reachable if accelerating
49
-    // from a safe speed (in consideration of jerking from zero speed).
50
-    BLOCK_FLAG_NOMINAL_LENGTH       = _BV(1),
55
+  // The block is busy
56
+  BLOCK_BIT_BUSY
57
+};
51 58
 
52
-    // Start from a halt at the start of this block, respecting the maximum allowed jerk.
53
-    BLOCK_FLAG_START_FROM_FULL_HALT = _BV(2)
59
+enum BlockFlag {
60
+  BLOCK_FLAG_RECALCULATE          = _BV(BLOCK_BIT_RECALCULATE),
61
+  BLOCK_FLAG_NOMINAL_LENGTH       = _BV(BLOCK_BIT_NOMINAL_LENGTH),
62
+  BLOCK_FLAG_START_FROM_FULL_HALT = _BV(BLOCK_BIT_START_FROM_FULL_HALT),
63
+  BLOCK_FLAG_BUSY                 = _BV(BLOCK_BIT_BUSY)
54 64
 };
55 65
 
56 66
 /**
@@ -113,8 +123,6 @@ typedef struct {
113 123
     unsigned long valve_pressure, e_to_p_pressure;
114 124
   #endif
115 125
 
116
-  volatile char busy;
117
-
118 126
 } block_t;
119 127
 
120 128
 #define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1))
@@ -341,7 +349,7 @@ class Planner {
341 349
     static block_t* get_current_block() {
342 350
       if (blocks_queued()) {
343 351
         block_t* block = &block_buffer[block_buffer_tail];
344
-        block->busy = true;
352
+        SBI(block->flag, BLOCK_BIT_BUSY);
345 353
         return block;
346 354
       }
347 355
       else

+ 1
- 1
Marlin/stepper.cpp View File

@@ -344,7 +344,7 @@ void Stepper::isr() {
344 344
     // Anything in the buffer?
345 345
     current_block = planner.get_current_block();
346 346
     if (current_block) {
347
-      current_block->busy = true;
347
+      SBI(current_block->flag, BLOCK_BIT_BUSY);
348 348
       trapezoid_generator_reset();
349 349
 
350 350
       // Initialize Bresenham counters to 1/2 the ceiling

Loading…
Cancel
Save