summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip/npcx/clock.c10
-rw-r--r--chip/npcx/hwtimer.c12
-rw-r--r--chip/npcx/hwtimer_chip.h7
3 files changed, 21 insertions, 8 deletions
diff --git a/chip/npcx/clock.c b/chip/npcx/clock.c
index 40ffa205dc..2dcd176c54 100644
--- a/chip/npcx/clock.c
+++ b/chip/npcx/clock.c
@@ -234,7 +234,7 @@ void __idle(void)
#else
timestamp_t t0, t1;
- uint32_t next_evt_us;
+ uint32_t next_evt_us, evt_count;
/*
* Initialize console in use to true and specify the console expire
@@ -272,13 +272,17 @@ void __idle(void)
NPCX_PMCSR = IDLE_PARAMS;
/* UART-rx(console) become to GPIO (NONE INT mode) */
clock_uart2gpio();
+
+ /* Get current counter value of event timer */
+ evt_count = __hw_clock_event_count();
/* Enter deep idle */
asm("wfi");
+ /* Get time delay cause of deep idle */
+ next_evt_us = __hw_clock_get_sleep_time(evt_count);
+
/* GPIO back to UART-rx (console) */
clock_gpio2uart();
- /* Get time delay cause of deep idle */
- next_evt_us = __hw_clock_get_sleep_time();
/* Fast forward timer according to wake-up timer. */
t1.val = t0.val + next_evt_us;
/* Record time spent in deep sleep. */
diff --git a/chip/npcx/hwtimer.c b/chip/npcx/hwtimer.c
index 0971198c03..4f8ff03308 100644
--- a/chip/npcx/hwtimer.c
+++ b/chip/npcx/hwtimer.c
@@ -108,8 +108,14 @@ uint32_t __hw_clock_event_get(void)
return evt_expired_us;
}
+/* Get current counter value of event timer */
+uint32_t __hw_clock_event_count(void)
+{
+ return NPCX_ITCNT16(ITIM_EVENT_NO);
+}
+
/* Returns time delay cause of deep idle */
-uint32_t __hw_clock_get_sleep_time(void)
+uint32_t __hw_clock_get_sleep_time(uint32_t pre_evt_cnt)
{
fp_t evt_tick = FLOAT_TO_FP(SECOND/(float)INT_32K_CLOCK);
uint32_t sleep_time;
@@ -118,10 +124,10 @@ uint32_t __hw_clock_get_sleep_time(void)
interrupt_disable();
/* Event has been triggered but timer ISR dosen't handle it */
if (IS_BIT_SET(NPCX_ITCTS(ITIM_EVENT_NO), NPCX_ITCTS_TO_STS))
- sleep_time = FP_TO_INT((fp_inter_t)(evt_cnt+1) * evt_tick);
+ sleep_time = FP_TO_INT((fp_inter_t)(pre_evt_cnt+1) * evt_tick);
/* Event hasn't been triggered */
else
- sleep_time = FP_TO_INT((fp_inter_t)(evt_cnt+1 - cnt) *
+ sleep_time = FP_TO_INT((fp_inter_t)(pre_evt_cnt+1 - cnt) *
evt_tick);
interrupt_enable();
diff --git a/chip/npcx/hwtimer_chip.h b/chip/npcx/hwtimer_chip.h
index b529bce463..ac657a2a4b 100644
--- a/chip/npcx/hwtimer_chip.h
+++ b/chip/npcx/hwtimer_chip.h
@@ -21,7 +21,10 @@ enum ITIM_SOURCE_CLOCK_T {
/* Initialize ITIM16 timer */
void init_hw_timer(int itim_no, enum ITIM_SOURCE_CLOCK_T source);
-/* Returns time delay cause of deep idle */
-uint32_t __hw_clock_get_sleep_time(void);
+/* Returns the counter value of event timer */
+uint32_t __hw_clock_event_count(void);
+
+/* Returns time delay because of deep idle */
+uint32_t __hw_clock_get_sleep_time(uint32_t pre_evt_cnt);
#endif /* __CROS_EC_HWTIMER_CHIP_H */