nRF5 SDK v17.1.0
Experimental: Task manager

The task manager is a simple co-operative scheduler. Main features of this library are:

Usage

Task manager is started by calling task_manager_start(). It should be called from main context. Scheduler will execute a task which was first created or idle task if no other task was created before calling task_manager_start().

task_create() creates and activates the task. If task is executed it will not be preempted by other task unless task explicitly triggers task switching. Task switch may be triggered by calling task_yield() or task_events_wait(). If task_yield() is called then task manager will switch to next active task. If there is no active task then switch will not occur. If task_events_wait() is called then context switch will occur if there are no events waiting for the task. task_events_wait() returns mask of events. Events are triggered by calling task_events_set() from any context.

Tasks are identified by task_id_t which is returned by task_create().

Task can be finished only from the task context by calling task_exit(). When task is finished then memory used for task stack is returned to the pool of available tasks.

Efficient power management

Idle task implements power management.

Example idle task implementation:

void idle_task(void * p_context)
{
for(;;)
{
if (NRF_LOG_PROCESS() == false)
{
//No more logs to process, go to sleep
power_manage();
}
//Trigger context switch after any interrupt
}
}

Documentation feedback | Developer Zone | Subscribe | Updated