This is the preferred order of initialization. It is crucial that the clock tick is not started before the tasks
are created and the kernel is initialized. The os_start
() calls the macro os_enable_interrupts() which can be defined
to start the clock tick driving the OS.
cocoOS keeps track of time by counting ticks and you must feed the counting with a call to os_tick
from the clock tick ISR.
A system of one main clock and several sub clocks is used in cocoOS. The main clock is typically realized
using one of the hardware timers within your target microcontroller which calls the os_tick
() function that
If your application does not need more than a single time base, the main clock fed by the os_tick
() call is
In case your application has to react to events in another time resolution than what is provided by the main
clock, you can use the sub clocks. The sub clocks are typically not associated with a hardware timer, but is
instead "ticked" by calling os_sub_tick
) from within your application code.
Sub clocks can also be advanced with a step greater than one using os_sub_nTick
, nTicks). There is one
task function associated with the sub clocks: task_wait_id
is a value in the range 1-255
assigned by the application, and ticks is the number of ticks to wait. An example of the use of sub clocks
could be a task that should be run after 64 bytes has been received on the UART. The task starts the wait by
An application is built up by a number of tasks. Each task is a associated with a (preferably short
procedure with a well defined purpose. The execution of the tasks, is managed by the os kernel, by letting
the highest priority task among all execution ready tasks to execute. All tasks have to make at least
one blocking call to a sheduling kernel function. This gives lower priority tasks a chance to execute.
The task procedure must enclose its code with the task_open
() and task_close
() macros, as shown below.
Such a task will be executed once only. If a task is intended to be executed "for ever"
, an endless loop
105 static void
When a task has finished it gives the CPU control to another task by calling one of the scheduling
Normally the scheduler will give the cpu to the highest priority task ready for execution. It is possible to
choose a round robin scheduling algorithm by putting the following line in os_defines.h:@n
This will make the scheduler to scan the list of tasks and run the next found task in the ready state.
#define msg_post_every(task, msg, period)
#define msg_post(task, msg)
uint8_t task_create(taskproctype taskproc, uint8_t prio, Msg_t *msgPool, uint8_t poolSize, uint16_t msgSize)
#define msg_receive(task, pMsg)
void os_sub_nTick(uint8_t id, uint16_t nTicks)
#define event_wait_multiple(waitAll, args...)
Sem_t sem_bin_create(uint8_t initial)
#define task_wait_id(id, x)
#define msg_post_in(task, msg, delay)
void os_sub_tick(uint8_t id)
#define event_wait_timeout(event, timeout)