tickless idle mode

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

tickless idle mode

András Szemző
Hi,

I try to implement tickless idle operation for NutOS. I’m using a stripped down NutOS (just the kernel, without vfs, net, configurator,c runtime etc) on Microchip/Atmel SAMD21 Cortex-m0+.
What I do is in the IDLE thread, I added a call to a function which have to calculate the next event from the timer list:

uint32_t NutIdleEventNext(void)
{
    NUTTIMERINFO *tn = nutTimerList;
    uint32_t ticks_sleep = UINT32_MAX;

        while (tn != NULL) {

            if ( tn->tn_ticks_left < ticks_sleep)
                ticks_sleep = tn->tn_ticks_left;

            tn = tn->tn_next;
        }

        return ticks_sleep;
}

It is possible to further tuning this function, to do not sleep if ticks_sleep < XXX, or something like that, but now it’s that simple.
The idle thread:

    for (;;) {

        /* Check if other threads became ready to run. */
        NutThreadYield();

        /* Remove terminated threads. */
        NutThreadDestroy();

#ifdef NUT_TICKLESS_IDLE
        vPortSuppressTicksAndSleep(NutIdleEventNext());
#endif
    }


The vPortSuppressTicksAndSleep is the timer setup function for sleep mode (yes, the name is from FreeRTOS).
I use the SAMD21’s timer4/5 in 32bit mode, and I use that for system tick (instead of Cortex's SYSTICK), and for the sleep counter with a ultra low power internal OSC.


After wakeup, I calculate the time we slept and fast-forward NutOS time with a function:

static void vTaskStepTick(uint32_t idle_time)
{
        nut_ticks += idle_time;
}

In the function vPortSuppressTicksAndSleep() after I stop the system tick timer, I disable the interrupts before sleep, and make a last check,
if any interrupt is fired (and any thread has to wake up with call NutEventPostFromIrq(xxx) ), something like that:

        /* Enter critical section */
        asm volatile( "cpsid i" ::: "memory" );
        asm volatile( "dsb" );
        asm volatile( "isb" );

        if (total_pending != 0) {
               
            system_tick_resume(); /* resume NutOS system tick timer */

            /* Leave critical section */
            asm volatile( "cpsie i" ::: "memory" );
            asm volatile( "dsb" );
            asm volatile( "isb" );

            NutThreadResume(); /* allow woken up thread to schedule */
            return;
        }

With this setup my power consumption is a few uA with NutOS at sleep.
Am I missing something? Is there any other implementation of tickeless mode for NutOS?

Regards,
Andras



_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion
Reply | Threaded
Open this post in threaded view
|

Re: tickless idle mode

Uwe Bonnes
Andras Szemzo writes:
> Hi,
>
> I try to implement tickless idle operation for NutOS. I’m using a
> stripped down NutOS (just the kernel, without vfs, net,
> configurator,c runtime etc) on Microchip/Atmel SAMD21 Cortex-m0+.  
> What I do is in the IDLE thread, I added a call to a function which
> have to calculate the next event from the timer list:
That sounds very interesting.
>
> ...
>
> With this setup my power consumption is a few uA with NutOS at
> sleep.

Are you using a sleep deeper than WFI/WFE?
Do all peripherals still work in that mode?

For STM32, type, peripheral and peripheral clock type decide if some
peripheral stillworks in sleep modes deeper than WFI/WFE.

> Am I missing something?
>Is there any other implementation of tickeless mode for NutOS?
Nothing that I know of.

Pleasekeep us informed.

Bye

--
Uwe Bonnes                [hidden email]

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion
Reply | Threaded
Open this post in threaded view
|

Re: tickless idle mode

András Szemző

> On 2018. Dec 3., at 13:39, [hidden email] wrote:
>
> Are you using a sleep deeper than WFI/WFE?
> Do all peripherals still work in that mode?
>

For SAMD21 I have an ACTIVE, IDLE0-2, and STANDBY sleep modes.
I use the STANDBY mode for achive the lowest power consumption.

There are several clock  sources (like 8MHz internal OSC, external OSC, 32KHz external OSC, 32KHz ultra low power external OSC etc)
and glock generators, where you can assign clock sources for them, and periperals can be mapped to clock generators)
(you can decide what peripherals/clock generators needs to run in sleep mode)

In my application, I use a 32bit timer with internal 32KHz ultra low power OSC for NutOS tick (with 1024 tick / sec),
and reprogrammed to use it as a sleep timer (for long timeouts).
I don’t need other peripherial in sleep mode, just the timer, and the external interrupt controller for wake up)

> For STM32, type, peripheral and peripheral clock type decide if some
> peripheral stillworks in sleep modes deeper than WFI/WFE.
>

Basically the same as SAMD21.

>> Am I missing something?
>> Is there any other implementation of tickeless mode for NutOS?
> Nothing that I know of.
>
> Pleasekeep us informed.
>

Beside this application, (where I read a few sensors and have a multi-master RS485 with a few GPIOs) my next
use case will be a WINC1500 WiFI SoC with NutOS/Net + MQTT client.
(This application is working, but I would like to use the WINC1500 in bypass mode)

Do anybody has a very simple Ethernut DHCP server, to use at WiFI AP mode? :)




_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion
Reply | Threaded
Open this post in threaded view
|

Re: tickless idle mode

Uwe Bonnes
Dear Andreas,

if have something you want in the main tree, please let be know.

Bye

B.t.w. in a similar situation with long periods of inactivity I programmed
the RTC wakeup, put the device into deep sleep and on wakeup started
from reset.

Bye

--
Uwe Bonnes                [hidden email]

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion
Reply | Threaded
Open this post in threaded view
|

Any NutOs DHCP Server? was: Re: tickless idle mode

Uwe Bonnes
In reply to this post by András Szemző
Andras Szemzo writes:
...
> Do anybody has a very simple Ethernut DHCP server, to use at WiFI AP mode? :)

Hello Andreas,

I don't know about a DHCP server for NutOs. I mostly work with CAN
communication.

I changed the subject. Perhaps others have done something similar and did
not read the original question buried deep down in another subject.

Bye

--
Uwe Bonnes                [hidden email]

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion