cortex_m_systick: fix _timer_cycle_get_32() race
We need to account for the interrupt happening in the middle of the calculation. Issue: ZEP-1546 Change-Id: I193534856d7521cac7ca354d3e5b65e93b984bb1 Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
1839cabe14
commit
b8d57738b8
1 changed files with 9 additions and 2 deletions
|
@ -28,7 +28,7 @@
|
||||||
#include <arch/arm/cortex_m/cmsis.h>
|
#include <arch/arm/cortex_m/cmsis.h>
|
||||||
|
|
||||||
/* running total of timer count */
|
/* running total of timer count */
|
||||||
static uint32_t clock_accumulated_count;
|
static volatile uint32_t clock_accumulated_count;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A board support package's board.h header must provide definitions for the
|
* A board support package's board.h header must provide definitions for the
|
||||||
|
@ -559,7 +559,14 @@ int _sys_clock_driver_init(struct device *device)
|
||||||
*/
|
*/
|
||||||
uint32_t _timer_cycle_get_32(void)
|
uint32_t _timer_cycle_get_32(void)
|
||||||
{
|
{
|
||||||
return clock_accumulated_count + (SysTick->LOAD - SysTick->VAL);
|
uint32_t cac, count;
|
||||||
|
|
||||||
|
do {
|
||||||
|
cac = clock_accumulated_count;
|
||||||
|
count = SysTick->LOAD - SysTick->VAL;
|
||||||
|
} while (cac != clock_accumulated_count);
|
||||||
|
|
||||||
|
return cac + count;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_SYSTEM_CLOCK_DISABLE
|
#ifdef CONFIG_SYSTEM_CLOCK_DISABLE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue