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 sleepmgr
getsleep
mode() to determine if we should sleep or not into the portSUPPRESSTICKS
ANDSLEEP call only to realize that portSUPPRESS
TICKSAND_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 sleepmgr
init(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;
xSemaphoreGive(sleepmgr_mutex);
}
static inline void sleepmgr
lockmode(enum sleepmgr
mode mode)
{
Assert(sleepmgrlocks[mode] < 0xff);
xSemaphoreTake(sleepmgr
mutex, portMAXDELAY);
++sleepmgr
locks[mode];
xSemaphoreGive(sleepmgrmutex);
}
static inline enum sleepmgr
mode sleepmgrget
sleepmode(void)
{
xSemaphoreTake(sleepmgr
mutex, portMAXDELAY);
enum sleepmgr
mode sleepmode = SLEEPMGR_ACTIVE;
uint8_t *lock_ptr = sleepmgr_locks;
// Find first non-zero lock count, starting with the shallowest modes.
while (!(*lock_ptr)) {
lock_ptr++;
sleep_mode++;
}
// 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);
xSemaphoreGive(sleepmgr_mutex);
return sleep_mode;
}