Browse Source

General cleanup HAL timers

Scott Lahteine 6 years ago
parent
commit
b8bc965414

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

@@ -100,13 +100,13 @@ extern "C" {
100 100
 
101 101
 
102 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 107
 #define HAL_TIMER_RATE          ((F_CPU) / 8)    // i.e., 2MHz or 2.5MHz
108 108
 #define HAL_STEPPER_TIMER_RATE  HAL_TIMER_RATE
109
-#define STEPPER_TIMER_PRESCALE  INT0_PRESCALER
109
+#define STEPPER_TIMER_PRESCALE  8
110 110
 #define HAL_TICKS_PER_US        ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
111 111
 
112 112
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
@@ -118,6 +118,8 @@ extern "C" {
118 118
 //void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
119 119
 #define HAL_timer_start(timer_num,frequency)
120 120
 
121
+#define HAL_timer_get_count(timer) timer
122
+
121 123
 //void HAL_timer_set_count(const uint8_t timer_num, const uint16_t count);
122 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,7 +87,7 @@ extern const tTimerConfig TimerConfig[];
87 87
 
88 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 91
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
92 92
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
93 93
 }
@@ -97,7 +97,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
97 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 101
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
102 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,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();

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

@@ -75,23 +75,23 @@ typedef uint32_t hal_timer_t;
75 75
 
76 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 80
     case 0: FTM0_C0V = count; break;
81 81
     case 1: FTM1_C0V = count; break;
82 82
   }
83 83
 }
84 84
 
85 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 87
     case 0: return FTM0_C0V;
88 88
     case 1: return FTM1_C0V;
89 89
   }
90 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 95
     case 0: return FTM0_CNT;
96 96
     case 1: return FTM1_CNT;
97 97
   }

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

@@ -44,8 +44,7 @@
44 44
 #define _O3          __attribute__((optimize("O3")))
45 45
 
46 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 49
 // Highly granular delays for step pulses, etc.
51 50
 #define DELAY_0_NOP NOOP

Loading…
Cancel
Save