Skip to content

Commit f2b9ba1

Browse files
RuibinChangcfriedt
authored andcommitted
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 <[email protected]>
1 parent fc33f6a commit f2b9ba1

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

drivers/timer/ite_it8xxx2_timer.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,13 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
180180
/* Critical section */
181181
k_spinlock_key_t key = k_spin_lock(&lock);
182182

183-
/* NOTE: To reduce cpu effort, we don't add critical section here */
183+
/* Disable event timer */
184+
IT8XXX2_EXT_CTRLX(EVENT_TIMER) &= ~IT8XXX2_EXT_ETXEN;
185+
184186
if (ticks == K_TICKS_FOREVER) {
185-
hw_cnt = EVENT_TIMER_MAX_CNT;
187+
/* Return since no future timer interrupts are required */
188+
k_spin_unlock(&lock, key);
189+
return;
186190
} else if (ticks <= 1) {
187191
/*
188192
* Ticks <= 1 means the kernel wants the tick announced
@@ -210,13 +214,15 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
210214
/* Set event timer 24-bit count */
211215
IT8XXX2_EXT_CNTX(EVENT_TIMER) = hw_cnt;
212216

213-
/* Enable and re-start event timer */
214-
IT8XXX2_EXT_CTRLX(EVENT_TIMER) |= (IT8XXX2_EXT_ETXEN |
215-
IT8XXX2_EXT_ETXRST);
216-
217217
/* W/C event timer interrupt status */
218218
ite_intc_isr_clear(EVENT_TIMER_IRQ);
219219

220+
/*
221+
* When timer enable bit is from 0->1, timer will reload counts and
222+
* start countdown.
223+
*/
224+
IT8XXX2_EXT_CTRLX(EVENT_TIMER) |= IT8XXX2_EXT_ETXEN;
225+
220226
k_spin_unlock(&lock, key);
221227

222228
LOG_DBG("timeout is 0x%x, set hw count 0x%x", ticks, hw_cnt);

0 commit comments

Comments
 (0)