Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions arch/arm/arm-m/systick/systick.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: delta_ticks reads oddly next to current_ticks / *ticks, which mean timer periods in this file. elapsed_cycles or similar would avoid the overload.

Also worth a one-line comment here that VAL == 0 is 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 and reload maps to 1.

uint32_t delta = delta_ticks / (tick_rate_mhz * 1000);
lk_time_t res = (ticks * tick_interval_ms) + delta;

return res;
Expand All @@ -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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: same expression as in current_time(). It could live once, e.g. have systick_get_ticks_val() return elapsed cycles instead of the raw VAL, so the two callers only differ in the divisor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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;
Expand Down
Loading