Browse Source

Followup to HAL_timer_restrain

Followup to #9985
Scott Lahteine 7 years ago
parent
commit
98d48fc731

+ 1
- 1
Marlin/src/HAL/HAL_AVR/HAL_AVR.h View File

150
 
150
 
151
 #define _CAT(a, ...) a ## __VA_ARGS__
151
 #define _CAT(a, ...) a ## __VA_ARGS__
152
 #define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
152
 #define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
153
-#define HAL_timer_restrain(timer, interval_us) NOLESS(_CAT(TIMER_OCR_, timer), _CAT(TIMER_COUNTER_, timer) + interval_us * HAL_TICKS_PER_US)
153
+#define HAL_timer_restrain(timer, interval_ticks) NOLESS(_CAT(TIMER_OCR_, timer), _CAT(TIMER_COUNTER_, timer) + interval_ticks)
154
 
154
 
155
 #define HAL_timer_get_compare(timer) _CAT(TIMER_OCR_, timer)
155
 #define HAL_timer_get_compare(timer) _CAT(TIMER_OCR_, timer)
156
 #define HAL_timer_get_count(timer) _CAT(TIMER_COUNTER_, timer)
156
 #define HAL_timer_get_count(timer) _CAT(TIMER_COUNTER_, timer)

+ 2
- 2
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h View File

109
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
109
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
110
 }
110
 }
111
 
111
 
112
-FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_us) {
113
-  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_us * HAL_TICKS_PER_US;
112
+FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
113
+  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
114
   if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
114
   if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
115
 }
115
 }
116
 
116
 

+ 2
- 2
Marlin/src/HAL/HAL_LPC1768/HAL_timers.h View File

120
   return 0;
120
   return 0;
121
 }
121
 }
122
 
122
 
123
-FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_us) {
124
-  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_us * HAL_TICKS_PER_US;
123
+FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
124
+  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
125
   if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
125
   if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
126
 }
126
 }
127
 
127
 

+ 2
- 2
Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h View File

154
   }
154
   }
155
 }
155
 }
156
 
156
 
157
-FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_us) {
158
-  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_us * HAL_TICKS_PER_US;
157
+FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
158
+  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
159
   if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
159
   if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
160
 }
160
 }
161
 
161
 

+ 2
- 2
Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp View File

137
   return __HAL_TIM_GetCounter(&timerConfig[timer_num].timerdef);
137
   return __HAL_TIM_GetCounter(&timerConfig[timer_num].timerdef);
138
 }
138
 }
139
 
139
 
140
-void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_us) {
141
-  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_us * HAL_TICKS_PER_US;
140
+void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
141
+  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
142
   if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
142
   if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
143
 }
143
 }
144
 
144
 

+ 1
- 1
Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h View File

96
 void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare);
96
 void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare);
97
 hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
97
 hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
98
 uint32_t HAL_timer_get_count(const uint8_t timer_num);
98
 uint32_t HAL_timer_get_count(const uint8_t timer_num);
99
-void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_us);
99
+void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks);
100
 
100
 
101
 void HAL_timer_isr_prologue(const uint8_t timer_num);
101
 void HAL_timer_isr_prologue(const uint8_t timer_num);
102
 
102
 

+ 2
- 2
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h View File

105
   return 0;
105
   return 0;
106
 }
106
 }
107
 
107
 
108
-FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_us) {
109
-  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_us * HAL_TICKS_PER_US;
108
+FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
109
+  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
110
   if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
110
   if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
111
 }
111
 }
112
 
112
 

+ 9
- 9
Marlin/src/module/stepper.cpp View File

365
     _NEXT_ISR(ocr_val);
365
     _NEXT_ISR(ocr_val);
366
 
366
 
367
     #if DISABLED(LIN_ADVANCE)
367
     #if DISABLED(LIN_ADVANCE)
368
-      HAL_timer_restrain(STEP_TIMER_NUM, STEP_TIMER_MIN_INTERVAL);
369
-      HAL_ENABLE_ISRs(); // re-enable ISRs
368
+      HAL_timer_restrain(STEP_TIMER_NUM, STEP_TIMER_MIN_INTERVAL * HAL_TICKS_PER_US);
369
+      HAL_ENABLE_ISRs();
370
     #endif
370
     #endif
371
 
371
 
372
     return;
372
     return;
419
         if (current_block->steps[Z_AXIS] > 0) {
419
         if (current_block->steps[Z_AXIS] > 0) {
420
           enable_Z();
420
           enable_Z();
421
           _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 1000); // Run at slow speed - 1 KHz
421
           _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 1000); // Run at slow speed - 1 KHz
422
-          HAL_ENABLE_ISRs(); // re-enable ISRs
422
+          HAL_ENABLE_ISRs();
423
           return;
423
           return;
424
         }
424
         }
425
       #endif
425
       #endif
426
     }
426
     }
427
     else {
427
     else {
428
       _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 1000); // Run at slow speed - 1 KHz
428
       _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 1000); // Run at slow speed - 1 KHz
429
-      HAL_ENABLE_ISRs(); // re-enable ISRs
429
+      HAL_ENABLE_ISRs();
430
       return;
430
       return;
431
     }
431
     }
432
   }
432
   }
727
   }
727
   }
728
 
728
 
729
   #if DISABLED(LIN_ADVANCE)
729
   #if DISABLED(LIN_ADVANCE)
730
-    HAL_timer_restrain(STEP_TIMER_NUM, STEP_TIMER_MIN_INTERVAL);
730
+    // Make sure stepper ISR doesn't monopolize the CPU
731
+    HAL_timer_restrain(STEP_TIMER_NUM, STEP_TIMER_MIN_INTERVAL * HAL_TICKS_PER_US);
731
   #endif
732
   #endif
732
 
733
 
733
   // If current block is finished, reset pointer
734
   // If current block is finished, reset pointer
736
     planner.discard_current_block();
737
     planner.discard_current_block();
737
   }
738
   }
738
   #if DISABLED(LIN_ADVANCE)
739
   #if DISABLED(LIN_ADVANCE)
739
-    HAL_ENABLE_ISRs(); // re-enable ISRs
740
+    HAL_ENABLE_ISRs();
740
   #endif
741
   #endif
741
 }
742
 }
742
 
743
 
889
       nextMainISR = 0;
890
       nextMainISR = 0;
890
     }
891
     }
891
 
892
 
892
-    // Don't run the ISR faster than possible
893
-    // Make sure stepper interrupt does not monopolise CPU by adjusting compare to give about 8µs room
894
-    HAL_timer_restrain(STEP_TIMER_NUM, STEP_TIMER_MIN_INTERVAL);
893
+    // Make sure stepper ISR doesn't monopolize the CPU
894
+    HAL_timer_restrain(STEP_TIMER_NUM, STEP_TIMER_MIN_INTERVAL * HAL_TICKS_PER_US);
895
 
895
 
896
     // Restore original ISR settings
896
     // Restore original ISR settings
897
     HAL_ENABLE_ISRs();
897
     HAL_ENABLE_ISRs();

Loading…
Cancel
Save