[2.0.x] HAL timer set/get count => set/get compare (#9581)
To reduce confusion over the current timer count vs. the compare (aka "top") value. Caution: this re-uses the function name, changing its meaning.
This commit is contained in:
@ -147,10 +147,10 @@ extern "C" {
|
||||
#define HAL_timer_start(timer_num, frequency)
|
||||
|
||||
#define _CAT(a, ...) a ## __VA_ARGS__
|
||||
#define HAL_timer_set_count(timer, count) (_CAT(TIMER_OCR_, timer) = count)
|
||||
#define HAL_timer_get_count(timer) _CAT(TIMER_OCR_, timer)
|
||||
#define HAL_timer_set_current_count(timer, count) (_CAT(TIMER_COUNTER_, timer) = count)
|
||||
#define HAL_timer_get_current_count(timer) _CAT(TIMER_COUNTER_, timer)
|
||||
#define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
|
||||
#define HAL_timer_get_compare(timer) _CAT(TIMER_OCR_, timer)
|
||||
#define HAL_timer_set_count(timer, count) (_CAT(TIMER_COUNTER_, timer) = count)
|
||||
#define HAL_timer_get_count(timer) _CAT(TIMER_COUNTER_, timer)
|
||||
|
||||
#define HAL_timer_isr_prologue(timer_num)
|
||||
|
||||
|
@ -127,9 +127,9 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
|
||||
}
|
||||
|
||||
#if 0
|
||||
void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
|
||||
void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
|
||||
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
|
||||
TC_SetRC(pConfig->pTimerRegs, pConfig->channel, count);
|
||||
TC_SetRC(pConfig->pTimerRegs, pConfig->channel, compare);
|
||||
}
|
||||
|
||||
void HAL_timer_isr_prologue(const uint8_t timer_num) {
|
||||
|
@ -91,22 +91,22 @@ 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 hal_timer_t count) {
|
||||
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
|
||||
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
|
||||
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
|
||||
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = compare;
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
|
||||
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
|
||||
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
|
||||
}
|
||||
|
||||
FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
|
||||
FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
|
||||
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
|
||||
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV = count;
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
|
||||
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
|
||||
}
|
||||
|
@ -87,22 +87,22 @@ typedef uint32_t hal_timer_t;
|
||||
void HAL_timer_init(void);
|
||||
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 hal_timer_t count) {
|
||||
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
|
||||
switch (timer_num) {
|
||||
case 0:
|
||||
LPC_TIM0->MR0 = count;
|
||||
if (LPC_TIM0->TC > count)
|
||||
LPC_TIM0->TC = count - 5; // generate an immediate stepper ISR
|
||||
LPC_TIM0->MR0 = compare;
|
||||
if (LPC_TIM0->TC > compare)
|
||||
LPC_TIM0->TC = compare - 5; // generate an immediate stepper ISR
|
||||
break;
|
||||
case 1:
|
||||
LPC_TIM1->MR0 = count;
|
||||
if (LPC_TIM1->TC > count)
|
||||
LPC_TIM1->TC = count - 5; // make sure we don't have one extra long period
|
||||
LPC_TIM1->MR0 = compare;
|
||||
if (LPC_TIM1->TC > compare)
|
||||
LPC_TIM1->TC = compare - 5; // make sure we don't have one extra long period
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
|
||||
switch (timer_num) {
|
||||
case 0: return LPC_TIM0->MR0;
|
||||
case 1: return LPC_TIM1->MR0;
|
||||
@ -110,14 +110,14 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_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: LPC_TIM0->TC = count; break;
|
||||
case 1: LPC_TIM1->TC = count; break;
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
switch (timer_num) {
|
||||
case 0: return LPC_TIM0->TC;
|
||||
case 1: return LPC_TIM1->TC;
|
||||
|
@ -46,7 +46,7 @@
|
||||
typedef uint16_t hal_timer_t;
|
||||
#define HAL_TIMER_TYPE_MAX 0xFFFF
|
||||
|
||||
#if defined MCU_STM32F103CB || defined(MCU_STM32F103C8)
|
||||
#if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
|
||||
#define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
|
||||
#else
|
||||
#define STEP_TIMER_NUM 5 // for other boards, five is fine.
|
||||
@ -82,8 +82,8 @@ typedef uint16_t hal_timer_t;
|
||||
#define ENABLE_TEMPERATURE_INTERRUPT() timer_enable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
|
||||
#define DISABLE_TEMPERATURE_INTERRUPT() timer_disable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
|
||||
|
||||
#define HAL_timer_get_current_count(timer_num) timer_get_count(TIMER_DEV(timer_num))
|
||||
#define HAL_timer_set_current_count(timer_num, count) timer_set_count(TIMER_DEV(timer_num), (uint16)count)
|
||||
#define HAL_timer_get_count(timer_num) timer_get_count(TIMER_DEV(timer_num))
|
||||
#define HAL_timer_set_count(timer_num, count) timer_set_count(TIMER_DEV(timer_num), (uint16)count)
|
||||
|
||||
|
||||
#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
|
||||
@ -128,21 +128,21 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
|
||||
* Todo: Look at that possibility later.
|
||||
*/
|
||||
|
||||
FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
|
||||
//count = min(count, HAL_TIMER_TYPE_MAX);
|
||||
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
|
||||
//compare = min(compare, HAL_TIMER_TYPE_MAX);
|
||||
switch (timer_num) {
|
||||
case STEP_TIMER_NUM:
|
||||
timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, count);
|
||||
timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, compare);
|
||||
return;
|
||||
case TEMP_TIMER_NUM:
|
||||
timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, count);
|
||||
timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, compare);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
|
||||
switch (timer_num) {
|
||||
case STEP_TIMER_NUM:
|
||||
return timer_get_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN);
|
||||
|
@ -117,11 +117,11 @@ extern "C" void TIM7_IRQHandler() {
|
||||
((void(*)(void))timerConfig[1].callback)();
|
||||
}
|
||||
|
||||
void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
|
||||
__HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, count);
|
||||
void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
|
||||
__HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, compare);
|
||||
}
|
||||
|
||||
void HAL_timer_set_current_count(const uint8_t timer_num, const uint32_t count) {
|
||||
void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
|
||||
__HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, count);
|
||||
}
|
||||
|
||||
@ -133,11 +133,11 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) {
|
||||
HAL_NVIC_DisableIRQ(timerConfig[timer_num].IRQ_Id);
|
||||
}
|
||||
|
||||
hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
|
||||
return __HAL_TIM_GetAutoreload(&timerConfig[timer_num].timerdef);
|
||||
}
|
||||
|
||||
uint32_t HAL_timer_get_current_count(const uint8_t timer_num) {
|
||||
uint32_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
return __HAL_TIM_GetCounter(&timerConfig[timer_num].timerdef);
|
||||
}
|
||||
|
||||
|
@ -91,12 +91,12 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
|
||||
void HAL_timer_enable_interrupt(const uint8_t timer_num);
|
||||
void HAL_timer_disable_interrupt(const uint8_t timer_num);
|
||||
|
||||
void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count);
|
||||
hal_timer_t HAL_timer_get_count(const uint8_t timer_num);
|
||||
uint32_t HAL_timer_get_current_count(const uint8_t timer_num);
|
||||
void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare);
|
||||
hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
|
||||
uint32_t HAL_timer_get_count(const uint8_t timer_num);
|
||||
|
||||
void HAL_timer_set_current_count(const uint8_t timer_num, const uint32_t count); // New
|
||||
/*FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
|
||||
void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count); // New
|
||||
/*FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
|
||||
// To do ??
|
||||
}*/
|
||||
|
||||
|
@ -80,14 +80,14 @@ 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 hal_timer_t count) {
|
||||
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 = count; break;
|
||||
case 1: FTM1_C0V = count; break;
|
||||
case 0: FTM0_C0V = compare; break;
|
||||
case 1: FTM1_C0V = compare; break;
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
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;
|
||||
@ -95,14 +95,14 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_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_CNT = count;
|
||||
case 1: FTM1_CNT = count;
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
|
||||
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;
|
||||
|
Reference in New Issue
Block a user