rtel wrote on Monday, March 27, 2017:
There are several ways of doing this.
You can run the initialisation code before you start the scheduler, but
if you do, be aware that calling any FreeRTOS API functions will leave
interrupts disabled until the scheduler is started. You can manually
re-enable them, but if you do be sure no interrupt service routines
attempt to use any FreeRTOS functions, or force a context switch, until
such time that the scheduler is running.
You can also create an initialisation task, start the scheduler, perform
the initialisation in the created task, then have that task create all
the other tasks needed by your application. The initialisation task
could then either delete itself, or better yet, re-purpose itself and
then perform some application functionality.
Yet another way if you are using software timers (configUSE_TIMERS is
set to 1), and the timer daemon/service task has a priority above any
other tasks, would be to use the vApplicationDaemonTaskStartupHook()
callback. Set configUSE_DAEMON_TASK_STARTUP_HOOK to 1 in
FreeRTOSConfig.h, then provide an implementation of the above function
(it doesn’t take any parameters and returns void), and the function will
get called exactly once when the timer task starts. Provided the
priority of the time task is higher than any other task the callback
function is guaranteed to execute before any application tasks - but of
course you cannot make any blocking calls otherwise the time task will
sleep and one of your application tasks will execute.