Browse Source

Apply minor optimizations to planner.cpp

Scott Lahteine 8 years ago
parent
commit
4d89652bc2
1 changed files with 11 additions and 12 deletions
  1. 11
    12
      Marlin/planner.cpp

+ 11
- 12
Marlin/planner.cpp View File

@@ -145,6 +145,8 @@ void Planner::init() {
145 145
   #endif
146 146
 }
147 147
 
148
+#define MINIMAL_STEP_RATE 120
149
+
148 150
 /**
149 151
  * Calculate trapezoid parameters, multiplying the entry- and exit-speeds
150 152
  * by the provided factors.
@@ -154,8 +156,8 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e
154 156
            final_rate = ceil(block->nominal_rate * exit_factor); // (steps per second)
155 157
 
156 158
   // Limit minimal step rate (Otherwise the timer will overflow.)
157
-  NOLESS(initial_rate, 120);
158
-  NOLESS(final_rate, 120);
159
+  NOLESS(initial_rate, MINIMAL_STEP_RATE);
160
+  NOLESS(final_rate, MINIMAL_STEP_RATE);
159 161
 
160 162
   int32_t accel = block->acceleration_steps_per_s2,
161 163
           accelerate_steps = ceil(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)),
@@ -172,13 +174,9 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e
172 174
     plateau_steps = 0;
173 175
   }
174 176
 
175
-  #if ENABLED(ADVANCE)
176
-    volatile int32_t initial_advance = block->advance * sq(entry_factor),
177
-                       final_advance = block->advance * sq(exit_factor);
178
-  #endif // ADVANCE
179
-
180 177
   // block->accelerate_until = accelerate_steps;
181 178
   // block->decelerate_after = accelerate_steps+plateau_steps;
179
+
182 180
   CRITICAL_SECTION_START;  // Fill variables used by the stepper in a critical section
183 181
   if (!block->busy) { // Don't update variables if block is busy.
184 182
     block->accelerate_until = accelerate_steps;
@@ -186,8 +184,8 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e
186 184
     block->initial_rate = initial_rate;
187 185
     block->final_rate = final_rate;
188 186
     #if ENABLED(ADVANCE)
189
-      block->initial_advance = initial_advance;
190
-      block->final_advance = final_advance;
187
+      block->initial_advance = block->advance * sq(entry_factor);
188
+      block->final_advance = block->advance * sq(exit_factor);
191 189
     #endif
192 190
   }
193 191
   CRITICAL_SECTION_END;
@@ -230,9 +228,10 @@ void Planner::reverse_pass() {
230 228
     block_t* block[3] = { NULL, NULL, NULL };
231 229
 
232 230
     // Make a local copy of block_buffer_tail, because the interrupt can alter it
233
-    CRITICAL_SECTION_START;
234
-      uint8_t tail = block_buffer_tail;
235
-    CRITICAL_SECTION_END
231
+    // Is a critical section REALLY needed for a single byte change?
232
+    //CRITICAL_SECTION_START;
233
+    uint8_t tail = block_buffer_tail;
234
+    //CRITICAL_SECTION_END
236 235
 
237 236
     uint8_t b = BLOCK_MOD(block_buffer_head - 3);
238 237
     while (b != tail) {

Loading…
Cancel
Save