-
Notifications
You must be signed in to change notification settings - Fork 2.1k
sys: make xtimer isr-safe #5428
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7e147d4
WIP: make xtimer ISR safe
kaspar030 d88e1c0
tests, examples: adapt to 64bit xtimer_usleep_until() argument
kaspar030 c741b41
REMOVEME: simple tets_xtimernow_continuity
kaspar030 216431e
fixup! WIP: make xtimer ISR safe
kaspar030 3defd4b
fixup! fixup! WIP: make xtimer ISR safe
kaspar030 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,8 +31,11 @@ extern "C" { | |
|
|
||
| #if XTIMER_MASK | ||
| extern volatile uint32_t _xtimer_high_cnt; | ||
| #define XTIMER_PERIOD_LENGTH XTIMER_TICKS_TO_USEC(~XTIMER_MASK + 1) | ||
| #endif | ||
|
|
||
| #define XTIMER_MSBMASK (((uint32_t)1)<<(XTIMER_WIDTH - 1 + XTIMER_SHIFT)) | ||
|
|
||
| #if (XTIMER_SHIFT < 0) | ||
| #define XTIMER_USEC_TO_TICKS(value) ( (value) << -XTIMER_SHIFT ) | ||
| #define XTIMER_TICKS_TO_USEC(value) ( (value) >> -XTIMER_SHIFT ) | ||
|
|
@@ -71,7 +74,7 @@ static inline uint32_t _xtimer_lltimer_mask(uint32_t val) | |
| * @brief xtimer internal stuff | ||
| * @internal | ||
| */ | ||
| int _xtimer_set_absolute(xtimer_t *timer, uint32_t target); | ||
| void _xtimer_set_absolute(xtimer_t *timer); | ||
| void _xtimer_set64(xtimer_t *timer, uint32_t offset, uint32_t long_offset); | ||
| void _xtimer_sleep(uint32_t offset, uint32_t long_offset); | ||
| /** @} */ | ||
|
|
@@ -89,18 +92,26 @@ void _xtimer_sleep(uint32_t offset, uint32_t long_offset); | |
| static inline uint32_t xtimer_now(void) | ||
| { | ||
| #if XTIMER_MASK | ||
| uint32_t latched_high_cnt, now; | ||
|
|
||
| /* _high_cnt can change at any time, so check the value before | ||
| * and after reading the low-level timer. If it hasn't changed, | ||
| * then it can be safely applied to the timer count. */ | ||
|
|
||
| do { | ||
| latched_high_cnt = _xtimer_high_cnt; | ||
| now = _xtimer_lltimer_now(); | ||
| } while (_xtimer_high_cnt != latched_high_cnt); | ||
|
|
||
| return latched_high_cnt | now; | ||
| uint32_t high_cnt = _xtimer_high_cnt; | ||
| uint32_t now = _xtimer_lltimer_now(); | ||
|
|
||
| /* _xtimer_high_cnt and the underlying hardware timer both count the most | ||
| * significant bit of the underlying hardware timer. | ||
| * | ||
| * Should the counter variable indicate we're in the first half of the | ||
| * hardware timer period, but the hardware timer indicates otherwise, the | ||
| * OR handles the missed interrupt. | ||
| * | ||
| * Should the counter variable indicate we're in the second half of the | ||
| * hardware timer period, but the actual timer value does not, we | ||
| * compensate by adding a half timer period. | ||
| * | ||
| * That way, timer overflow interrupts which are up to half a timer period | ||
| * late can be compensated for. | ||
| */ | ||
|
|
||
| return (high_cnt | now) + | ||
| ((uint32_t)((high_cnt & (XTIMER_MSBMASK)) && (~now & XTIMER_MSBMASK))) * (XTIMER_PERIOD_LENGTH >> 1); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not simply |
||
| #else | ||
| return _xtimer_lltimer_now(); | ||
| #endif | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
all of these last_wakeup changes should use
xtimer_now64(). Not because I expect the startup of the example code to take more than 71 minutes, but because the examples will be copied by users who may use them in a different context than the original example was written for, where the last_wakeup may be initialized after the system has been running for 71 minutes.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.