Fix SAMD51 Step Timer (#17692)
This commit is contained in:
parent
4af83430b5
commit
d7f90c36df
|
@ -121,14 +121,15 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||||
tc->COUNT32.CTRLA.bit.SWRST = true;
|
tc->COUNT32.CTRLA.bit.SWRST = true;
|
||||||
SYNC(tc->COUNT32.SYNCBUSY.bit.SWRST);
|
SYNC(tc->COUNT32.SYNCBUSY.bit.SWRST);
|
||||||
|
|
||||||
// Wave mode, reset counter on overflow on 0 (I use count down to prevent double buffer use)
|
// Wave mode, reset counter on compare match
|
||||||
tc->COUNT32.WAVE.reg = TC_WAVE_WAVEGEN_MFRQ;
|
tc->COUNT32.WAVE.reg = TC_WAVE_WAVEGEN_MFRQ;
|
||||||
tc->COUNT32.CTRLA.reg = TC_CTRLA_MODE_COUNT32 | TC_CTRLA_PRESCALER_DIV1;
|
tc->COUNT32.CTRLA.reg = TC_CTRLA_MODE_COUNT32 | TC_CTRLA_PRESCALER_DIV1;
|
||||||
tc->COUNT32.CTRLBSET.reg = TC_CTRLBCLR_DIR;
|
tc->COUNT32.CTRLBCLR.reg = TC_CTRLBCLR_DIR;
|
||||||
SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB);
|
SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB);
|
||||||
|
|
||||||
// Set compare value
|
// Set compare value
|
||||||
tc->COUNT32.COUNT.reg = tc->COUNT32.CC[0].reg = (HAL_TIMER_RATE) / frequency;
|
tc->COUNT32.CC[0].reg = (HAL_TIMER_RATE) / frequency;
|
||||||
|
tc->COUNT32.COUNT.reg = 0;
|
||||||
|
|
||||||
// Enable interrupt on compare
|
// Enable interrupt on compare
|
||||||
tc->COUNT32.INTFLAG.reg = TC_INTFLAG_OVF; // reset pending interrupt
|
tc->COUNT32.INTFLAG.reg = TC_INTFLAG_OVF; // reset pending interrupt
|
||||||
|
|
|
@ -97,13 +97,13 @@ 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) {
|
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
|
// Should never be called with timer RTC_TIMER_NUM
|
||||||
Tc * const tc = TimerConfig[timer_num].pTc;
|
Tc * const tc = TimerConfig[timer_num].pTc;
|
||||||
tc->COUNT32.CC[0].reg = HAL_TIMER_TYPE_MAX - compare;
|
tc->COUNT32.CC[0].reg = compare;
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
|
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
|
||||||
// Should never be called with timer RTC_TIMER_NUM
|
// Should never be called with timer RTC_TIMER_NUM
|
||||||
Tc * const tc = TimerConfig[timer_num].pTc;
|
Tc * const tc = TimerConfig[timer_num].pTc;
|
||||||
return (hal_timer_t)(HAL_TIMER_TYPE_MAX - tc->COUNT32.CC[0].reg);
|
return (hal_timer_t)tc->COUNT32.CC[0].reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||||
|
@ -111,7 +111,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||||
Tc * const tc = TimerConfig[timer_num].pTc;
|
Tc * const tc = TimerConfig[timer_num].pTc;
|
||||||
tc->COUNT32.CTRLBSET.reg = TC_CTRLBCLR_CMD_READSYNC;
|
tc->COUNT32.CTRLBSET.reg = TC_CTRLBCLR_CMD_READSYNC;
|
||||||
SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB || tc->COUNT32.SYNCBUSY.bit.COUNT);
|
SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB || tc->COUNT32.SYNCBUSY.bit.COUNT);
|
||||||
return HAL_TIMER_TYPE_MAX - tc->COUNT32.COUNT.reg;
|
return tc->COUNT32.COUNT.reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HAL_timer_enable_interrupt(const uint8_t timer_num);
|
void HAL_timer_enable_interrupt(const uint8_t timer_num);
|
||||||
|
|
Loading…
Reference in a new issue