Datasheet

Adding Tasks
A task ( os_task ) in Mynewt is made up of a task handler function, a task 'stack' which provide the block of memory
that will be used when executing the task, and a priority level.
Since Mynewt is a multitasking environment, tasks are also assigned a priority level, and at any given time the highest
priority task will run. When the highest priority task stops (waiting for an event, or when delayed in code) the next
highest priority task will fire, and so on until the scheduler gets down to the lowest priority task, usually called 'idle'
(which will be set by the kernel when the OS starts up).
Declaring a task, priority and stack size
In order to declare a task, you need to set the task's:
priority
stack size
and the name of the task handler that will be run when the task is active.
The task's priority can be from 1..255, where the higher the number the lower the priority.
The stack size is in units of os_stack_t , which is usually a 32-bit value, meaning a stack size of 64 (as shown in the
example below) is 256 bytes wide.
The task handler has the following signature: void my_task_func(void *arg)
Initializing a task
To initialize the task, you need to call the sysinit() function then add your task to the os via: os_task_init . This
normally takes place in the main loop, or in a dedicated function called inside main like init_tasks() .
os_task_init has the following signature and parameters:
struct os_task *t : A pointer to the os_task to initialize
const char *name : The public name to associate with this task, which will be visible in the shell, newtmgr, and
other reporting systems.
The official Mynewt 'Task' documentation is available at:
https://mynewt.apache.org/latest/os/core_os/task/task.html
/* Define task stack and task object */
#define MY_TASK_PRIO (OS_TASK_PRI_HIGHEST)
#define MY_STACK_SIZE OS_STACK_ALIGN(64)
struct os_task my_task;
os_stack_t my_task_stack[MY_STACK_SIZE];
os_task_init(struct os_task *t, const char *name, os_task_func_t func,
void *arg, uint8_t prio, os_time_t sanity_itvl,
os_stack_t *stack_bottom, uint16_t stack_size)
© Adafruit Industries https://learn.adafruit.com/adafruit-nrf52-pro-feather Page 53 of 87