The main building block of your application is the task. The tasks should be created in the main function of the application before starting the os. The number of created tasks must not exceed the defined value N_TASKS in os_defines.h. A task is created this way:
The return value, taskId, above is just an uint8_t that can be used to identify the different tasks.
taskProc is a function pointer to the task procedure that is executed when the task is scheduled to run.
prio is the task priority in range 1-254, where 1 is highest priority. The kernel always lets the task with highest priority execute first. There can not be two tasks with same priority.
queue is a pointer to a message queue for the task. If the specified size is 0, no message queue is allocated for the task, and the queue parameter is ignored.
Q_SIZE is the length of the message queue. Set to 0 if no queue should be used.
msgSize is the size of the message type held in the message queue. Ignored of no queue is used.
This task will execute only once. When the task_close() line is executed, the task is put in the killed state and will not be executed again. If the task has to synchronize with some external event, we can put a blocking call in the middle:
This task will run to the event_wait() call and then block. The kernel will schedule other tasks to execute and eventually the event will be signalled which will put the task back to ready state again. Execution will be resumed after the event_wait() call. Once the task_close() statement is reached, the task will be killed and will not be executed again.
If we want a task to be excuted periodically we must put the code into an endless loop:
Another example of a task waiting for characters to be received on the serial port:
The rxEvt may be signalled from the uart ISR using event_ISR_signal(rxEvt).
The task API consists of the following functions and macros: