-
Notifications
You must be signed in to change notification settings - Fork 2k
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
sys/ztimer: add ZTIMER_SEC #15715
sys/ztimer: add ZTIMER_SEC #15715
Conversation
@kfessel might want to have a look at this |
sys/ztimer/auto_init.c
Outdated
static ztimer_convert_frac_t _ztimer_convert_frac_sec; | ||
ztimer_clock_t *const ZTIMER_SEC = &_ztimer_convert_frac_sec.super.super; | ||
ztimer_clock_t *const ZTIMER_SEC_BASE = &_ztimer_periph_timer_msec.super; | ||
# define ZTIMER_SEC_CONVERT_LOWER (&_ztimer_periph_timer_rtt_msec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it ok to use this symbol here? doesn't it need the rtt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I changed the preprocessor conditional to only uses this if both ztimer_msec
and ztimer_periph_rtt
are used.
Maybe it makes sense to decouple this from ztimer_msec
to also profit from the power savings when ztimer_sec
but not ztimer_msec
is used. I'll fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. RTT is now used for ZTIMER_SEC
when available regardless of ZTIMER_MSEC
, unless the application/user explicitly pulled in ztimer_periph_rtc
.
Long overdue! But I think we should try to not use RTC. On most platforms, it shares the same hardware with RTT anyways (requiring to chose one). Also the RTC interface is clumsy to use if only a seconds granularity counter is desired (like in this case). So, please change to use RTT as preference (possibly a converted ZTIMER_MSEC), and only fall back to RTC if no RTT is available. |
Yeah, the RTC backend probably doesn't yet deal with setting 0 or 1 properly. It would need to set at least +2 to be safe. |
Hmm, if one pulls in Btw.: Shouldn't we (unrelated of this PR) use |
Oh, I chose the wrong commit with |
That's an FAQ by now. The issue is that if ztimer_periph_rtt is used, it'll be used for ztimer_msec. But not all periph_rtt can actually do 1000 or 1024 Hz (or are configured that way). I think we need to add more fine-grained rtt capabilities as features. |
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not want to respond without measuring. Yesterday i found my nucleo-l073rz having a IDD bride. I tested different configuration (non extra, rtt, rtc, rtt and rtc). Not every configuration could be built first I fixed that, patch attached an added the pm_layerd configuration for ZTIMER_SEC
i will add the patch later
@kfessel: Care to also squash when rebasing? |
75b1781
to
13cbca8
Compare
sys/ztimer/auto_init.c
Outdated
# ifdef MODULE_PM_LAYERED | ||
LOG_DEBUG("ztimer_init(): ZTIMER_SEC setting required_pm_mode to %i\n", | ||
CONFIG_ZTIMER_SEC_REQUIRED_PM_MODE); | ||
ZTIMER_SEC->required_pm_mode = CONFIG_ZTIMER_SEC_REQUIRED_PM_MODE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right and while writing that lines i thought this is wrong but its the current way to go and i was already searching if there is an issue or PR in this direction.
so these PRs are in "conflict". one has to merged the other has to follow
my Test Example IDD on nucleo-l073rz waitfor rtc or rtt 1.5µA (30€ Multimeter) |
with restructure for flexibility i also fixed the issue of #15911 |
uncrustify keeps calling out: |
the fixup also adds the comments |
uncrustfy is just plain wrong wrong about sys/include/ztimer.h#L297 and sys/include/ztimer.h#L309 its against the riot uncrustfy rules and no one in their right mind would consider to do that
it kills the last bit of readablity that was left (after a line breake that it sugested there for 2-5 chars |
uncrustify is currently only warning. just use up-to-date uncrustify and ignore the warnings.
main reason to use uncrustify is to not deal with formatting anymore but still have consistent looks. right now, that might be at the cost of some readability sometimes. |
Maybe we could configure |
I do like being able to do "strg-f" (my shortcut for uncrustify) and be done with it, and enjoy not going through a CI static-test fail/look at/manually fix cycle... We should definitely update the uncrustify on CI. if it takes too long to go to 2020.04 LTS, maybe self-compile the latest version. |
but even the version that comes with 2020.10 wants to make that define less readable ATM i think changing CONFIG_ZTIMER_TIMER_REQUIRED_PM_MODE to CONFIG_ZTIMER_TIM_REQ_PM_MODE to cicumvent that uncrustify problem for the gcc warning you can state don't do that here, is there something that does it for uncrustify |
Add Also: But generally: The coding convention only recommends to keep lines shorter than up to 100 chars - as otherwise this sets and insensitive to use short but unreadable names. |
so i remove the linebreakes and ignore the uncrustify? |
you can also use code-style-ignore comments. |
Let's wait a bit. I'll PR a change to 100 chars. That should go in without discussion, as our coding convention was updated to allow this and we just forgot to also touch uncrustify. Maybe the issue is gone with that already. |
#16149 will update riot-uncrustify to 100 chars (riot-coding convention) |
just checked the complains by uncrustify: |
wire up ZTIMER_SEC to the existing RTC backend, or RTT backend, or periph_timer backend (in this order of preference). Update sys/ztimer/auto_init.c Co-authored-by: Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
rename ztimer_periph_timer_rtt for readability fix debugmessage reorder defines
MSEC and SEC are now usable on TIMER(0) without having USEC pm is configured by used hardware OLD configuration values are translated for backward compatibility
better go for readybility and convention than uncrustify
BLOCK instead of require
rebased for uncrustify config update |
At this point I'm still formally author of this PR, but haven't really authored much of the changes. IMO it would make sense if I close the PR and @kfessel opens a new one with the current state (which references this one). This would IMO better document the development history and authorship. |
Please continue the review in #16172 |
Contribution description
Wired up
ZTIMER_SEC
to the existing RTC backend, or RTT backend, orperiph_timer
backend (in this order of preference).Testing procedure
tests/ztimer_msg
has been updated to allow testingZTIMER_SEC
. Note: Uncomment a line in the Makefile as documented theretests/ztimer_underflow
has been updated to allow testingZTIMER_SEC
make TEST_ZTIMER_CLOCK=ZTIMER_SEC -C tests/ztimer_underflow flash test
master
unrelated to the PR that needs fixing.Issues/PRs references
None