diff options
author | Mulin Chao <mlchao@nuvoton.com> | 2016-11-18 12:26:08 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-11-22 11:51:56 -0800 |
commit | 50fbfc5040ab2668b3031f0ebf56be8e7f4546fe (patch) | |
tree | a607336add25937b8ea24b5f395664f94b335299 /chip | |
parent | 20ca52a9eec2d6f805d077f541ae22bd07732a3f (diff) | |
download | chrome-ec-50fbfc5040ab2668b3031f0ebf56be8e7f4546fe.tar.gz |
npcx: hwtimer: Add consecutive reading for ITCNT32
The mux for selecting source clock of ITIM will introduce a delay
and have a chance to make ITIM's source clock and core clock are
asynchronous. We need consecutive reading for ITCNT32 no matter source
clock is APB2 or 32k.
Modified sources:
1. hwtimer.c: Add consecutive reading for ITCNT32
BRANCH=none
BUG=chrome-os-partner:34346,chrome-os-partner:59240
TEST=No time stamp symptoms occur on wheatley for 30 hours.
Change-Id: I8b54e93b320e3ea74fc3d6ea13f0d178f9c449cd
Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-on: https://chromium-review.googlesource.com/412505
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r-- | chip/npcx/hwtimer.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/chip/npcx/hwtimer.c b/chip/npcx/hwtimer.c index ac5a301019..58bcda17c5 100644 --- a/chip/npcx/hwtimer.c +++ b/chip/npcx/hwtimer.c @@ -123,11 +123,12 @@ uint32_t __hw_clock_event_get(void) /* Get current counter value of event timer */ uint16_t __hw_clock_event_count(void) { - uint16_t cnt; + uint16_t cnt, cnt2; + + cnt = NPCX_ITCNT16(ITIM_EVENT_NO); /* Wait for two consecutive equal values are read */ - do { - cnt = NPCX_ITCNT16(ITIM_EVENT_NO); - } while (cnt != NPCX_ITCNT16(ITIM_EVENT_NO)); + while ((cnt2 = NPCX_ITCNT16(ITIM_EVENT_NO)) != cnt) + cnt = cnt2; return cnt; } @@ -220,7 +221,16 @@ void hw_clock_source_set_preload(uint32_t ts, uint8_t clear) /* Returns the value of the free-running counter used as clock. */ uint32_t __hw_clock_source_read(void) { - uint32_t cnt = NPCX_ITCNT32; + uint32_t cnt, cnt2; + + cnt = NPCX_ITCNT32; + /* + * Wait for two consecutive equal values are read no matter + * ITIM's source clock is APB2 or 32K since mux's delay. + */ + while ((cnt2 = NPCX_ITCNT32) != cnt) + cnt = cnt2; + #if DEBUG_TMR cur_cnt_us_dbg = TICK_ITIM32_MAX_CNT - cnt; #endif |