From ac368f27887a4ab423a0103dc85d9268b3b7e00c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 11 Jan 2018 20:59:16 -0600 Subject: [PATCH] Add STEPPER_ISR_ENABLED() to HALs Some also get a `HAL_timer_interrupt_enabled` function. --- Marlin/src/HAL/HAL_AVR/HAL_AVR.h | 1 + Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp | 13 +++++++++---- Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h | 12 +++++++----- Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp | 8 ++++++++ Marlin/src/HAL/HAL_LPC1768/HAL_timers.h | 3 +++ Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp | 14 +++++++++++--- Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h | 10 +++++----- .../src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp | 8 ++++++++ Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h | 4 +++- 9 files changed, 55 insertions(+), 18 deletions(-) diff --git a/Marlin/src/HAL/HAL_AVR/HAL_AVR.h b/Marlin/src/HAL/HAL_AVR/HAL_AVR.h index 8ea43c815..c3b7403e3 100644 --- a/Marlin/src/HAL/HAL_AVR/HAL_AVR.h +++ b/Marlin/src/HAL/HAL_AVR/HAL_AVR.h @@ -139,6 +139,7 @@ extern "C" { #define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A) #define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A) +#define STEPPER_ISR_ENABLED() TEST(TIMSK1, OCIE1A) #define ENABLE_TEMPERATURE_INTERRUPT() SBI(TIMSK0, OCIE0B) #define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B) diff --git a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp b/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp index dbeb28541..a604f6806 100644 --- a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp +++ b/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp @@ -112,23 +112,28 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { } void HAL_timer_enable_interrupt(const uint8_t timer_num) { - const tTimerConfig *pConfig = &TimerConfig[timer_num]; + const tTimerConfig * const pConfig = &TimerConfig[timer_num]; pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IER = TC_IER_CPCS; } void HAL_timer_disable_interrupt(const uint8_t timer_num) { - const tTimerConfig *pConfig = &TimerConfig[timer_num]; + const tTimerConfig * const pConfig = &TimerConfig[timer_num]; pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IDR = TC_IDR_CPCS; } +void HAL_timer_interrupt_enabled(const uint8_t timer_num) { + const tTimerConfig * const pConfig = &TimerConfig[timer_num]; + return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IER == TC_IER_CPCS; +} + #if 0 void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) { - const tTimerConfig *pConfig = &TimerConfig[timer_num]; + const tTimerConfig * const pConfig = &TimerConfig[timer_num]; TC_SetRC(pConfig->pTimerRegs, pConfig->channel, count); } void HAL_timer_isr_prologue(const uint8_t timer_num) { - const tTimerConfig *pConfig = &TimerConfig[timer_num]; + const tTimerConfig * const pConfig = &TimerConfig[timer_num]; TC_GetStatus(pConfig->pTimerRegs, pConfig->channel); } #endif diff --git a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h b/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h index b93e80b7d..d4d4a6e51 100644 --- a/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h +++ b/Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h @@ -55,6 +55,7 @@ typedef uint32_t hal_timer_t; #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM) #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM) +#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM) #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM) #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM) @@ -91,32 +92,33 @@ extern const tTimerConfig TimerConfig[]; void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) { - const tTimerConfig *pConfig = &TimerConfig[timer_num]; + const tTimerConfig * const pConfig = &TimerConfig[timer_num]; pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count; } FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) { - const tTimerConfig *pConfig = &TimerConfig[timer_num]; + const tTimerConfig * const pConfig = &TimerConfig[timer_num]; return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC; } FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) { - const tTimerConfig *pConfig = &TimerConfig[timer_num]; + const tTimerConfig * const pConfig = &TimerConfig[timer_num]; pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV = count; } FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) { - const tTimerConfig *pConfig = &TimerConfig[timer_num]; + const tTimerConfig * const pConfig = &TimerConfig[timer_num]; return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV; } void HAL_timer_enable_interrupt(const uint8_t timer_num); void HAL_timer_disable_interrupt(const uint8_t timer_num); +bool HAL_timer_interrupt_enabled(const uint8_t timer_num); //void HAL_timer_isr_prologue(const uint8_t timer_num); FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) { - const tTimerConfig *pConfig = &TimerConfig[timer_num]; + const tTimerConfig * const pConfig = &TimerConfig[timer_num]; // Reading the status register clears the interrupt flag pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_SR; } diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp b/Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp index c9e25693e..3f7507aa5 100644 --- a/Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp @@ -75,6 +75,14 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) { } } +bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { + switch (timer_num) { + case 0: return NVIC_GetActive(TIMER0_IRQn); + case 1: return NVIC_GetActive(TIMER1_IRQn); + } + return false; +} + void HAL_timer_isr_prologue(const uint8_t timer_num) { switch (timer_num) { case 0: SBI(LPC_TIM0->IR, 0); break; // Clear the Interrupt diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL_timers.h b/Marlin/src/HAL/HAL_LPC1768/HAL_timers.h index 34b3b24b9..8b4c222af 100644 --- a/Marlin/src/HAL/HAL_LPC1768/HAL_timers.h +++ b/Marlin/src/HAL/HAL_LPC1768/HAL_timers.h @@ -58,6 +58,8 @@ typedef uint32_t hal_timer_t; #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM) #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM) +#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM) + #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM) #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM) @@ -125,6 +127,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_ void HAL_timer_enable_interrupt(const uint8_t timer_num); void HAL_timer_disable_interrupt(const uint8_t timer_num); +bool HAL_timer_interrupt_enabled(const uint8_t timer_num); void HAL_timer_isr_prologue(const uint8_t timer_num); #endif // _HAL_TIMERS_DUE_H diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp index 45ed20df1..0d64e86f5 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp @@ -93,7 +93,7 @@ const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = { * TODO: Calculate Timer prescale value, so we get the 32bit to adjust */ -void HAL_timer_start(uint8_t timer_num, uint32_t frequency) { +void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { nvic_irq_num irq_num; switch (timer_num) { case 1: irq_num = NVIC_TIMER1_CC; break; @@ -135,7 +135,7 @@ void HAL_timer_start(uint8_t timer_num, uint32_t frequency) { } } -void HAL_timer_enable_interrupt(uint8_t timer_num) { +void HAL_timer_enable_interrupt(const uint8_t timer_num) { switch (timer_num) { case STEP_TIMER_NUM: timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN); @@ -148,7 +148,7 @@ void HAL_timer_enable_interrupt(uint8_t timer_num) { } } -void HAL_timer_disable_interrupt(uint8_t timer_num) { +void HAL_timer_disable_interrupt(const uint8_t timer_num) { switch (timer_num) { case STEP_TIMER_NUM: timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN); @@ -161,4 +161,12 @@ void HAL_timer_disable_interrupt(uint8_t timer_num) { } } +bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { + switch (timer_num) { + case STEP_TIMER_NUM: return bool(TIM_DIER(STEP_TIMER_DEV) & STEP_TIMER_CHAN); + case TEMP_TIMER_NUM: return bool(TIM_DIER(TEMP_TIMER_DEV) & TEMP_TIMER_CHAN); + } + return false; +} + #endif // __STM32F1__ diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h index bdc083e2a..79c9408ca 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h @@ -62,8 +62,6 @@ typedef uint16_t hal_timer_t; #define STEP_TIMER_DEV TIMER_DEV(STEP_TIMER_NUM) #define TEMP_TIMER_DEV TIMER_DEV(TEMP_TIMER_NUM) - - //STM32_HAVE_TIMER(n); #define HAL_TIMER_RATE (F_CPU) // frequency of timers peripherals @@ -79,6 +77,7 @@ typedef uint16_t hal_timer_t; #define ENABLE_STEPPER_DRIVER_INTERRUPT() timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN) #define DISABLE_STEPPER_DRIVER_INTERRUPT() timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN) +#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM) #define ENABLE_TEMPERATURE_INTERRUPT() timer_enable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN) #define DISABLE_TEMPERATURE_INTERRUPT() timer_disable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN) @@ -113,9 +112,10 @@ static HardwareTimer TempTimer(TEMP_TIMER_NUM); // Public functions // -------------------------------------------------------------------------- -void HAL_timer_start(uint8_t timer_num, uint32_t frequency); -void HAL_timer_enable_interrupt(uint8_t timer_num); -void HAL_timer_disable_interrupt(uint8_t timer_num); +void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); +void HAL_timer_enable_interrupt(const uint8_t timer_num); +void HAL_timer_disable_interrupt(const uint8_t timer_num); +bool HAL_timer_interrupt_enabled(const uint8_t timer_num); /** * NOTE: By default libmaple sets ARPE = 1, which means the Auto reload register is preloaded (will only update with an update event) diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp index 6a2d39234..03bf9dadd 100644 --- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp +++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp @@ -67,6 +67,14 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) { } } +bool HAL_timer_interrupt_enabled(const uint8_t timer_num) { + switch (timer_num) { + case 0: return NVIC_IS_ENABLED(IRQ_FTM0); + case 1: return NVIC_IS_ENABLED(IRQ_FTM1); + } + return false; +} + void HAL_timer_isr_prologue(const uint8_t timer_num) { switch(timer_num) { case 0: 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 3675ea60b..9482bee5b 100644 --- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h +++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h @@ -68,6 +68,8 @@ typedef uint32_t hal_timer_t; #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM) #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM) +#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM) + #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM) #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM) @@ -110,8 +112,8 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_ void HAL_timer_enable_interrupt(const uint8_t timer_num); void HAL_timer_disable_interrupt(const uint8_t timer_num); +bool HAL_timer_interrupt_enabled(const uint8_t timer_num); void HAL_timer_isr_prologue(const uint8_t timer_num); #endif // _HAL_TIMERS_TEENSY_H -