Skip to content
Snippets Groups Projects
Commit b8bc9654 authored by Scott Lahteine's avatar Scott Lahteine
Browse files

General cleanup HAL timers

parent 69d49a24
Branches
Tags
No related merge requests found
...@@ -106,7 +106,7 @@ extern "C" { ...@@ -106,7 +106,7 @@ extern "C" {
#define HAL_TIMER_RATE ((F_CPU) / 8) // i.e., 2MHz or 2.5MHz #define HAL_TIMER_RATE ((F_CPU) / 8) // i.e., 2MHz or 2.5MHz
#define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE #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 HAL_TICKS_PER_US ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A) #define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
...@@ -118,6 +118,8 @@ extern "C" { ...@@ -118,6 +118,8 @@ extern "C" {
//void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); //void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
#define HAL_timer_start(timer_num,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); //void HAL_timer_set_count(const uint8_t timer_num, const uint16_t count);
#define HAL_timer_set_count(timer, count) timer = (count) #define HAL_timer_set_count(timer, count) timer = (count)
... ...
......
...@@ -87,7 +87,7 @@ extern const tTimerConfig TimerConfig[]; ...@@ -87,7 +87,7 @@ extern const tTimerConfig TimerConfig[];
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); 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]; const tTimerConfig *pConfig = &TimerConfig[timer_num];
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count; 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) { ...@@ -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; 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]; const tTimerConfig *pConfig = &TimerConfig[timer_num];
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV; return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
} }
... ...
......
...@@ -51,7 +51,6 @@ typedef uint16_t hal_timer_t; ...@@ -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_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 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 HAL_TIMER_RATE (F_CPU) // frequency of timers peripherals
#define STEPPER_TIMER_PRESCALE 36 // prescaler for setting stepper timer, 2Mhz #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) #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); ...@@ -107,7 +106,7 @@ void HAL_timer_disable_interrupt(uint8_t timer_num);
* Todo: Look at that possibility later. * 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) { switch (timer_num) {
case STEP_TIMER_NUM: case STEP_TIMER_NUM:
StepperTimer.pause(); StepperTimer.pause();
...@@ -126,7 +125,7 @@ FORCE_INLINE static void HAL_timer_set_count (uint8_t timer_num, uint32_t count) ...@@ -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; hal_timer_t temp;
switch (timer_num) { switch (timer_num) {
case STEP_TIMER_NUM: case STEP_TIMER_NUM:
...@@ -142,7 +141,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count (uint8_t timer_num) { ...@@ -142,7 +141,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count (uint8_t timer_num) {
return temp; 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; hal_timer_t temp;
switch (timer_num) { switch (timer_num) {
case STEP_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) { ...@@ -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) { switch (timer_num) {
case STEP_TIMER_NUM: case STEP_TIMER_NUM:
StepperTimer.pause(); StepperTimer.pause();
... ...
......
...@@ -75,7 +75,7 @@ typedef uint32_t hal_timer_t; ...@@ -75,7 +75,7 @@ typedef uint32_t hal_timer_t;
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); 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) { switch (timer_num) {
case 0: FTM0_C0V = count; break; case 0: FTM0_C0V = count; break;
case 1: FTM1_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) { ...@@ -90,7 +90,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
return 0; 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) { switch (timer_num) {
case 0: return FTM0_CNT; case 0: return FTM0_CNT;
case 1: return FTM1_CNT; case 1: return FTM1_CNT;
... ...
......
...@@ -44,8 +44,7 @@ ...@@ -44,8 +44,7 @@
#define _O3 __attribute__((optimize("O3"))) #define _O3 __attribute__((optimize("O3")))
// Clock speed factors // Clock speed factors
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20 #define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20 on AVR
#define INT0_PRESCALER 8
// Highly granular delays for step pulses, etc. // Highly granular delays for step pulses, etc.
#define DELAY_0_NOP NOOP #define DELAY_0_NOP NOOP
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment