npcx: system: Fixed bug that ec received unexpected rtc interrupt

In old system driver, ec clears "Predefined Time Occurred" (PTO) flag
before setting a new alarm (PT field in WTC). If PT field is the same
as the first 25 TTC bits at this moment, we might receive unexpected
rtc interrupt again. This CL sets new alarm first then clears PTO flag
to make sure rtc interrupt is issued from new alarm.

BRANCH=none
BUG=b:38310685
TEST=Duplicated the same symptom by the script in issue 38310685 on
gru. No symptoms occurred with the same script for 3 hours by applying
this CL.

Change-Id: Ia6410d6aa4ef8e2acb7bfadf9192d619045bfa58
Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-on: https://chromium-review.googlesource.com/508572
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
This commit is contained in:
Mulin Chao
2017-05-19 13:32:12 +08:00
committed by chrome-bot
parent 300403c83d
commit b72178b6ec

View File

@@ -418,12 +418,15 @@ void system_set_rtc_alarm(uint32_t seconds, uint32_t microseconds)
alarm_secs = cur_secs + seconds;
alarm_secs = alarm_secs & MTC_ALARM_MASK;
/*
* We should set new alarm (first 25 bits of clock value) first before
* clearing PTO in case issue rtc interrupt immediately.
*/
NPCX_WTC = alarm_secs;
/* Reset alarm first */
system_reset_rtc_alarm();
/* Set alarm, use first 25 bits of clock value */
NPCX_WTC = alarm_secs;
/* Enable interrupt mode alarm */
SET_BIT(NPCX_WTC, NPCX_WTC_WIE);