Using the tickless mode I would like to go to deep sleep only when all tasks are blocked with a delay of portMAX_DELAY. I would have expected the xExpectedIdleTime to equal portMAX_DELAY in the call to vPortSuppressTicksAndSleep but it’s not. It appears as if it was portMAX_DELAY but is being decremented with time. I thought tasks blocking with portMAX_DELAY were put on the suspended task list so their block time would not decrement.
I do have INCLUDE_vTaskSuspend 1 and configUSE_TICKLESS_IDLE 1 defined.
In tickless mode the RTOS will configure a clock to generate an
interrupt at the time the scheduler knows a task next needs to run - for
example if a task has called vTaskDelay( 100 ) then the scheduler knows
that task needs to run 100 ticks after the function was called.
However there is a limit to how far in the future it is possible to
generate an interrupt. The limit depends on the number of bits the
clock used to generate the interrupt has, and the speed at which the
clock is running - basically how quickly the clock will overflow. If
you are using the default Cortex-M tickless implementation then the
clock will overflow very quickly because it uses the systick to generate
the tick and the SysTick runs at the system clock speed (normally) and
is limited to 24-bits. You can override the default behaviour to use
whichever clock you like though - and the the official SAM4L tickless
demo does exactly that to enable it to sleep for much much much longer
when the tick is turned off.
If you want to sleep indefinitely then you can use the
eTaskConfirmSleepModeStatus() function to know if this is possible. If
all the tasks are block with a portMAX_DELAY block time and software
timers are not being used then eTaskConfirmSleepModeStatus() will return
eNoTasksWaitingTimeout. I think the RX100 tickless demo does this so
you can look at the source code as a reference. http://www.freertos.org/RX100_RSK_Low_Power_Tick-less_RTOS_Demo.html Be
aware if you do that though that, unless you re-sync with an RTC when
you exit low power mode, the SAM3 device will loose track of time
relative to calendar time. That probably doesn’t matter if you are
sleeping indefinitely though.