-
Notifications
You must be signed in to change notification settings - Fork 3k
Unify RTC, lp ticker, and us ticker for NRF51 and NRF52 series #7172
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
Conversation
RTC counter is 24-bit. Upper layer handles counter size and wraps ticks count when interrupt is to be fired before passing it to common_rtc_set_interrupt(), but for consistency and safety reasons we can wrap it again in the NRF driver.
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.
LGTM
@@ -100,6 +100,9 @@ void us_ticker_init(void) | |||
|
|||
nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_START); | |||
|
|||
/* Bug fix. First value can't be trusted. */ | |||
nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_CAPTURE1); |
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.
If this is somehow related to one of the known anomalies, it may be worth adding a reference.
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 don't think it is. I just noticed some very odd behavior on my boards.
#define LP_TICKER_COUNTER_BITS 32u | ||
#define LP_TICKER_FREQ 31250 | ||
|
||
#endif // LP_TICKER_H |
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 can't see where this file is being used?
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.
This file is added by mistake. I have removed it.
@@ -110,7 +110,9 @@ void us_ticker_set_interrupt(timestamp_t timestamp) | |||
{ | |||
core_util_critical_section_enter(); | |||
|
|||
nrf_timer_cc_write(NRF_TIMER1, NRF_TIMER_CC_CHANNEL0, timestamp & 0xFFFF); | |||
const uint32_t counter_mask = ((1 << US_TICKER_COUNTER_BITS) - 1); |
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.
Will this bit-shift always work? I was expecting this:
((1ULL << US_TICKER_COUNTER_BITS) - 1)
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.
Fixed as suggested.
@@ -110,7 +110,9 @@ void us_ticker_set_interrupt(timestamp_t timestamp) | |||
{ | |||
core_util_critical_section_enter(); | |||
|
|||
nrf_timer_cc_write(NRF_TIMER1, NRF_TIMER_CC_CHANNEL0, timestamp & 0xFFFF); | |||
const uint32_t counter_mask = ((1 << US_TICKER_COUNTER_BITS) - 1); |
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.
Same comment as above.
@mprse I just got back in the office, thank you for pushing this! I've added a couple of minor comments. |
It has been noticed that first read value can not be trusted.
Set the second highest user level, leaving the highest for UART (we are having constant overflows) and two levels below for everything else. This should increase the timer accuracy.
02d7d25
Provided some fixes after review. |
Looks good! Thank you! |
/morph build |
Build : SUCCESSBuild number : 2402 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 2037 |
Test : SUCCESSBuild number : 2188 |
Description
Add the following ticker modifications for NRF5x boards:
Most of these changes have been proposed by @marcuschangarm. Can you review this PR?
Pull request type