Repository navigation
[arch][arm-m][systick] fix elapsed cycle calculation in current_time #545
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,7 +110,8 @@ lk_time_t current_time(void) { | |
| systick_get_ticks_val(&ticks, &val); | ||
|
|
||
| /* convert ticks to msec */ | ||
| uint32_t delta = (reload - val) / (tick_rate_mhz * 1000); | ||
| uint32_t delta_ticks = val ? (reload + 1 - val) : 0; | ||
| uint32_t delta = delta_ticks / (tick_rate_mhz * 1000); | ||
| lk_time_t res = (ticks * tick_interval_ms) + delta; | ||
|
|
||
| return res; | ||
|
|
@@ -125,7 +126,8 @@ lk_bigtime_t current_time_hires(void) { | |
| systick_get_ticks_val(&ticks, &val); | ||
|
|
||
| /* convert ticks to usec */ | ||
| uint32_t delta = (reload - val) / tick_rate_mhz; | ||
| uint32_t delta_ticks = val ? (reload + 1 - val) : 0; | ||
|
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. nit: same expression as in
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. Though these are AI generated this one actually makes the most sense to me. the others are pretty optional. |
||
| uint32_t delta = delta_ticks / tick_rate_mhz; | ||
| lk_bigtime_t res = (ticks * tick_interval_us) + delta; | ||
|
|
||
| return res; | ||
|
|
||
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.
nit:
delta_ticksreads oddly next tocurrent_ticks/*ticks, which mean timer periods in this file.elapsed_cyclesor similar would avoid the overload.Also worth a one-line comment here that
VAL == 0is the cycle between the 1->0 transition and the reload, so the next reader doesn't have to go to the ARM ARM to see why 0 maps to 0 andreloadmaps to 1.