From 98d48fc7310adeb305ecaae7d025b33533dc9402 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 7 Mar 2018 22:18:13 -0600 Subject: [PATCH] Followup to HAL_timer_restrain Followup to #9985 --- Marlin/src/HAL/HAL_AVR/HAL_AVR.h | 2 +- Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h | 4 ++-- Marlin/src/HAL/HAL_LPC1768/HAL_timers.h | 4 ++-- .../src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h | 4 ++-- .../src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp | 4 ++-- .../src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h | 2 +- .../HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h | 4 ++-- Marlin/src/module/stepper.cpp | 18 +++++++++--------- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Marlin/src/HAL/HAL_AVR/HAL_AVR.h b/Marlin/src/HAL/HAL_AVR/HAL_AVR.h index 0575f407a3..df6e7efe2e 100644 --- a/Marlin/src/HAL/HAL_AVR/HAL_AVR.h +++ b/Marlin/src/HAL/HAL_AVR/HAL_AVR.h @@ -150,7 +150,7 @@ extern "C" { #define _CAT(a, ...) a ## __VA_ARGS__ #define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare) -#define HAL_timer_restrain(timer, interval_us) NOLESS(_CAT(TIMER_OCR_, timer), _CAT(TIMER_COUNTER_, timer) + interval_us * HAL_TICKS_PER_US) +#define HAL_timer_restrain(timer, interval_ticks) NOLESS(_CAT(TIMER_OCR_, timer), _CAT(TIMER_COUNTER_, timer) + interval_ticks) #define HAL_timer_get_compare(timer) _CAT(TIMER_OCR_, timer) #define HAL_timer_get_count(timer) _CAT(TIMER_COUNTER_, timer) diff --git a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h b/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h index 6fd59471e3..b1df3a86dc 100644 --- a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h +++ b/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h @@ -109,8 +109,8 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) { return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV; } -FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_us) { - const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_us * HAL_TICKS_PER_US; +FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) { + const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks; if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp); } diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL_timers.h b/Marlin/src/HAL/HAL_LPC1768/HAL_timers.h index 69fdcce974..ef875edfd8 100644 --- a/Marlin/src/HAL/HAL_LPC1768/HAL_timers.h +++ b/Marlin/src/HAL/HAL_LPC1768/HAL_timers.h @@ -120,8 +120,8 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) { return 0; } -FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_us) { - const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_us * HAL_TICKS_PER_US; +FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) { + const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks; if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp); } diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h index 492385f38d..6c2c6a68c8 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h @@ -154,8 +154,8 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) { } } -FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_us) { - const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_us * HAL_TICKS_PER_US; +FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) { + const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks; if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp); } diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp b/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp index 2589db33d2..3678d33de0 100644 --- a/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp +++ b/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp @@ -137,8 +137,8 @@ uint32_t HAL_timer_get_count(const uint8_t timer_num) { return __HAL_TIM_GetCounter(&timerConfig[timer_num].timerdef); } -void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_us) { - const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_us * HAL_TICKS_PER_US; +void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) { + const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks; if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp); } diff --git a/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h b/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h index 8f1eff9c13..7990614b02 100644 --- a/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h +++ b/Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h @@ -96,7 +96,7 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num); void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare); hal_timer_t HAL_timer_get_compare(const uint8_t timer_num); uint32_t HAL_timer_get_count(const uint8_t timer_num); -void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_us); +void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks); void HAL_timer_isr_prologue(const uint8_t timer_num); diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h index 6e18a66ff2..f9c1509f2a 100644 --- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h +++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h @@ -105,8 +105,8 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) { return 0; } -FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_us) { - const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_us * HAL_TICKS_PER_US; +FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) { + const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks; if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp); } diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 9da2c036cf..fe3e39638d 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -365,8 +365,8 @@ void Stepper::isr() { _NEXT_ISR(ocr_val); #if DISABLED(LIN_ADVANCE) - HAL_timer_restrain(STEP_TIMER_NUM, STEP_TIMER_MIN_INTERVAL); - HAL_ENABLE_ISRs(); // re-enable ISRs + HAL_timer_restrain(STEP_TIMER_NUM, STEP_TIMER_MIN_INTERVAL * HAL_TICKS_PER_US); + HAL_ENABLE_ISRs(); #endif return; @@ -419,14 +419,14 @@ void Stepper::isr() { if (current_block->steps[Z_AXIS] > 0) { enable_Z(); _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 1000); // Run at slow speed - 1 KHz - HAL_ENABLE_ISRs(); // re-enable ISRs + HAL_ENABLE_ISRs(); return; } #endif } else { _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 1000); // Run at slow speed - 1 KHz - HAL_ENABLE_ISRs(); // re-enable ISRs + HAL_ENABLE_ISRs(); return; } } @@ -727,7 +727,8 @@ void Stepper::isr() { } #if DISABLED(LIN_ADVANCE) - HAL_timer_restrain(STEP_TIMER_NUM, STEP_TIMER_MIN_INTERVAL); + // Make sure stepper ISR doesn't monopolize the CPU + HAL_timer_restrain(STEP_TIMER_NUM, STEP_TIMER_MIN_INTERVAL * HAL_TICKS_PER_US); #endif // If current block is finished, reset pointer @@ -736,7 +737,7 @@ void Stepper::isr() { planner.discard_current_block(); } #if DISABLED(LIN_ADVANCE) - HAL_ENABLE_ISRs(); // re-enable ISRs + HAL_ENABLE_ISRs(); #endif } @@ -889,9 +890,8 @@ void Stepper::isr() { nextMainISR = 0; } - // Don't run the ISR faster than possible - // Make sure stepper interrupt does not monopolise CPU by adjusting compare to give about 8µs room - HAL_timer_restrain(STEP_TIMER_NUM, STEP_TIMER_MIN_INTERVAL); + // Make sure stepper ISR doesn't monopolize the CPU + HAL_timer_restrain(STEP_TIMER_NUM, STEP_TIMER_MIN_INTERVAL * HAL_TICKS_PER_US); // Restore original ISR settings HAL_ENABLE_ISRs();