AnsweredAssumed Answered

KL82 low power mode in RTX

Question asked by Diandi Zhu on Nov 30, 2016
Latest reply on Jan 10, 2017 by knishi

Hi there,

I tried to write some code to make kl82 enter to lls3 in RTX. Here is my code:

volatile uint32_t tc;
volatile uint32_t tc_weakup;
volatile uint8_t lp_sleep = 0;
void LPTMR1_IRQHandler()
{
        if (kLPTMR_TimerInterruptEnable & LPTMR_GetEnabledInterrupts(LPTMR1))
        {
                LPTMR_DisableInterrupts(LPTMR1, kLPTMR_TimerInterruptEnable);
                LPTMR_ClearStatusFlags(LPTMR1, kLPTMR_TimerCompareFlag);
                LPTMR_StopTimer(LPTMR1);
        }
}

void LLWU_IRQHandler(void)
{
    /* If wakeup by LPTMR. */

        tc = 0;
        //LPTMR_DisableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
        if (LPTMR1->CSR >> 7 )
        {
                INTMUX_DisableInterrupt(INTMUX0, 0, LPTMR1_IRQn);
                LPTMR_ClearStatusFlags(LPTMR1, kLPTMR_TimerCompareFlag);
                LPTMR_StopTimer(LPTMR1);
                NVIC_EnableIRQ(LPTMR0_IRQn);
        }



}



/// \brief The idle demon is running when no other thread is ready to run
void os_idle_demon (void) {

  for (;;) {
//        __WFI();
          tc_weakup = os_suspend();
          if (tc_weakup > 0)
          {
                  lptmr_config_t lptmrConfig;
                  /* Setup LPTMR. */
                  LPTMR_GetDefaultConfig(&lptmrConfig);
                  /* Use LPO as clock source. */
                  lptmrConfig.prescalerClockSource = kLPTMR_PrescalerClock_1;
                  lptmrConfig.bypassPrescaler = true;
                  LPTMR_Init(LPTMR1, &lptmrConfig);
                  INTMUX_Init(INTMUX0);
                  INTMUX_SetChannelMode(INTMUX0, 0, kINTMUX_ChannelLogicOR);
                  INTMUX_EnableInterrupt(INTMUX0, 0, LPTMR1_IRQn);

                  LPTMR_SetTimerPeriod(LPTMR1, tc_weakup - 1U);
                  LPTMR_StartTimer(LPTMR1);
                  LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);     

                  LLWU_EnableInternalModuleInterruptWakup(LLWU, 0, true);//Module 0 for lptmr0 and lptmr1
                  NVIC_EnableIRQ(LLWU_IRQn);

                  SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeLls);//dont forget to allow lls mode
                 
                  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);

  }
}

any comments?

 

Thank you very much in advance.

Best Regards,

Outcomes