Tickless mode for KL25 Kinetis L

ChibiOS public support forum for topics related to the Freescale Kinetis family of micro-controllers.

Moderator: utzig

colin
Posts: 149
Joined: Thu Dec 22, 2011 7:44 pm

Tickless mode for KL25 Kinetis L

Postby colin » Tue Jan 27, 2015 10:41 pm

I wondered if anyone has given thought to how ChibiOS/RT tickless mode could be implemented on the Kinetis L port.

It seems like the LPTMR peripheral would support a tickless kernel. The benefit of LPTMR is that it operates in all low-power modes.

The LPTMR counter is, however, only 16 bits wide. But if we set the systick frequency to 1000 Hz, for instance, this would still allow sleeping for up to about 60 seconds in a stretch. Perhaps it would be possible to have the ChibiOS systick low level driver accommodate this by sleeping for whatever time is necessary in blocks of 60 seconds (or whatever the limit is based on systick frequency).

There is also an RTC peripheral that would appear at first to be a candidate for the tickless systick driver, but it can only alarm at one-second resolution, so it is not really suitable.

Ideally the MCU could be put into a low-power mode when possible, like VLPS or LLS, and the ChibiOS tickless systick driver would continue to keep time and wake up when required. Of course it is another matter altogether to figure out how to determine when to enter and exit the low power mode and perform it correctly.

utzig
Posts: 354
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 16 times
Contact:

Re: Tickless mode for KL25 Kinetis L

Postby utzig » Tue Jan 27, 2015 11:02 pm

Colin,

I wrote the AVR support for tickless and it also uses a 16-bit counter which with the best prescaler option gives a maximum of something like 2 or 3 seconds (I can't recall the right value). But yeah, very short. I talked to Giovanni back then about doing some kind of callback when the timer overflows in a way that the tickless code would re-calculate its internal values. Of course, this would only work if the timer has support for both compare and overflow interrupts. I don't think that is high priority on the list of TODOs though, but I might take a look if I can make it work as soon as I finish some other things.

Anyway having the tickless support would be nice even with the mentioned shortcoming!

Cheers,
Fabio Utzig

User avatar
Giovanni
Site Admin
Posts: 11375
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 429 times
Been thanked: 361 times
Contact:

Re: Tickless mode for KL25 Kinetis L

Postby Giovanni » Wed Jan 28, 2015 9:23 am

There is an easy workaround for this, just write a custom sleep() function that calls chThdSleep() in smaller intervals. It would not be fully tickless but still at a very low tick rate.

This is not very different from the proposed callback, the CPU still is forced to wakeup, but without added complexity.

Giovanni

colin
Posts: 149
Joined: Thu Dec 22, 2011 7:44 pm

Re: Tickless mode for KL25 Kinetis L

Postby colin » Wed Jan 28, 2015 5:36 pm

It seems that a function like sleep() that wraps chThdSleep() would not address every kind of possible sleep? E.g. what if an I/O operation etc. was initiated with a timeout greater than the maximum LPTMR value?

It seems that the best place to implement the timer "chunking" (i.e. sleeping in smaller chunks than actually requested) would best be implemented in a single place, wherever the system ticks are handled, so it can solve the problem universally.

User avatar
Giovanni
Site Admin
Posts: 11375
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 429 times
Been thanked: 361 times
Contact:

Re: Tickless mode for KL25 Kinetis L

Postby Giovanni » Wed Jan 28, 2015 6:30 pm

Good point. I think this could be implemented within the ST driver implementation without modifications outside.

Just make it look like a 32 bits counter (lower half HW, upper half SW) to the system and use a 16 bits timer internally. It could also be done for those STM32s without 32 bits timers.

Giovanni


Return to “Kinetis Support”

Who is online

Users browsing this forum: No registered users and 2 guests