littlekernel / lk

LK embedded kernel
MIT License
3.12k stars 613 forks source link

Cortex m0 current_time_hires() can return incorrect result if called with interrupts disabled. #216

Open konkers opened 6 years ago

konkers commented 6 years ago

The cortex m0's systick driver uses a ticks global to accumulate timer overflows. This counter is incremented in the _systick() irq handler. current_time() and current_time_hires() rely on ticks being updated as a way of detecting overflows. If those functions are called with interrupts disabled, the counter can roll without detection. This manifests as time appearing to go backwards.