Here is my latest code for LLWU handler, LPTMR handler and os_idle_deamon thread. I set the OS_SYSTICK to 1, so instead of running RTX systick on LPTMR0, now the kernel is running systick on the ARM Cortex-M processors SysTick timer. It seems use a bit more current than the LPTMR while runing. But my idle is 3ma now instead of 13ma before. I am wondering now, is it possible to setup LLWU to only wakeup when a LPTMR1 interrupt is generated, but ignore LPTMR0 interrupt. I saw the manual says both LPTMR0/1 both belongs to LLWU module 0. But still want to confirm if it is possible.
void LLWU_IRQHandler(void)
{
if (LLWU_GetInternalWakeupModuleFlag(LLWU, 0U))
{
LPTMR_DisableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag);
LPTMR_StopTimer(LPTMR0);
}
}
void LPTMR0_IRQHandler(void)
{
if (kLPTMR_TimerInterruptEnable & LPTMR_GetEnabledInterrupts(LPTMR0))
{
LPTMR_DisableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag);
LPTMR_StopTimer(LPTMR0);
}
}
void os_idle_demon (void) {
for (;;) {
__WFE();
tc_weakup = os_suspend();
if (tc_weakup > 0)
{
tc = 0;
lp_sleep = 1;
lptmr_config_t lptmrConfig;
LPTMR_GetDefaultConfig(&lptmrConfig);
lptmrConfig.prescalerClockSource = kLPTMR_PrescalerClock_1;
lptmrConfig.bypassPrescaler = true;
LPTMR_Init(LPTMR0, &lptmrConfig);
NVIC_EnableIRQ(LLWU_IRQn);
NVIC_EnableIRQ(LPTMR0_IRQn);
LPTMR_SetTimerPeriod(LPTMR0, tc_weakup);
LPTMR_StartTimer(LPTMR0);
LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
LLWU_EnableInternalModuleInterruptWakup(LLWU, 0U, true);
NVIC_EnableIRQ(LLWU_IRQn);
SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeLls);
smc_power_mode_lls_config_t lls_config;
lls_config.subMode = kSMC_StopSub3;
lls_config.enableLpoClock = 1;
SMC_SetPowerModeLls(SMC, &lls_config);
tc = 0;
}
os_resume(tc_weakup);
}
}