Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Tickless idle atmel sam3x device

Posted by wlauer on November 20, 2014

I've been experimenting with the tickless idle functionality and have a few questions. I need to put our device into a lower power mode which involves changing the main clock speed to a lower value and restoring it upon waking. I've figured out all the details and it works as expected.

But I ran into an issue where the device would enter sleep mode while waiting on peripherals to complete. Unfortunately when entering sleep the resulting change in the main clock also changes affects the peripherals operation. So I modified the sleepmgr code that atmel provides to provide a locking mechanism around the code that deals with the peripherals.

As you can see I wrapped a mutex around a variable array that keeps the lock count for various depths of sleeping. So I though I would put the call sleepmgrgetsleepmode() to determine if we should sleep or not into the portSUPPRESSTICKSANDSLEEP call only to realize that portSUPPRESSTICKSAND_SLEEP is just another hook into the Idle task which can have no blocking calls.

How should I be handling this? How do i get around not blocking in the idle task?

Thanks in advance, Bill

a snippet of the sleepmgr code:

static inline void sleepmgrinit(void) { uint8t i;

/* semaphore used to access the sleep level as it is written to from more than one task. */
sleepmgr_mutex = xSemaphoreCreateMutex();
xSemaphoreTake(sleepmgr_mutex, portMAX_DELAY);

for (i = 0; i < SLEEPMGR_NR_OF_MODES - 1; i++) {
	sleepmgr_locks[i] = 0;
sleepmgr_locks[SLEEPMGR_NR_OF_MODES - 1] = 1;


static inline void sleepmgrlockmode(enum sleepmgrmode mode) { Assert(sleepmgrlocks[mode] < 0xff); xSemaphoreTake(sleepmgrmutex, portMAXDELAY); ++sleepmgrlocks[mode]; xSemaphoreGive(sleepmgrmutex); }

static inline enum sleepmgrmode sleepmgrgetsleepmode(void) { xSemaphoreTake(sleepmgrmutex, portMAXDELAY); enum sleepmgrmode sleepmode = SLEEPMGR_ACTIVE;

uint8_t *lock_ptr = sleepmgr_locks;
// Find first non-zero lock count, starting with the shallowest modes.
while (!(*lock_ptr)) {

// Catch the case where one too many sleepmgr_unlock_mode() call has been
// performed on the deepest sleep mode.
Assert((uintptr_t)(lock_ptr - sleepmgr_locks) < SLEEPMGR_NR_OF_MODES);

return sleep_mode;


Tickless idle atmel sam3x device

Posted by davedoors on November 21, 2014

The semaphore is probably only needed when changing the lock count. So tasks that update the lock count could use the functions with the mutex, and the idle task could use a function without a mutex just to read the lock counts as long is it does not change them. Would that work for you?

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists