ITE drivers/timer: add disable event timer control

We add disable event timer at the beginning of critical section
for two reason:
1.For K_TICKS_FOREVER case: since no future timer interrupts
are expected or required, so we disable the event timer.
2.Others case: according it81202 spec, when timer enable bit
from 0->1, the timer will reload counts and start countdown.

Signed-off-by: Ruibin Chang <ruibin.chang@ite.com.tw>
This commit is contained in:
Ruibin Chang 2021-08-17 11:21:10 +08:00 committed by Christopher Friedt
parent fc33f6af3a
commit f2b9ba1b2c

View file

@ -180,9 +180,13 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
/* Critical section */
k_spinlock_key_t key = k_spin_lock(&lock);
/* NOTE: To reduce cpu effort, we don't add critical section here */
/* Disable event timer */
IT8XXX2_EXT_CTRLX(EVENT_TIMER) &= ~IT8XXX2_EXT_ETXEN;
if (ticks == K_TICKS_FOREVER) {
hw_cnt = EVENT_TIMER_MAX_CNT;
/* Return since no future timer interrupts are required */
k_spin_unlock(&lock, key);
return;
} else if (ticks <= 1) {
/*
* Ticks <= 1 means the kernel wants the tick announced
@ -210,13 +214,15 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
/* Set event timer 24-bit count */
IT8XXX2_EXT_CNTX(EVENT_TIMER) = hw_cnt;
/* Enable and re-start event timer */
IT8XXX2_EXT_CTRLX(EVENT_TIMER) |= (IT8XXX2_EXT_ETXEN |
IT8XXX2_EXT_ETXRST);
/* W/C event timer interrupt status */
ite_intc_isr_clear(EVENT_TIMER_IRQ);
/*
* When timer enable bit is from 0->1, timer will reload counts and
* start countdown.
*/
IT8XXX2_EXT_CTRLX(EVENT_TIMER) |= IT8XXX2_EXT_ETXEN;
k_spin_unlock(&lock, key);
LOG_DBG("timeout is 0x%x, set hw count 0x%x", ticks, hw_cnt);