🎨 Rename HAL timer elements
This commit is contained in:
committed by
Scott Lahteine
parent
d75e7784e5
commit
9b1c0a75e1
@ -47,7 +47,7 @@ FORCE_INLINE static void __DSB() {
|
||||
|
||||
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
switch (timer_num) {
|
||||
case 0:
|
||||
case MF_TIMER_STEP:
|
||||
FTM0_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN;
|
||||
FTM0_SC = 0x00; // Set this to zero before changing the modulus
|
||||
FTM0_CNT = 0x0000; // Reset the count to zero
|
||||
@ -56,7 +56,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
FTM0_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM0_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 8
|
||||
FTM0_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
|
||||
break;
|
||||
case 1:
|
||||
case MF_TIMER_TEMP:
|
||||
FTM1_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN; // Disable write protection, Enable FTM1
|
||||
FTM1_SC = 0x00; // Set this to zero before changing the modulus
|
||||
FTM1_CNT = 0x0000; // Reset the count to zero
|
||||
@ -70,15 +70,15 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
|
||||
void HAL_timer_enable_interrupt(const uint8_t timer_num) {
|
||||
switch (timer_num) {
|
||||
case 0: NVIC_ENABLE_IRQ(IRQ_FTM0); break;
|
||||
case 1: NVIC_ENABLE_IRQ(IRQ_FTM1); break;
|
||||
case MF_TIMER_STEP: NVIC_ENABLE_IRQ(IRQ_FTM0); break;
|
||||
case MF_TIMER_TEMP: NVIC_ENABLE_IRQ(IRQ_FTM1); break;
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_timer_disable_interrupt(const uint8_t timer_num) {
|
||||
switch (timer_num) {
|
||||
case 0: NVIC_DISABLE_IRQ(IRQ_FTM0); break;
|
||||
case 1: NVIC_DISABLE_IRQ(IRQ_FTM1); break;
|
||||
case MF_TIMER_STEP: NVIC_DISABLE_IRQ(IRQ_FTM0); break;
|
||||
case MF_TIMER_TEMP: NVIC_DISABLE_IRQ(IRQ_FTM1); break;
|
||||
}
|
||||
|
||||
// We NEED memory barriers to ensure Interrupts are actually disabled!
|
||||
@ -89,20 +89,20 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) {
|
||||
|
||||
bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
|
||||
switch (timer_num) {
|
||||
case 0: return NVIC_IS_ENABLED(IRQ_FTM0);
|
||||
case 1: return NVIC_IS_ENABLED(IRQ_FTM1);
|
||||
case MF_TIMER_STEP: return NVIC_IS_ENABLED(IRQ_FTM0);
|
||||
case MF_TIMER_TEMP: return NVIC_IS_ENABLED(IRQ_FTM1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void HAL_timer_isr_prologue(const uint8_t timer_num) {
|
||||
switch (timer_num) {
|
||||
case 0:
|
||||
case MF_TIMER_STEP:
|
||||
FTM0_CNT = 0x0000;
|
||||
FTM0_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
|
||||
FTM0_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
|
||||
break;
|
||||
case 1:
|
||||
case MF_TIMER_TEMP:
|
||||
FTM1_CNT = 0x0000;
|
||||
FTM1_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
|
||||
FTM1_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
|
||||
|
@ -46,14 +46,14 @@ typedef uint32_t hal_timer_t;
|
||||
|
||||
#define HAL_TIMER_RATE (FTM0_TIMER_RATE)
|
||||
|
||||
#ifndef STEP_TIMER_NUM
|
||||
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
||||
#ifndef MF_TIMER_STEP
|
||||
#define MF_TIMER_STEP 0 // Timer Index for Stepper
|
||||
#endif
|
||||
#ifndef PULSE_TIMER_NUM
|
||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||
#ifndef MF_TIMER_PULSE
|
||||
#define MF_TIMER_PULSE MF_TIMER_STEP
|
||||
#endif
|
||||
#ifndef TEMP_TIMER_NUM
|
||||
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
|
||||
#ifndef MF_TIMER_TEMP
|
||||
#define MF_TIMER_TEMP 1 // Timer Index for Temperature
|
||||
#endif
|
||||
|
||||
#define TEMP_TIMER_FREQUENCY 1000
|
||||
@ -66,12 +66,12 @@ typedef uint32_t hal_timer_t;
|
||||
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
||||
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
|
||||
|
||||
#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 STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
|
||||
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_STEP)
|
||||
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_STEP)
|
||||
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(MF_TIMER_STEP)
|
||||
|
||||
#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(MF_TIMER_TEMP)
|
||||
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_TEMP)
|
||||
|
||||
#ifndef HAL_STEP_TIMER_ISR
|
||||
#define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr() //void TC3_Handler()
|
||||
@ -84,23 +84,23 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
|
||||
|
||||
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
|
||||
switch (timer_num) {
|
||||
case 0: FTM0_C0V = compare; break;
|
||||
case 1: FTM1_C0V = compare; break;
|
||||
case MF_TIMER_STEP: FTM0_C0V = compare; break;
|
||||
case MF_TIMER_TEMP: FTM1_C0V = compare; break;
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
|
||||
switch (timer_num) {
|
||||
case 0: return FTM0_C0V;
|
||||
case 1: return FTM1_C0V;
|
||||
case MF_TIMER_STEP: return FTM0_C0V;
|
||||
case MF_TIMER_TEMP: return FTM1_C0V;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
switch (timer_num) {
|
||||
case 0: return FTM0_CNT;
|
||||
case 1: return FTM1_CNT;
|
||||
case MF_TIMER_STEP: return FTM0_CNT;
|
||||
case MF_TIMER_TEMP: return FTM1_CNT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user