AnsweredAssumed Answered

Low power and freertos

Question asked by PO220 on Feb 17, 2018

HI everybody

I make an application on a KL27 with freertos and LLS. It works but I'm at the same point as whata at the end of this Tickless Freertos and LLS mode : ulLPTimerInterruptFired was being set too early.

 

I have started from demo Tickless for Freertos.

As shown in the freertos documentation I defined the 2 macros (configPRE_SLEEP_PROCESSING and configPOST_SLEEP_PROCESSING in FreeRTOSconfig.h with :

#define configPRE_SLEEP_PROCESSING(x)     x = 0; myConfigPRE_SLEEP_PROCESSING() // x=0 to not execute the 3 asm lines in fsl_tickless_lptmr.c
#define configPOST_SLEEP_PROCESSING(x)     myConfigPOST_SLEEP_PROCESSING(x)

 

and file myLOWPWR.c with

void myConfigPRE_SLEEP_PROCESSING()
{
    smc_power_mode_lls_config_t lls_config    = {.enableLpoClock=1 };

    PRINTF("sleep!!!\r\n");

    DbgConsole_Deinit(); //arret du debug console
    PORT_SetPinMux(DEBUG_CONSOLE_RX_PORT, DEBUG_CONSOLE_RX_PIN, kPORT_PinDisabledOrAnalog);

     /* Set up LLWU to receive interrupts from LPTMR=0U */
     LLWU_EnableInternalModuleInterruptWakup(LLWU, LLWU_LPTMR_IDX, true);
     NVIC_EnableIRQ(LLWU_IRQn);

 

        SMC_PreEnterStopModes();
        SMC_SetPowerModeLls(SMC, &lls_config);
        SMC_PostExitStopModes();
}

 

 

void myConfigPOST_SLEEP_PROCESSING(uint32_t xModifiableIdleTime)
{
        /* Re-enable console */
        PORT_SetPinMux(DEBUG_CONSOLE_RX_PORT, DEBUG_CONSOLE_RX_PIN , kPORT_MuxAlt5);            /* PORTE30 is configured as LPUART1_TX */
        BOARD_InitDebugConsole();

 

    PRINTF("Wup!!!\r\n");
}

 

 

 

void LLWU_IRQHandler(void)
{
    /* If wakeup by LPTMR. */
    if (LLWU_GetInternalWakeupModuleFlag(LLWU, LLWU_LPTMR_IDX))
    {
        vPortLptmrIsr(); // is in fsl_tickless_lptmr.c
    }
}

 

With this, we go well on sleep and the weakup is working too but

    void vPortLptmrIsr(void)
    {
        ulLPTimerInterruptFired = true; //<= this
        LPTMR_ClearStatusFlags(vPortGetLptrmBase(), kLPTMR_TimerCompareFlag);
    }

is executed before

ulLPTimerInterruptFired = false;

in fsl_tickless_lptmr.c

 

Because of this the test

if( ulLPTimerInterruptFired )
            {

                ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
                ulLPTimerInterruptFired = false;
            }
            else
            {
                /* Something other than the tick interrupt ended the sleep.
                Work out how long the sleep lasted rounded to complete tick
                periods (not the ulReload value which accounted for part
                ticks). */
                ulCompleteTickPeriods = LPTMR_GetCurrentTimerCount(pxLptmrBase);

            }

prevents the good recovery of tickless freertos.

 

I solved the problem by setting the initialization of ulLPTimerInterruptFired  earlier

 

This obliges me to modify the file of freertos (fsl_tickless_lptmr.c) and I am afraid that it hides something...

 

>>Why  low power interrupt activate ulLPTimerInterruptFired earlier than the same without low power (jsute tickless) ?

>>how to fix this without changing fsl_tickless_lptmr.c ?

 

Thanks in advance

Outcomes