static void lptmr_isr(void) { LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag); LPTMR_StopTimer(LPTMR0); lp_ticker_irq_handler(); }
void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) { uint32_t ulReloadValue, ulCompleteTickPeriods; TickType_t xModifiableIdleTime; LPTMR_Type *pxLptmrBase; pxLptmrBase = vPortGetLptrmBase(); if (pxLptmrBase == 0) return; /* Make sure the SysTick reload value does not overflow the counter. */ if( xExpectedIdleTime > xMaximumPossibleSuppressedTicks ) { xExpectedIdleTime = xMaximumPossibleSuppressedTicks; } if (xExpectedIdleTime == 0) return; /* Calculate the reload value required to wait xExpectedIdleTime tick periods. -1 is used because this code will execute part way through one of the tick periods. */ ulReloadValue = LPTMR_GetCurrentTimerCount(pxLptmrBase) + ( ulLPTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) ); /* Stop the LPTMR and systick momentarily. The time the LPTMR and systick is stopped for is accounted for as best it can be, but using the tickless mode will inevitably result in some tiny drift of the time maintained by the kernel with respect to calendar time. */ LPTMR_StopTimer(pxLptmrBase); *(portNVIC_SYSTICK_CTRL) &= ~portNVIC_SYSTICK_ENABLE_BIT; /* Enter a critical section but don't use the taskENTER_CRITICAL() method as that will mask interrupts that should exit sleep mode. */ __asm volatile( "cpsid i" ); /* 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 from whatever is left in the count register to complete this tick period. */ *(portNVIC_SYSTICK_LOAD) = portNVIC_SYSTICK_CURRENT_VALUE_REG; /* Restart SysTick. */ *(portNVIC_SYSTICK_CTRL) |= portNVIC_SYSTICK_ENABLE_BIT; /* Reset the reload register to the value required for normal tick periods. */ *(portNVIC_SYSTICK_LOAD) = ulTimerCountsForOneTick - 1UL; /* Re-enable interrupts - see comments above __disable_interrupt() call above. */ __asm volatile( "cpsie i" ); }