Просмотр исходного кода

Allow setting current timer counter

Scott Lahteine 6 лет назад
Родитель
Сommit
6149b82119

+ 18
- 15
Marlin/src/HAL/HAL_AVR/HAL_AVR.h Просмотреть файл

@@ -100,17 +100,23 @@ 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)
106
-
107 103
 #define HAL_TIMER_RATE          ((F_CPU) / 8)    // i.e., 2MHz or 2.5MHz
104
+#define HAL_TICKS_PER_US        ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
105
+
106
+#define TEMP_TIMER_FREQUENCY    ((F_CPU) / 64.0 / 256.0)
107
+
108 108
 #define HAL_STEPPER_TIMER_RATE  HAL_TIMER_RATE
109 109
 #define STEPPER_TIMER_PRESCALE  8
110
-#define HAL_TICKS_PER_US        ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
111 110
 
112
-#define PULSE_TIMER_NUM         TEMP_TIMER_NUM
111
+#define STEP_TIMER_NUM          1
112
+#define TIMER_OCR_1             OCR1A
113
+#define TIMER_COUNTER_1         TCNT1
114
+
115
+#define TEMP_TIMER_NUM          0
116
+#define TIMER_OCR_0             OCR0A
113 117
 #define TIMER_COUNTER_0         TCNT0
118
+
119
+#define PULSE_TIMER_NUM         TEMP_TIMER_NUM
114 120
 #define PULSE_TIMER_PRESCALE    8
115 121
 
116 122
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
@@ -119,17 +125,14 @@ extern "C" {
119 125
 #define ENABLE_TEMPERATURE_INTERRUPT()  SBI(TIMSK0, OCIE0B)
120 126
 #define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
121 127
 
122
-//void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
123
-#define HAL_timer_start(timer_num,frequency)
124
-
125
-#define HAL_timer_get_count(timer) timer
126
-
127
-//void HAL_timer_set_count(const uint8_t timer_num, const uint16_t count);
128
-#define HAL_timer_set_count(timer, count) timer = (count)
128
+#define HAL_timer_start(timer_num, frequency)
129 129
 
130
-#define HAL_timer_get_current_count(timer) timer
130
+#define _CAT(a, ...) a ## __VA_ARGS__
131
+#define HAL_timer_set_count(timer, count) (_CAT(TIMER_OCR_, timer) = count)
132
+#define HAL_timer_get_count(timer) _CAT(TIMER_OCR_, timer)
133
+#define HAL_timer_set_current_count(timer, count) (_CAT(TIMER_COUNTER_, timer) = count)
134
+#define HAL_timer_get_current_count(timer) _CAT(TIMER_COUNTER_, timer)
131 135
 
132
-//void HAL_timer_isr_prologue(const uint8_t timer_num);
133 136
 #define HAL_timer_isr_prologue(timer_num)
134 137
 
135 138
 #define HAL_STEP_TIMER_ISR ISR(TIMER1_COMPA_vect)

+ 5
- 0
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h Просмотреть файл

@@ -100,6 +100,11 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
100 100
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
101 101
 }
102 102
 
103
+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
+  pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV = count;
106
+}
107
+
103 108
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
104 109
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
105 110
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;

+ 7
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_timers.h Просмотреть файл

@@ -103,6 +103,13 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
103 103
   return 0;
104 104
 }
105 105
 
106
+FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
107
+  switch (timer_num) {
108
+    case 0: LPC_TIM0->TC = count; break;
109
+    case 1: LPC_TIM1->TC = count; break;
110
+  }
111
+}
112
+
106 113
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
107 114
   switch (timer_num) {
108 115
     case 0: return LPC_TIM0->TC;

+ 7
- 1
Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h Просмотреть файл

@@ -144,6 +144,13 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
144 144
   return temp;
145 145
 }
146 146
 
147
+FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
148
+  switch (timer_num) {
149
+    case STEP_TIMER_NUM: StepperTimer.setCount(count); break;
150
+    case TEMP_TIMER_NUM: TempTimer.setCount(count); break;
151
+  }
152
+}
153
+
147 154
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
148 155
   hal_timer_t temp;
149 156
   switch (timer_num) {
@@ -160,7 +167,6 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_
160 167
   return temp;
161 168
 }
162 169
 
163
-
164 170
 //void HAL_timer_isr_prologue (const uint8_t timer_num);
165 171
 
166 172
 FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {

+ 7
- 0
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h Просмотреть файл

@@ -93,6 +93,13 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
93 93
   return 0;
94 94
 }
95 95
 
96
+FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
97
+  switch (timer_num) {
98
+    case 0: FTM0_CNT = count;
99
+    case 1: FTM1_CNT = count;
100
+  }
101
+}
102
+
96 103
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
97 104
   switch (timer_num) {
98 105
     case 0: return FTM0_CNT;

Загрузка…
Отмена
Сохранить