Browse Source

General cleanup HAL timers

Scott Lahteine 7 years ago
parent
commit
b8bc965414

+ 6
- 4
Marlin/src/HAL/HAL_AVR/HAL_AVR.h View File

100
 
100
 
101
 
101
 
102
 // timers
102
 // timers
103
-#define STEP_TIMER_NUM OCR1A
104
-#define TEMP_TIMER_NUM 0
105
-#define TEMP_TIMER_FREQUENCY (F_CPU / 64.0 / 256.0)
103
+#define STEP_TIMER_NUM          OCR1A
104
+#define TEMP_TIMER_NUM          0
105
+#define TEMP_TIMER_FREQUENCY    (F_CPU / 64.0 / 256.0)
106
 
106
 
107
 #define HAL_TIMER_RATE          ((F_CPU) / 8)    // i.e., 2MHz or 2.5MHz
107
 #define HAL_TIMER_RATE          ((F_CPU) / 8)    // i.e., 2MHz or 2.5MHz
108
 #define HAL_STEPPER_TIMER_RATE  HAL_TIMER_RATE
108
 #define HAL_STEPPER_TIMER_RATE  HAL_TIMER_RATE
109
-#define STEPPER_TIMER_PRESCALE  INT0_PRESCALER
109
+#define STEPPER_TIMER_PRESCALE  8
110
 #define HAL_TICKS_PER_US        ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
110
 #define HAL_TICKS_PER_US        ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
111
 
111
 
112
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
112
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
118
 //void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
118
 //void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
119
 #define HAL_timer_start(timer_num,frequency)
119
 #define HAL_timer_start(timer_num,frequency)
120
 
120
 
121
+#define HAL_timer_get_count(timer) timer
122
+
121
 //void HAL_timer_set_count(const uint8_t timer_num, const uint16_t count);
123
 //void HAL_timer_set_count(const uint8_t timer_num, const uint16_t count);
122
 #define HAL_timer_set_count(timer, count) timer = (count)
124
 #define HAL_timer_set_count(timer, count) timer = (count)
123
 
125
 

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

87
 
87
 
88
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
88
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
89
 
89
 
90
-FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
90
+FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
91
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
91
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
92
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
92
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
93
 }
93
 }
97
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
97
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
98
 }
98
 }
99
 
99
 
100
-FORCE_INLINE static uint32_t HAL_timer_get_current_count(const uint8_t timer_num) {
100
+FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
101
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
101
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
102
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
102
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
103
 }
103
 }

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

51
 #define TEMP_TIMER_NUM 2  // index of timer to use for temperature
51
 #define TEMP_TIMER_NUM 2  // index of timer to use for temperature
52
 #define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
52
 #define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
53
 
53
 
54
-
55
 #define HAL_TIMER_RATE         (F_CPU)  // frequency of timers peripherals
54
 #define HAL_TIMER_RATE         (F_CPU)  // frequency of timers peripherals
56
 #define STEPPER_TIMER_PRESCALE 36             // prescaler for setting stepper timer, 2Mhz
55
 #define STEPPER_TIMER_PRESCALE 36             // prescaler for setting stepper timer, 2Mhz
57
 #define HAL_STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
56
 #define HAL_STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
60
 #define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
59
 #define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
61
 #define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
60
 #define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
62
 
61
 
63
-#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt (STEP_TIMER_NUM)
64
-#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt (STEP_TIMER_NUM)
62
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
63
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
65
 
64
 
66
-#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt (TEMP_TIMER_NUM)
67
-#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt (TEMP_TIMER_NUM)
65
+#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
66
+#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
68
 
67
 
69
 #define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
68
 #define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
70
 // TODO change this
69
 // TODO change this
92
 // Public functions
91
 // Public functions
93
 // --------------------------------------------------------------------------
92
 // --------------------------------------------------------------------------
94
 
93
 
95
-void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
94
+void HAL_timer_start(uint8_t timer_num, uint32_t frequency);
96
 void HAL_timer_enable_interrupt(uint8_t timer_num);
95
 void HAL_timer_enable_interrupt(uint8_t timer_num);
97
 void HAL_timer_disable_interrupt(uint8_t timer_num);
96
 void HAL_timer_disable_interrupt(uint8_t timer_num);
98
 
97
 
107
  * Todo: Look at that possibility later.
106
  * Todo: Look at that possibility later.
108
  */
107
  */
109
 
108
 
110
-FORCE_INLINE static void HAL_timer_set_count (uint8_t timer_num, uint32_t count) {
109
+FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
111
   switch (timer_num) {
110
   switch (timer_num) {
112
   case STEP_TIMER_NUM:
111
   case STEP_TIMER_NUM:
113
     StepperTimer.pause();
112
     StepperTimer.pause();
114
-    StepperTimer.setCompare (STEP_TIMER_CHAN, count);
115
-    StepperTimer.refresh ();
116
-    StepperTimer.resume ();
113
+    StepperTimer.setCompare(STEP_TIMER_CHAN, count);
114
+    StepperTimer.refresh();
115
+    StepperTimer.resume();
117
     break;
116
     break;
118
   case TEMP_TIMER_NUM:
117
   case TEMP_TIMER_NUM:
119
     TempTimer.pause();
118
     TempTimer.pause();
120
-    TempTimer.setCompare (TEMP_TIMER_CHAN, count);
121
-    TempTimer.refresh ();
122
-    TempTimer.resume ();
119
+    TempTimer.setCompare(TEMP_TIMER_CHAN, count);
120
+    TempTimer.refresh();
121
+    TempTimer.resume();
123
     break;
122
     break;
124
   default:
123
   default:
125
     break;
124
     break;
126
   }
125
   }
127
 }
126
 }
128
 
127
 
129
-FORCE_INLINE static hal_timer_t HAL_timer_get_count (uint8_t timer_num) {
128
+FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
130
   hal_timer_t temp;
129
   hal_timer_t temp;
131
   switch (timer_num) {
130
   switch (timer_num) {
132
   case STEP_TIMER_NUM:
131
   case STEP_TIMER_NUM:
142
   return temp;
141
   return temp;
143
 }
142
 }
144
 
143
 
145
-FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(uint8_t timer_num) {
144
+FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
146
   hal_timer_t temp;
145
   hal_timer_t temp;
147
   switch (timer_num) {
146
   switch (timer_num) {
148
   case STEP_TIMER_NUM:
147
   case STEP_TIMER_NUM:
159
 }
158
 }
160
 
159
 
161
 
160
 
162
-//void HAL_timer_isr_prologue (uint8_t timer_num);
161
+//void HAL_timer_isr_prologue (const uint8_t timer_num);
163
 
162
 
164
-FORCE_INLINE static void HAL_timer_isr_prologue(uint8_t timer_num) {
163
+FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
165
   switch (timer_num) {
164
   switch (timer_num) {
166
   case STEP_TIMER_NUM:
165
   case STEP_TIMER_NUM:
167
     StepperTimer.pause();
166
     StepperTimer.pause();

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

75
 
75
 
76
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
76
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
77
 
77
 
78
-FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
79
-  switch(timer_num) {
78
+FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
79
+  switch (timer_num) {
80
     case 0: FTM0_C0V = count; break;
80
     case 0: FTM0_C0V = count; break;
81
     case 1: FTM1_C0V = count; break;
81
     case 1: FTM1_C0V = count; break;
82
   }
82
   }
83
 }
83
 }
84
 
84
 
85
 FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
85
 FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
86
-  switch(timer_num) {
86
+  switch (timer_num) {
87
     case 0: return FTM0_C0V;
87
     case 0: return FTM0_C0V;
88
     case 1: return FTM1_C0V;
88
     case 1: return FTM1_C0V;
89
   }
89
   }
90
   return 0;
90
   return 0;
91
 }
91
 }
92
 
92
 
93
-FORCE_INLINE static uint32_t HAL_timer_get_current_count(const uint8_t timer_num) {
94
-  switch(timer_num) {
93
+FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
94
+  switch (timer_num) {
95
     case 0: return FTM0_CNT;
95
     case 0: return FTM0_CNT;
96
     case 1: return FTM1_CNT;
96
     case 1: return FTM1_CNT;
97
   }
97
   }

+ 1
- 2
Marlin/src/core/macros.h View File

44
 #define _O3          __attribute__((optimize("O3")))
44
 #define _O3          __attribute__((optimize("O3")))
45
 
45
 
46
 // Clock speed factors
46
 // Clock speed factors
47
-#define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20
48
-#define INT0_PRESCALER 8
47
+#define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20 on AVR
49
 
48
 
50
 // Highly granular delays for step pulses, etc.
49
 // Highly granular delays for step pulses, etc.
51
 #define DELAY_0_NOP NOOP
50
 #define DELAY_0_NOP NOOP

Loading…
Cancel
Save