Keil™, An ARM® Company

RTX51 Tiny User's Guide

Events

Events in a real-time operating system may be used to control the execution of tasks in the program. A task may wait for an event or may set event flags for other tasks.

The os_wait function allows a task to wait for one or more events.

  • The Timeout is a common event for which a task can wait. A timeout is simply a number of clock ticks. While a task waits for a timeout, other tasks may execute. Once the specified number of timer ticks elapses, the task may continue execution.
  • The Interval is a variation of the Timeout. An interval is like a timeout except that the specified number of clock ticks is relative to the last time the os_wait function was invoked by the task. The Interval may be used to generate a task which is run on a regular, synchronous schedule (like once every second) regardless of how long the task takes between calls to the os_wait function. If the specified number of clock ticks have already elapsed (since the os_wait function was last invoked) the task is re-started immediately—no other tasks execute.
  • A Signal is a simple form of inter-task communication. A task can wait for another task to send it a signal (with the os_send_signal and isr_send_signal functions).
  • Each task has a Ready flag which may be set by other tasks (with the os_set_ready and isr_set_ready functions). A task that is waiting for a timeout, interval, or signal may be started by setting its ready flag.

Each event has an associated event flag that RTX51 Tiny maintains. The following event selectors may be used with the os_wait function to specify what to wait for:

Event SelectorDescription
K_IVLWait for the specified interval.
K_SIGWait for a signal.
K_TMOWait for a specified timeout.

When the os_wait functio returns, the events that occurred are specified by the return value:

Return ValueDescription
RDY_EVENTThe task's ready flag was set.
SIG_EVENTA signal was received.
TMO_EVENTA time-out has completed or an interval has elapsed.

The os_wait function may wait for the following combinations of events:

  • K_SIG | K_TMO: os_wait delays the task until a signal is sent to it or until the specified number of clock ticks has elapsed.
  • K_SIG | K_IVL: os_wait delays the task until a signal is sent to it or until the specified interval has elapsed.

Note

  • The K_IVL and K_TMO event selectors may not be combined.