/* If a context switch is pending or a task is waiting for the scheduler
to be unsuspended then abandon the low power entry. */
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
{
/* Restart SysTick. */
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;
/* Re-enable interrupts - see comments above the cpsid instruction()
above. */
__asm volatile( "cpsie i" );
}
My understanding from the CM3 core documentation is that writing NVIC_SYSTICK_ENABLE_BIT will reload the value from the SYSTICK_LOAD_REG and start counting down. Thus if the entry into sleep mode is aborted, the SYS_TICK interval is restarted, loosing any of the tick period that has elapsed so far.
Given the amount of effort expended in trying to correct for lost clocks to the SYS_TICK timer when it is disabled and then re-enabled when the tick-less period is generated by extending the SYS_TICK period, this seems like a bit of an oversight. I therefore expect I’ve missed a subtlety in the implementation.
Can someone (Richard?) explain what I’ve missed and why restarting the SYS_TICK timer without making a prior adjustment to the reload register is OK?
Thanks,Phil.