Chapter 3 Introduction to MR308
- 39 -

3.5.6 Synchronization and Communication Function (Eventflag)

The eventflag is an internal facility of MR308 that is used to synchronize the execution of multiple tasks. The
eventflag uses a flag wait pattern and a 16-bit pattern to control task execution. A task is kept waiting until the
flag wait conditions set are met.
It is possible to determine whether multiple waiting tasks can be enqueued in one eventflag waiting queue by
specifying the eventflag attribute TA_WSGL or TA_WMUL.
Furthermore, it is possible to clear the eventflag bit pattern to 0 when the eventflag meets wait conditions by
specifying TA_CLR for the eventflag attribute.
There are following eventflag service calls that are provided by the MR308 kernel.
Set Eventflag (set_flg, iset_flg)
Sets the eventflag so that a task waiting the eventflag is released from the WAITING state.
Clear Eventflag (clr_flg, iclr_flg)
Clears the Eventflag.
Wait for Eventflag (wai_flg, twai_flg)
Waits until the eventflag is set to a certain pattern. There are two modes as listed below in which the
eventflag is waited for.
AND wait
Waits until all specified bits are set.
OR wait
Waits until any one of the specified bits is set
Wait for Eventflag (polling)(pol_flg, ipol_flg)
Examines whether the eventflag is in a certain pattern. In this service call, tasks are not placed in
WAITING state.
Reference Eventflag Status (ref_flg, iref_flg)
Checks the existence of the bit pattern and wait task for the target eventflag.
Figure 3.31 shows an example of task execution control by the eventflag using the wai_flg and set_flg service
calls.
The eventflag has a feature that it can wake up multiple tasks collectively at a time.
In Figure 3.31, there are six tasks linked one to another, task A to task F. When the flag pattern is set to 0xF by
the set_flg service call, the tasks that meet the wait conditions are removed sequentially from the top of the
queue. In this diagram, the tasks that meet the wait conditions are task A, task C, and task E. Out of these tasks,
task A, task C, and task E are removed from the queue.
If this event flag has a TA_CLR attribute, when the waiting of Task A is canceled, the bit pattern of the event flag
will be set to 0, and Task C and Task E will not be removed from queue.