Datasheet

os_task_funct_t func : The function to execute when this task is active, which will have the following
signature: void my_task_handler(void *arg)
void *arg : Optional arguments to pass into the task handler
uint8_t prio : The priority level for the task, lower = higher priority
os_time_t sanity_itvl : The time at which this task should check in with the sanity
task. OS_WAIT_FOREVER means never check in.
os_stack_t *stack_bottom : A pointer to the bottom of a task's stack.
uint16_t stack_size : The size of the task's stack (in os_stack_t units), which are usually 32-bits.
The following examples initialises a task matching the values declared earlier in this document:
Implementing the task handler
The last part of the system is the task handler, which will be called every time that the task is active (as determined by
the scheduler).
Task handlers are infinite loops that have an initial setup face, and then normally a while(1) loop that runs forever as
long as the task is active.
The following example initialises a GPIO pin as an output, setting the pin high. It then starts an infinite loop and toggles
the LED every second, sleeping between 1s intervals so that other tasks can run:
/* This is the main function for the project */
int main(void) {
int rc;
/* Initialize OS */
os_init();
/* Initialize the task */
os_task_init(&my_task, "my_task", my_task_func, NULL, MY_TASK_PRIO,
OS_WAIT_FOREVER, my_task_stack, MY_STACK_SIZE);
/* Start the OS */
os_start();
/* os start should never return. If it does, this should be an error */
assert(0);
return rc;
}
Note that there are two parts to the task handler. An initial chunk of code that will be run once when the task
is initialized, then a 'while (1)' loop that will be run in repetition whenever the task has focus in the scheduler.
© Adafruit Industries https://learn.adafruit.com/adafruit-nrf52-pro-feather Page 54 of 87