Browse Source

General cleanup HAL timers

pull/1/head
Scott Lahteine 7 years ago
parent
commit
b8bc965414
  1. 4
      Marlin/src/HAL/HAL_AVR/HAL_AVR.h
  2. 4
      Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h
  3. 11
      Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h
  4. 4
      Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h
  5. 3
      Marlin/src/core/macros.h

4
Marlin/src/HAL/HAL_AVR/HAL_AVR.h

@ -106,7 +106,7 @@ extern "C" {
#define HAL_TIMER_RATE ((F_CPU) / 8) // i.e., 2MHz or 2.5MHz
#define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE
#define STEPPER_TIMER_PRESCALE INT0_PRESCALER
#define STEPPER_TIMER_PRESCALE 8
#define HAL_TICKS_PER_US ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
@ -118,6 +118,8 @@ extern "C" {
//void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
#define HAL_timer_start(timer_num,frequency)
#define HAL_timer_get_count(timer) timer
//void HAL_timer_set_count(const uint8_t timer_num, const uint16_t count);
#define HAL_timer_set_count(timer, count) timer = (count)

4
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h

@ -87,7 +87,7 @@ extern const tTimerConfig TimerConfig[];
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
const tTimerConfig *pConfig = &TimerConfig[timer_num];
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
}
@ -97,7 +97,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
}
FORCE_INLINE static uint32_t HAL_timer_get_current_count(const uint8_t timer_num) {
FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
const tTimerConfig *pConfig = &TimerConfig[timer_num];
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
}

11
Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h

@ -51,7 +51,6 @@ typedef uint16_t hal_timer_t;
#define TEMP_TIMER_NUM 2 // index of timer to use for temperature
#define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
#define HAL_TIMER_RATE (F_CPU) // frequency of timers peripherals
#define STEPPER_TIMER_PRESCALE 36 // prescaler for setting stepper timer, 2Mhz
#define HAL_STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
@ -107,7 +106,7 @@ void HAL_timer_disable_interrupt(uint8_t timer_num);
* Todo: Look at that possibility later.
*/
FORCE_INLINE static void HAL_timer_set_count (uint8_t timer_num, uint32_t count) {
FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
switch (timer_num) {
case STEP_TIMER_NUM:
StepperTimer.pause();
@ -126,7 +125,7 @@ FORCE_INLINE static void HAL_timer_set_count (uint8_t timer_num, uint32_t count)
}
}
FORCE_INLINE static hal_timer_t HAL_timer_get_count (uint8_t timer_num) {
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
hal_timer_t temp;
switch (timer_num) {
case STEP_TIMER_NUM:
@ -142,7 +141,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count (uint8_t timer_num) {
return temp;
}
FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(uint8_t timer_num) {
FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
hal_timer_t temp;
switch (timer_num) {
case STEP_TIMER_NUM:
@ -159,9 +158,9 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(uint8_t timer_num) {
}
//void HAL_timer_isr_prologue (uint8_t timer_num);
//void HAL_timer_isr_prologue (const uint8_t timer_num);
FORCE_INLINE static void HAL_timer_isr_prologue(uint8_t timer_num) {
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
switch (timer_num) {
case STEP_TIMER_NUM:
StepperTimer.pause();

4
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h

@ -75,7 +75,7 @@ typedef uint32_t hal_timer_t;
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
switch (timer_num) {
case 0: FTM0_C0V = count; break;
case 1: FTM1_C0V = count; break;
@ -90,7 +90,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
return 0;
}
FORCE_INLINE static uint32_t HAL_timer_get_current_count(const uint8_t timer_num) {
FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
switch (timer_num) {
case 0: return FTM0_CNT;
case 1: return FTM1_CNT;

3
Marlin/src/core/macros.h

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

Loading…
Cancel
Save