From 5732b3a98766d67a26dcb1f12d9eec89862e4f99 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Thu, 14 May 2020 15:49:24 +0200 Subject: [PATCH 1/2] driver: counter: counter_ll_stm32_rtc.c: Add 1 tick to alarm Add +1 tick to alarm in order to compensate the partially started tick. Alarm will expire between requested ticks and ticks+1. In case only 1 tick is requested, it will avoid that +1 Tick event occurs before alarm setting is finished. Signed-off-by: Alexandre Bourdiol --- drivers/counter/counter_ll_stm32_rtc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/counter/counter_ll_stm32_rtc.c b/drivers/counter/counter_ll_stm32_rtc.c index dd70f95e347e..c9502ae70247 100644 --- a/drivers/counter/counter_ll_stm32_rtc.c +++ b/drivers/counter/counter_ll_stm32_rtc.c @@ -143,7 +143,12 @@ static int rtc_stm32_set_alarm(struct device *dev, u8_t chan_id, data->user_data = alarm_cfg->user_data; if ((alarm_cfg->flags & COUNTER_ALARM_CFG_ABSOLUTE) == 0) { - ticks += now; + /* Add +1 in order to compensate the partially started tick. + * Alarm will expire between requested ticks and ticks+1. + * In case only 1 tick is requested, it will avoid + * that tick+1 event occurs before alarm setting is finished. + */ + ticks += now + 1; } LOG_DBG("Set Alarm: %d\n", ticks); From efa83d00923ef3144bb761ce178e627bdaed5f8a Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Fri, 15 May 2020 17:58:23 +0200 Subject: [PATCH 2/2] sample: drivers: counter: alarm: adapt test to driver change Due to counter driver implementation change "driver/counter/counter_ll_stm32_rtc.c: Add 1 tick to alarm" It is necessary to adapt sample test (sanitycheck) to take into consideration 1 tick precision/tolerance. Signed-off-by: Alexandre Bourdiol --- samples/drivers/counter/alarm/README.rst | 4 ++++ samples/drivers/counter/alarm/sample.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/samples/drivers/counter/alarm/README.rst b/samples/drivers/counter/alarm/README.rst index 25fb8b74b083..9efffc81ae71 100644 --- a/samples/drivers/counter/alarm/README.rst +++ b/samples/drivers/counter/alarm/README.rst @@ -9,6 +9,10 @@ This sample provides an example of alarm application using counter API. It sets an alarm with an initial delay of 2 seconds. At each alarm expiry, a new alarm is configured with a delay multiplied by 2. +.. note:: + In case of 1Hz frequency (RTC for example), precision is 1 second. + Therefore, the sample output may differ in 1 second + Requirements ************ diff --git a/samples/drivers/counter/alarm/sample.yaml b/samples/drivers/counter/alarm/sample.yaml index e3401dc39bf1..4408f21ca5e9 100644 --- a/samples/drivers/counter/alarm/sample.yaml +++ b/samples/drivers/counter/alarm/sample.yaml @@ -13,5 +13,5 @@ tests: - "Counter alarm sample" - "Set alarm in 2 sec" - "!!! Alarm !!!" - - "Now: 2" + - "Now: [2|3]" depends_on: counter