@@ -154,8 +154,10 @@ extern void xPortSysTickHandler (void);
154154 SysTick handler implementation that also clears overflow flag.
155155*/
156156void SysTick_Handler (void ) {
157+ #if (configUSE_TICKLESS_IDLE == 0 )
157158 /* Clear overflow flag */
158159 SysTick -> CTRL ;
160+ #endif
159161
160162 if (xTaskGetSchedulerState () != taskSCHEDULER_NOT_STARTED ) {
161163 /* Call tick handler */
@@ -474,17 +476,35 @@ uint32_t osKernelGetSysTimerCount (void) {
474476 uint32_t irqmask = IS_IRQ_MASKED ();
475477 TickType_t ticks ;
476478 uint32_t val ;
479+ #if (configUSE_TICKLESS_IDLE != 0 )
480+ uint32_t val0 ;
481+
482+ /* Low Power Tickless Idle controls timer overflow flag and therefore */
483+ /* OS_Tick_GetOverflow may be non-functional. As a workaround a reference */
484+ /* time is measured here before disabling interrupts. Timer value overflow */
485+ /* is then checked by comparing reference against latest time measurement. */
486+ /* Timer count value returned by this method is less accurate but if an */
487+ /* overflow is missed, an invalid timer count would be returned. */
488+ val0 = OS_Tick_GetCount ();
489+ #endif
477490
478491 __disable_irq ();
479492
480493 ticks = xTaskGetTickCount ();
481494 val = OS_Tick_GetCount ();
482495
483496 /* Update tick count and timer value when timer overflows */
497+ #if (configUSE_TICKLESS_IDLE != 0 )
498+ if (val < val0 ) {
499+ ticks ++ ;
500+ }
501+ #else
484502 if (OS_Tick_GetOverflow () != 0U ) {
485503 val = OS_Tick_GetCount ();
486504 ticks ++ ;
487505 }
506+ #endif
507+
488508 val += ticks * OS_Tick_GetInterval ();
489509
490510 if (irqmask == 0U ) {
0 commit comments