General cleanup HAL timers
This commit is contained in:
parent
69d49a2438
commit
b8bc965414
@ -100,13 +100,13 @@ extern "C" {
|
||||
|
||||
|
||||
// timers
|
||||
#define STEP_TIMER_NUM OCR1A
|
||||
#define TEMP_TIMER_NUM 0
|
||||
#define TEMP_TIMER_FREQUENCY (F_CPU / 64.0 / 256.0)
|
||||
#define STEP_TIMER_NUM OCR1A
|
||||
#define TEMP_TIMER_NUM 0
|
||||
#define TEMP_TIMER_FREQUENCY (F_CPU / 64.0 / 256.0)
|
||||
|
||||
#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)
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
@ -60,11 +59,11 @@ typedef uint16_t hal_timer_t;
|
||||
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
|
||||
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
||||
|
||||
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt (STEP_TIMER_NUM)
|
||||
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt (STEP_TIMER_NUM)
|
||||
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
|
||||
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
|
||||
|
||||
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt (TEMP_TIMER_NUM)
|
||||
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt (TEMP_TIMER_NUM)
|
||||
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
|
||||
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
|
||||
|
||||
#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
|
||||
// TODO change this
|
||||
@ -92,7 +91,7 @@ static HardwareTimer TempTimer(TEMP_TIMER_NUM);
|
||||
// Public functions
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
|
||||
void HAL_timer_start(uint8_t timer_num, uint32_t frequency);
|
||||
void HAL_timer_enable_interrupt(uint8_t timer_num);
|
||||
void HAL_timer_disable_interrupt(uint8_t timer_num);
|
||||
|
||||
@ -107,26 +106,26 @@ 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();
|
||||
StepperTimer.setCompare (STEP_TIMER_CHAN, count);
|
||||
StepperTimer.refresh ();
|
||||
StepperTimer.resume ();
|
||||
StepperTimer.setCompare(STEP_TIMER_CHAN, count);
|
||||
StepperTimer.refresh();
|
||||
StepperTimer.resume();
|
||||
break;
|
||||
case TEMP_TIMER_NUM:
|
||||
TempTimer.pause();
|
||||
TempTimer.setCompare (TEMP_TIMER_CHAN, count);
|
||||
TempTimer.refresh ();
|
||||
TempTimer.resume ();
|
||||
TempTimer.setCompare(TEMP_TIMER_CHAN, count);
|
||||
TempTimer.refresh();
|
||||
TempTimer.resume();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
@ -75,23 +75,23 @@ 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) {
|
||||
switch(timer_num) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
switch(timer_num) {
|
||||
switch (timer_num) {
|
||||
case 0: return FTM0_C0V;
|
||||
case 1: return FTM1_C0V;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
FORCE_INLINE static uint32_t HAL_timer_get_current_count(const uint8_t timer_num) {
|
||||
switch(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;
|
||||
}
|
||||
|
@ -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…
Reference in New Issue
Block a user