Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

driver/counter/counter_ll_stm32_rtc.c: Add 1 tick to alarm #25367

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion drivers/counter/counter_ll_stm32_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions samples/drivers/counter/alarm/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
************

Expand Down
2 changes: 1 addition & 1 deletion samples/drivers/counter/alarm/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ tests:
- "Counter alarm sample"
- "Set alarm in 2 sec"
- "!!! Alarm !!!"
- "Now: 2"
- "Now: [2|3]"
depends_on: counter