|
@@ -51,7 +51,6 @@ typedef uint16_t hal_timer_t;
|
51
|
51
|
#define TEMP_TIMER_NUM 2 // index of timer to use for temperature
|
52
|
52
|
#define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
|
53
|
53
|
|
54
|
|
-
|
55
|
54
|
#define HAL_TIMER_RATE (F_CPU) // frequency of timers peripherals
|
56
|
55
|
#define STEPPER_TIMER_PRESCALE 36 // prescaler for setting stepper timer, 2Mhz
|
57
|
56
|
#define HAL_STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
|
|
@@ -60,11 +59,11 @@ typedef uint16_t hal_timer_t;
|
60
|
59
|
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
|
61
|
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
|
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
|
69
|
// TODO change this
|
|
@@ -92,7 +91,7 @@ static HardwareTimer TempTimer(TEMP_TIMER_NUM);
|
92
|
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
|
95
|
void HAL_timer_enable_interrupt(uint8_t timer_num);
|
97
|
96
|
void HAL_timer_disable_interrupt(uint8_t timer_num);
|
98
|
97
|
|
|
@@ -107,26 +106,26 @@ void HAL_timer_disable_interrupt(uint8_t timer_num);
|
107
|
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
|
110
|
switch (timer_num) {
|
112
|
111
|
case STEP_TIMER_NUM:
|
113
|
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
|
116
|
break;
|
118
|
117
|
case TEMP_TIMER_NUM:
|
119
|
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
|
122
|
break;
|
124
|
123
|
default:
|
125
|
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
|
129
|
hal_timer_t temp;
|
131
|
130
|
switch (timer_num) {
|
132
|
131
|
case STEP_TIMER_NUM:
|
|
@@ -142,7 +141,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count (uint8_t timer_num) {
|
142
|
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
|
145
|
hal_timer_t temp;
|
147
|
146
|
switch (timer_num) {
|
148
|
147
|
case STEP_TIMER_NUM:
|
|
@@ -159,9 +158,9 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(uint8_t 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
|
164
|
switch (timer_num) {
|
166
|
165
|
case STEP_TIMER_NUM:
|
167
|
166
|
StepperTimer.pause();
|