Browse Source

Add STEPPER_ISR_ENABLED() to HALs

Some also get a `HAL_timer_interrupt_enabled` function.
Scott Lahteine 7 years ago
parent
commit
ac368f2788

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

139
 
139
 
140
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
140
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
141
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
141
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
142
+#define STEPPER_ISR_ENABLED() TEST(TIMSK1, OCIE1A)
142
 
143
 
143
 #define ENABLE_TEMPERATURE_INTERRUPT()  SBI(TIMSK0, OCIE0B)
144
 #define ENABLE_TEMPERATURE_INTERRUPT()  SBI(TIMSK0, OCIE0B)
144
 #define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
145
 #define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)

+ 9
- 4
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp View File

112
 }
112
 }
113
 
113
 
114
 void HAL_timer_enable_interrupt(const uint8_t timer_num) {
114
 void HAL_timer_enable_interrupt(const uint8_t timer_num) {
115
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
115
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
116
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IER = TC_IER_CPCS;
116
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IER = TC_IER_CPCS;
117
 }
117
 }
118
 
118
 
119
 void HAL_timer_disable_interrupt(const uint8_t timer_num) {
119
 void HAL_timer_disable_interrupt(const uint8_t timer_num) {
120
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
120
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
121
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IDR = TC_IDR_CPCS;
121
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IDR = TC_IDR_CPCS;
122
 }
122
 }
123
 
123
 
124
+void HAL_timer_interrupt_enabled(const uint8_t timer_num) {
125
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
126
+  return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IER == TC_IER_CPCS;
127
+}
128
+
124
 #if 0
129
 #if 0
125
   void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
130
   void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
126
-    const tTimerConfig *pConfig = &TimerConfig[timer_num];
131
+    const tTimerConfig * const pConfig = &TimerConfig[timer_num];
127
     TC_SetRC(pConfig->pTimerRegs, pConfig->channel, count);
132
     TC_SetRC(pConfig->pTimerRegs, pConfig->channel, count);
128
   }
133
   }
129
 
134
 
130
   void HAL_timer_isr_prologue(const uint8_t timer_num) {
135
   void HAL_timer_isr_prologue(const uint8_t timer_num) {
131
-    const tTimerConfig *pConfig = &TimerConfig[timer_num];
136
+    const tTimerConfig * const pConfig = &TimerConfig[timer_num];
132
     TC_GetStatus(pConfig->pTimerRegs, pConfig->channel);
137
     TC_GetStatus(pConfig->pTimerRegs, pConfig->channel);
133
   }
138
   }
134
 #endif
139
 #endif

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

55
 
55
 
56
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
56
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
57
 #define DISABLE_STEPPER_DRIVER_INTERRUPT()  HAL_timer_disable_interrupt(STEP_TIMER_NUM)
57
 #define DISABLE_STEPPER_DRIVER_INTERRUPT()  HAL_timer_disable_interrupt(STEP_TIMER_NUM)
58
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
58
 
59
 
59
 #define ENABLE_TEMPERATURE_INTERRUPT()  HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
60
 #define ENABLE_TEMPERATURE_INTERRUPT()  HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
60
 #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
61
 #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
91
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
92
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
92
 
93
 
93
 FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
94
 FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
94
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
95
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
95
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
96
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
96
 }
97
 }
97
 
98
 
98
 FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
99
 FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
99
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
100
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
100
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
101
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
101
 }
102
 }
102
 
103
 
103
 FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
104
 FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
104
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
105
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
105
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV = count;
106
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV = count;
106
 }
107
 }
107
 
108
 
108
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
109
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
109
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
110
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
110
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
111
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
111
 }
112
 }
112
 
113
 
113
 void HAL_timer_enable_interrupt(const uint8_t timer_num);
114
 void HAL_timer_enable_interrupt(const uint8_t timer_num);
114
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
115
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
116
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
115
 
117
 
116
 //void HAL_timer_isr_prologue(const uint8_t timer_num);
118
 //void HAL_timer_isr_prologue(const uint8_t timer_num);
117
 
119
 
118
 FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
120
 FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
119
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
121
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
120
   // Reading the status register clears the interrupt flag
122
   // Reading the status register clears the interrupt flag
121
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_SR;
123
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_SR;
122
 }
124
 }

+ 8
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp View File

75
   }
75
   }
76
 }
76
 }
77
 
77
 
78
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
79
+  switch (timer_num) {
80
+    case 0: return NVIC_GetActive(TIMER0_IRQn);
81
+    case 1: return NVIC_GetActive(TIMER1_IRQn);
82
+  }
83
+  return false;
84
+}
85
+
78
 void HAL_timer_isr_prologue(const uint8_t timer_num) {
86
 void HAL_timer_isr_prologue(const uint8_t timer_num) {
79
   switch (timer_num) {
87
   switch (timer_num) {
80
     case 0: SBI(LPC_TIM0->IR, 0); break; // Clear the Interrupt
88
     case 0: SBI(LPC_TIM0->IR, 0); break; // Clear the Interrupt

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

58
 
58
 
59
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
59
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
60
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
60
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
61
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
62
+
61
 #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
63
 #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
62
 #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
64
 #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
63
 
65
 
125
 
127
 
126
 void HAL_timer_enable_interrupt(const uint8_t timer_num);
128
 void HAL_timer_enable_interrupt(const uint8_t timer_num);
127
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
129
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
130
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
128
 void HAL_timer_isr_prologue(const uint8_t timer_num);
131
 void HAL_timer_isr_prologue(const uint8_t timer_num);
129
 
132
 
130
 #endif // _HAL_TIMERS_DUE_H
133
 #endif // _HAL_TIMERS_DUE_H

+ 11
- 3
Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp View File

93
  * TODO: Calculate Timer prescale value, so we get the 32bit to adjust
93
  * TODO: Calculate Timer prescale value, so we get the 32bit to adjust
94
  */
94
  */
95
 
95
 
96
-void HAL_timer_start(uint8_t timer_num, uint32_t frequency) {
96
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
97
   nvic_irq_num irq_num;
97
   nvic_irq_num irq_num;
98
   switch (timer_num) {
98
   switch (timer_num) {
99
     case 1: irq_num = NVIC_TIMER1_CC; break;
99
     case 1: irq_num = NVIC_TIMER1_CC; break;
135
   }
135
   }
136
 }
136
 }
137
 
137
 
138
-void HAL_timer_enable_interrupt(uint8_t timer_num) {
138
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
139
   switch (timer_num) {
139
   switch (timer_num) {
140
     case STEP_TIMER_NUM:
140
     case STEP_TIMER_NUM:
141
       timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN);
141
       timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN);
148
   }
148
   }
149
 }
149
 }
150
 
150
 
151
-void HAL_timer_disable_interrupt(uint8_t timer_num) {
151
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
152
   switch (timer_num) {
152
   switch (timer_num) {
153
     case STEP_TIMER_NUM:
153
     case STEP_TIMER_NUM:
154
       timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN);
154
       timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN);
161
   }
161
   }
162
 }
162
 }
163
 
163
 
164
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
165
+  switch (timer_num) {
166
+    case STEP_TIMER_NUM: return bool(TIM_DIER(STEP_TIMER_DEV) & STEP_TIMER_CHAN);
167
+    case TEMP_TIMER_NUM: return bool(TIM_DIER(TEMP_TIMER_DEV) & TEMP_TIMER_CHAN);
168
+  }
169
+  return false;
170
+}
171
+
164
 #endif // __STM32F1__
172
 #endif // __STM32F1__

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

62
 #define STEP_TIMER_DEV TIMER_DEV(STEP_TIMER_NUM)
62
 #define STEP_TIMER_DEV TIMER_DEV(STEP_TIMER_NUM)
63
 #define TEMP_TIMER_DEV TIMER_DEV(TEMP_TIMER_NUM)
63
 #define TEMP_TIMER_DEV TIMER_DEV(TEMP_TIMER_NUM)
64
 
64
 
65
-
66
-
67
 //STM32_HAVE_TIMER(n);
65
 //STM32_HAVE_TIMER(n);
68
 
66
 
69
 #define HAL_TIMER_RATE         (F_CPU)  // frequency of timers peripherals
67
 #define HAL_TIMER_RATE         (F_CPU)  // frequency of timers peripherals
79
 
77
 
80
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN)
78
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN)
81
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN)
79
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN)
80
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
82
 
81
 
83
 #define ENABLE_TEMPERATURE_INTERRUPT() timer_enable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
82
 #define ENABLE_TEMPERATURE_INTERRUPT() timer_enable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
84
 #define DISABLE_TEMPERATURE_INTERRUPT() timer_disable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
83
 #define DISABLE_TEMPERATURE_INTERRUPT() timer_disable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
113
 // Public functions
112
 // Public functions
114
 // --------------------------------------------------------------------------
113
 // --------------------------------------------------------------------------
115
 
114
 
116
-void HAL_timer_start(uint8_t timer_num, uint32_t frequency);
117
-void HAL_timer_enable_interrupt(uint8_t timer_num);
118
-void HAL_timer_disable_interrupt(uint8_t timer_num);
115
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
116
+void HAL_timer_enable_interrupt(const uint8_t timer_num);
117
+void HAL_timer_disable_interrupt(const uint8_t timer_num);
118
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
119
 
119
 
120
 /**
120
 /**
121
  * NOTE: By default libmaple sets ARPE = 1, which means the Auto reload register is preloaded (will only update with an update event)
121
  * NOTE: By default libmaple sets ARPE = 1, which means the Auto reload register is preloaded (will only update with an update event)

+ 8
- 0
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp View File

67
   }
67
   }
68
 }
68
 }
69
 
69
 
70
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
71
+  switch (timer_num) {
72
+    case 0: return NVIC_IS_ENABLED(IRQ_FTM0);
73
+    case 1: return NVIC_IS_ENABLED(IRQ_FTM1);
74
+  }
75
+  return false;
76
+}
77
+
70
 void HAL_timer_isr_prologue(const uint8_t timer_num) {
78
 void HAL_timer_isr_prologue(const uint8_t timer_num) {
71
   switch(timer_num) {
79
   switch(timer_num) {
72
     case 0:
80
     case 0:

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

68
 
68
 
69
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
69
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
70
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
70
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
71
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
72
+
71
 #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
73
 #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
72
 #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
74
 #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
73
 
75
 
110
 
112
 
111
 void HAL_timer_enable_interrupt(const uint8_t timer_num);
113
 void HAL_timer_enable_interrupt(const uint8_t timer_num);
112
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
114
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
115
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
113
 
116
 
114
 void HAL_timer_isr_prologue(const uint8_t timer_num);
117
 void HAL_timer_isr_prologue(const uint8_t timer_num);
115
 
118
 
116
 #endif // _HAL_TIMERS_TEENSY_H
119
 #endif // _HAL_TIMERS_TEENSY_H
117
-

Loading…
Cancel
Save