Skip to content

Commit

Permalink
drivers: timers: systick: Enforce a barrier in _timer_cycle_get_32.
Browse files Browse the repository at this point in the history
The code assumes that when the systick counter hits zero,
the timer interrupt will be taken before the loop can
read the LOAD/VAL registers, but this is not architecturally
guaranteed, and so the code can see a post-reload SysTick->VAL
and a pre-reload clock_accumulated_count, which causes it to
return an incorrectly small cycle count. By adding a ISB we
overcome this issue.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
  • Loading branch information
AdithyaBaglody authored and nashif committed Sep 21, 2018
1 parent 023bc92 commit 36365e3
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions drivers/timer/cortex_m_systick.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ return (u32_t) get_elapsed_count();
#else
count = SysTick->LOAD - SysTick->VAL;
#endif
__ISB();
} while (cac != clock_accumulated_count);

return cac + count;
Expand Down

0 comments on commit 36365e3

Please sign in to comment.