🎨 Rename HAL timer elements
This commit is contained in:
committed by
Scott Lahteine
parent
d75e7784e5
commit
9b1c0a75e1
@ -53,7 +53,7 @@
|
||||
static volatile int8_t currentServoIndex[_Nbr_16timers]; // index for the servo being pulsed for each timer (or -1 if refresh interval)
|
||||
|
||||
FORCE_INLINE static uint16_t getTimerCount() {
|
||||
Tc * const tc = TimerConfig[SERVO_TC].pTc;
|
||||
Tc * const tc = timer_config[SERVO_TC].pTc;
|
||||
|
||||
tc->COUNT16.CTRLBSET.reg = TC_CTRLBCLR_CMD_READSYNC;
|
||||
SYNC(tc->COUNT16.SYNCBUSY.bit.CTRLB || tc->COUNT16.SYNCBUSY.bit.COUNT);
|
||||
@ -65,7 +65,7 @@ FORCE_INLINE static uint16_t getTimerCount() {
|
||||
// Interrupt handler for the TC
|
||||
// ----------------------------
|
||||
HAL_SERVO_TIMER_ISR() {
|
||||
Tc * const tc = TimerConfig[SERVO_TC].pTc;
|
||||
Tc * const tc = timer_config[SERVO_TC].pTc;
|
||||
const timer16_Sequence_t timer =
|
||||
#ifndef _useTimer1
|
||||
_timer2
|
||||
@ -125,7 +125,7 @@ HAL_SERVO_TIMER_ISR() {
|
||||
}
|
||||
|
||||
void initISR(timer16_Sequence_t timer) {
|
||||
Tc * const tc = TimerConfig[SERVO_TC].pTc;
|
||||
Tc * const tc = timer_config[SERVO_TC].pTc;
|
||||
const uint8_t tcChannel = TIMER_TCCHANNEL(timer);
|
||||
|
||||
static bool initialized = false; // Servo TC has been initialized
|
||||
@ -202,7 +202,7 @@ void initISR(timer16_Sequence_t timer) {
|
||||
}
|
||||
|
||||
void finISR(timer16_Sequence_t timer) {
|
||||
Tc * const tc = TimerConfig[SERVO_TC].pTc;
|
||||
Tc * const tc = timer_config[SERVO_TC].pTc;
|
||||
const uint8_t tcChannel = TIMER_TCCHANNEL(timer);
|
||||
|
||||
// Disable the match channel interrupt request
|
||||
|
@ -36,7 +36,7 @@
|
||||
#error "OnBoard SPI BUS can't be shared with other devices."
|
||||
#endif
|
||||
|
||||
#if SERVO_TC == RTC_TIMER_NUM
|
||||
#if SERVO_TC == MF_TIMER_RTC
|
||||
#error "Servos can't use RTC timer"
|
||||
#endif
|
||||
|
||||
|
@ -31,13 +31,13 @@
|
||||
// Local defines
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#define NUM_HARDWARE_TIMERS 8
|
||||
#define NUM_HARDWARE_TIMERS 9
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Private Variables
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
const tTimerConfig TimerConfig[NUM_HARDWARE_TIMERS+1] = {
|
||||
const tTimerConfig timer_config[NUM_HARDWARE_TIMERS] = {
|
||||
{ {.pTc=TC0}, TC0_IRQn, TC_PRIORITY(0) }, // 0 - stepper (assigned priority 2)
|
||||
{ {.pTc=TC1}, TC1_IRQn, TC_PRIORITY(1) }, // 1 - stepper (needed by 32 bit timers)
|
||||
{ {.pTc=TC2}, TC2_IRQn, 5 }, // 2 - tone (reserved by framework and fixed assigned priority 5)
|
||||
@ -67,13 +67,13 @@ FORCE_INLINE void Disable_Irq(IRQn_Type irq) {
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
|
||||
IRQn_Type irq = timer_config[timer_num].IRQ_Id;
|
||||
|
||||
// Disable interrupt, just in case it was already enabled
|
||||
Disable_Irq(irq);
|
||||
|
||||
if (timer_num == RTC_TIMER_NUM) {
|
||||
Rtc * const rtc = TimerConfig[timer_num].pRtc;
|
||||
if (timer_num == MF_TIMER_RTC) {
|
||||
Rtc * const rtc = timer_config[timer_num].pRtc;
|
||||
|
||||
// Disable timer interrupt
|
||||
rtc->MODE0.INTENCLR.reg = RTC_MODE0_INTENCLR_CMP0;
|
||||
@ -101,7 +101,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
SYNC(rtc->MODE0.SYNCBUSY.bit.ENABLE);
|
||||
}
|
||||
else {
|
||||
Tc * const tc = TimerConfig[timer_num].pTc;
|
||||
Tc * const tc = timer_config[timer_num].pTc;
|
||||
|
||||
// Disable timer interrupt
|
||||
tc->COUNT32.INTENCLR.reg = TC_INTENCLR_OVF; // disable overflow interrupt
|
||||
@ -141,17 +141,17 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
}
|
||||
|
||||
// Finally, enable IRQ
|
||||
NVIC_SetPriority(irq, TimerConfig[timer_num].priority);
|
||||
NVIC_SetPriority(irq, timer_config[timer_num].priority);
|
||||
NVIC_EnableIRQ(irq);
|
||||
}
|
||||
|
||||
void HAL_timer_enable_interrupt(const uint8_t timer_num) {
|
||||
const IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
|
||||
const IRQn_Type irq = timer_config[timer_num].IRQ_Id;
|
||||
NVIC_EnableIRQ(irq);
|
||||
}
|
||||
|
||||
void HAL_timer_disable_interrupt(const uint8_t timer_num) {
|
||||
const IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
|
||||
const IRQn_Type irq = timer_config[timer_num].IRQ_Id;
|
||||
Disable_Irq(irq);
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ static bool NVIC_GetEnabledIRQ(IRQn_Type IRQn) {
|
||||
}
|
||||
|
||||
bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
|
||||
const IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
|
||||
const IRQn_Type irq = timer_config[timer_num].IRQ_Id;
|
||||
return NVIC_GetEnabledIRQ(irq);
|
||||
}
|
||||
|
||||
|
@ -25,21 +25,22 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Defines
|
||||
// --------------------------------------------------------------------------
|
||||
#define RTC_TIMER_NUM 8 // This is not a TC but a RTC
|
||||
|
||||
typedef uint32_t hal_timer_t;
|
||||
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
|
||||
|
||||
#define HAL_TIMER_RATE F_CPU // frequency of timers peripherals
|
||||
|
||||
#ifndef STEP_TIMER_NUM
|
||||
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
||||
#define MF_TIMER_RTC 8 // This is not a TC but a RTC
|
||||
|
||||
#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 RTC_TIMER_NUM // Timer Index for Temperature
|
||||
#ifndef MF_TIMER_TEMP
|
||||
#define MF_TIMER_TEMP MF_TIMER_RTC // Timer Index for Temperature
|
||||
#endif
|
||||
|
||||
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
||||
@ -52,30 +53,29 @@ 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)
|
||||
|
||||
#define TC_PRIORITY(t) t == SERVO_TC ? 1 \
|
||||
: (t == STEP_TIMER_NUM || t == PULSE_TIMER_NUM) ? 2 \
|
||||
: (t == TEMP_TIMER_NUM) ? 6 \
|
||||
: 7
|
||||
#define TC_PRIORITY(t) ( t == SERVO_TC ? 1 \
|
||||
: (t == MF_TIMER_STEP || t == MF_TIMER_PULSE) ? 2 \
|
||||
: (t == MF_TIMER_TEMP) ? 6 : 7 )
|
||||
|
||||
#define _TC_HANDLER(t) void TC##t##_Handler()
|
||||
#define TC_HANDLER(t) _TC_HANDLER(t)
|
||||
#ifndef HAL_STEP_TIMER_ISR
|
||||
#define HAL_STEP_TIMER_ISR() TC_HANDLER(STEP_TIMER_NUM)
|
||||
#define HAL_STEP_TIMER_ISR() TC_HANDLER(MF_TIMER_STEP)
|
||||
#endif
|
||||
#if STEP_TIMER_NUM != PULSE_TIMER_NUM
|
||||
#define HAL_PULSE_TIMER_ISR() TC_HANDLER(PULSE_TIMER_NUM)
|
||||
#if MF_TIMER_STEP != MF_TIMER_PULSE
|
||||
#define HAL_PULSE_TIMER_ISR() TC_HANDLER(MF_TIMER_PULSE)
|
||||
#endif
|
||||
#if TEMP_TIMER_NUM == RTC_TIMER_NUM
|
||||
#if MF_TIMER_TEMP == MF_TIMER_RTC
|
||||
#define HAL_TEMP_TIMER_ISR() void RTC_Handler()
|
||||
#else
|
||||
#define HAL_TEMP_TIMER_ISR() TC_HANDLER(TEMP_TIMER_NUM)
|
||||
#define HAL_TEMP_TIMER_ISR() TC_HANDLER(MF_TIMER_TEMP)
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -95,7 +95,7 @@ typedef struct {
|
||||
// Public Variables
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
extern const tTimerConfig TimerConfig[];
|
||||
extern const tTimerConfig timer_config[];
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Public functions
|
||||
@ -104,20 +104,20 @@ extern const tTimerConfig TimerConfig[];
|
||||
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) {
|
||||
// Should never be called with timer RTC_TIMER_NUM
|
||||
Tc * const tc = TimerConfig[timer_num].pTc;
|
||||
// Should never be called with timer MF_TIMER_RTC
|
||||
Tc * const tc = timer_config[timer_num].pTc;
|
||||
tc->COUNT32.CC[0].reg = compare;
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
|
||||
// Should never be called with timer RTC_TIMER_NUM
|
||||
Tc * const tc = TimerConfig[timer_num].pTc;
|
||||
// Should never be called with timer MF_TIMER_RTC
|
||||
Tc * const tc = timer_config[timer_num].pTc;
|
||||
return (hal_timer_t)tc->COUNT32.CC[0].reg;
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
// Should never be called with timer RTC_TIMER_NUM
|
||||
Tc * const tc = TimerConfig[timer_num].pTc;
|
||||
// Should never be called with timer MF_TIMER_RTC
|
||||
Tc * const tc = timer_config[timer_num].pTc;
|
||||
tc->COUNT32.CTRLBSET.reg = TC_CTRLBCLR_CMD_READSYNC;
|
||||
SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB || tc->COUNT32.SYNCBUSY.bit.COUNT);
|
||||
return tc->COUNT32.COUNT.reg;
|
||||
@ -128,13 +128,13 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num);
|
||||
bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
|
||||
|
||||
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
|
||||
if (timer_num == RTC_TIMER_NUM) {
|
||||
Rtc * const rtc = TimerConfig[timer_num].pRtc;
|
||||
if (timer_num == MF_TIMER_RTC) {
|
||||
Rtc * const rtc = timer_config[timer_num].pRtc;
|
||||
// Clear interrupt flag
|
||||
rtc->MODE0.INTFLAG.reg = RTC_MODE0_INTFLAG_CMP0;
|
||||
}
|
||||
else {
|
||||
Tc * const tc = TimerConfig[timer_num].pTc;
|
||||
Tc * const tc = timer_config[timer_num].pTc;
|
||||
// Clear interrupt flag
|
||||
tc->COUNT32.INTFLAG.reg = TC_INTFLAG_OVF;
|
||||
}
|
||||
|
Reference in New Issue
Block a user