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

[RFC] Adding RTC API #23526

Closed
wants to merge 7 commits into from
Closed

Conversation

jdascenzio
Copy link
Contributor

Hi,
I'm working on a RTC driver for stm32. Currently in Zephyr, RTC is used as a counter. In my project, I would like to use it at a real clock time to timestamp my data. I also integrated this driver in clock_[get/set]time. I'm open to all suggestions to improve it. In the future, I would like to integrate also alarm

@jdascenzio jdascenzio changed the title Rtc driver drivers: rtc Mar 17, 2020
@zephyrbot zephyrbot added area: POSIX POSIX API Library area: API Changes to public APIs labels Mar 17, 2020
@zephyrbot
Copy link
Collaborator

zephyrbot commented Mar 17, 2020

All checks are passing now.

Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages.

@tbursztyka tbursztyka changed the title drivers: rtc [RFC] Adding RTC API Mar 17, 2020
include/drivers/rtc.h Outdated Show resolved Hide resolved
lib/posix/clock.c Outdated Show resolved Hide resolved
@jdascenzio jdascenzio force-pushed the rtc_driver branch 3 times, most recently from b35cf6e to fe2f35c Compare March 17, 2020 16:57
@carlescufi carlescufi added the RFC Request For Comments: want input from the community label Mar 17, 2020
drivers/rtc/rtc_stm32.c Outdated Show resolved Hide resolved
drivers/rtc/rtc_stm32.c Show resolved Hide resolved
lib/posix/clock.c Outdated Show resolved Hide resolved
@@ -26,6 +40,9 @@ int clock_gettime(clockid_t clock_id, struct timespec *ts)
{
u64_t elapsed_msecs;
struct timespec base;
#ifdef CONFIG_RTC
struct device *dev_rtc;
#endif

switch (clock_id) {
case CLOCK_MONOTONIC:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so RTC is used only for REALTIME. Could that be an issue in some cases? It means that those clock ids are using different source clock thus accuracy. I'm not sure what are the typical uses cases but can imagine that someone reads both at one point of time and next time in an hour. Monotonic will show different time elapsed than realtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my system I need to timestamp some data precisely. My system could run during a long time without time synchronization. The RTC have a lower clock drift than system clock.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly, thus i wonder if it is possible to provide monotonic based on RTC device. Maybe logging uptime offset when settime is called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is 2 problems to use RTC as monotonic:

  • According to Posix: "the MONOTONIC clock is not affected by discontinuous jumps in the system time". (A workaround will be to save the offset on settime and use it to correct monotonic clock)
  • The resolution for shorter time is better with system clock

include/drivers/rtc.h Show resolved Hide resolved
lib/posix/clock.c Outdated Show resolved Hide resolved
lib/posix/clock.c Outdated Show resolved Hide resolved
lib/posix/clock.c Outdated Show resolved Hide resolved
include/drivers/rtc.h Outdated Show resolved Hide resolved
drivers/rtc/rtc_stm32.c Outdated Show resolved Hide resolved
@erwango erwango requested a review from FRASTM March 18, 2020 12:56
@jdascenzio jdascenzio force-pushed the rtc_driver branch 5 times, most recently from 9150c9a to ac9af10 Compare March 19, 2020 13:46
@github-actions github-actions bot added has-conflicts Issue/PR has conflicts with another issue/PR platform: STM32 ST Micro STM32 and removed has-conflicts Issue/PR has conflicts with another issue/PR labels Jul 2, 2020
@pabigot
Copy link
Collaborator

pabigot commented Jul 7, 2020

API 2020-07-07: Moved from triage to To-Do pending submission of draft proposals by @pabigot, @henrikbrixandersen, or others.

@pabigot pabigot moved this from Triage to To Do in Architecture Project Jul 7, 2020
@carlescufi carlescufi moved this from To Do to In Progress in Architecture Project Jul 28, 2020
@nashif nashif added the Stale label Sep 7, 2020
@llisauskas
Copy link

llisauskas commented Sep 8, 2020

@jdascenzio is this PR going to recieve any updates? I'm planning to start work on something similiar, since my system requires this, but it does not make sense if this is going forward. I can contribute if it get's approved.

@jdascenzio
Copy link
Contributor Author

@jdascenzio is this PR going to recieve any updates? I'm planning to start work on something similiar, since my system requires this, but it does not make sense if this is going forward. I can contribute if it get's approved.

For now, I have stopped to work on it. I used this driver which suits me for the moment. Maybe @pabigot or @henrikbrixandersen will make a draft to add some of these functionalities in driver counter....

@pabigot
Copy link
Collaborator

pabigot commented Sep 12, 2020

For now, I have stopped to work on it. I used this driver which suits me for the moment. Maybe @pabigot or @henrikbrixandersen will make a draft to add some of these functionalities in driver counter....

The architecture design I still support is that counters continue to provide an integer interface, and things like timeutil_timegm64 and gmtime are used to translate between civil and integer time representations to allow a counter to support civil time maintenance and alarms. There are also supporting capabilities necessary to:

  1. register civil time against the local clock (without that being restricted to CONFIG_POSIX=y);
  2. accommodate leap seconds and local time offset changes for people who require them; and
  3. compensate for local clock skew.

I have draft support for the pieces of that that are important to me (1 and 3), but they didn't make the 2.4.0 deadline. I expect to get them posted around the time 2.5.0 development opens up in a few weeks.

@github-actions github-actions bot removed the Stale label Sep 19, 2020
@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Nov 19, 2020
@github-actions github-actions bot closed this Dec 3, 2020
Architecture Project automation moved this from In Progress to Done Dec 3, 2020
@cederom
Copy link

cederom commented May 20, 2021

Hello world :-) I also create set time by manual time shift on set add.. but this is not preserved across reboots. I have created a feature request for RTC framework here: #35333 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: Boards area: POSIX POSIX API Library area: Tests Issues related to a particular existing or missing test has-conflicts Issue/PR has conflicts with another issue/PR platform: STM32 ST Micro STM32 RFC Request For Comments: want input from the community Stale
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet