« Previous - Version 4/45 (diff) - Next » - Current version
Anthony Rowe, 06/08/2007 08:08 pm

= Signals And Semaphores =


A signal is a message that a task can use to wakeup one or more tasks waiting on an
event or events. When waiting on an event, a task is suspended and does not consume
CPU time. Nano-RK supports 32 unique signals. It is possible to wait on multiple
signals such that any one of them can wake a task from sleep. All signals must be
created and registered before they can be used.

A semaphore is a protected variable and constitutes the classic method for restricting
access to shared resources (e.g. storage,actuators etc) in a multiprogramming environment.
Signals are used to allow one task to wakeup another task (or tasks) that
are suspended on an event. Nano-RK implements semaphores and signals such that
tasks that are suspended on an event or waiting for access to a semaphore will not be
scheduled until the corresponding signal is sent or semaphore becomes available.

'''nrk_sig_mask_t nrk_get_active_signal_mask();'''

'''int8_t nrk_delete_signal(nrk_sig_t sig_id);'''

'''int8_t nrk_signal_unregister(nrk_sig_t sig_id);'''

'''int8_t nrk_signal_register(nrk_sig_t sig_id);'''

'''nrk_sig_t nrk_signal_create();'''

'''int8_t nrk_event_signal(nrk_sig_t sig_id);'''

This function is used to signal tasks that are waiting on events using nrk_event_wait().
See example below.

'''nrk_sig_mask_t nrk_event_wait(nrk_sig_mask_t event_mask);'''

This function will wait for a set events. nano-RK supports up to 31 signals. Each signal
represents a bit in a 32 bit number (bit 0 is reserved) so it is possible to logically
OR multiple signals together if you wish to wait on a combination of events. The 32
bit number returned by nrk_event_wait() corresponds to the signal that was returned.
When waiting on multiple signals, this should be used to determine which signal actually
triggered the wakeup. All signals should be defined in the nrk_cfg.h file for each

'''nrk_sem_t* nrk_sem_create(uint8_t count, uint8_t ceiling_prio);'''

This function creates a semaphore resource, with a priority ceiling for PCPE. It allows
you to specify number of entries allowed into the critical section and set a priority
ceiling on the critical section to allow the system to implement Priority Ceiling Protocol
Emulation. count sets the number of entities that are able to access the critical section
specified by the semaphore. task_hi_prio sets the ceiling value for the task; Note if
using PCPE this should be the highest priority task accessing the critical section.

'''int8_t nrk_sem_post(nrk_sem_t* rsrc);'''

Semaphore post simply takes the address of the created semaphore and posts the semaphore.
This should be called after exiting the critical section. This allows other tasks to access
the protected region.

'''int8_t nrk_sem_pend(nrk_sem_t *rsrc );'''

Semaphore pend simply takes the address of the created semaphore and pends the
semaphore. Its intention is to protect critical sections of code. This will cause the task
to go to a suspended state if the semaphore count is violated by allowing access into
the critical section.

[wiki:nrk-api Contents] [wiki:nrk-api-device-drivers Device Drivers]