Everything
5.3 Eventflags
The RI600V4 provides 32-bit eventflags as a queuing function for tasks, such as keeping the tasks waiting for execution, until the results of the execution of a given processing program are output.
The following shows a processing flow when using an eventflag.
Figure 5-2 Processing Flow (Eventflag)
5.3.1 Create eventflag
In the RI600V4, the method of creating an eventflag is limited to "static creation".
Eventflags therefore cannot be created dynamically using a method such as issuing a service call from a processing program.
Static event flag creation means defining of event flags using static API "flag[]" in the system configuration file.
For details about the static API "flag[]", refer to "19.9 Eventflag Information (flag[])".
5.3.2 Set eventflag
A bit pattern is set by issuing the following service call from the processing program.
- set_flg, iset_flg
These service calls set the result of ORing the bit pattern of the eventflag specified by parameter flgid and the bit pattern specified by parameter setptn as the bit pattern of the target eventflag.
After that, these service calls evaluate whether the wait condition of the tasks in the wait queue is satisfied. This evaluation is done in order of the wait queue. If the wait condition is satisfied, the relevant task is unlinked from the wait queue at the same time as bit pattern setting processing. As a result, the relevant task is moved from the WAITING state (WAITING state for an eventflag) to the READY state, or from the WAITING-SUSPENDED state to the SUSPENDED state. At this time, the bit pattern of the target event flag is cleared to 0 and this service call finishes processing if the TA_CLR attribute is specified for the target eventflag.
 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600*/
 
 void task (VP_INT exinf)
 {
     ID      flgid = 1;              /*Declares and initializes variable*/
     FLGPTN  setptn = 0x00000001UL;  /*Declares and initializes variable*/
 
     /* ......... */
 
     set_flg (flgid, setptn);        /*Set eventflag*/
 
     /* ......... */
 }

5.3.3 Clear eventflag
A bit pattern is cleared by issuing the following service call from the processing program.
- clr_flg, iclr_flg
This service call sets the result of ANDing the bit pattern set to the eventflag specified by parameter flgid and the bit pattern specified by parameter clrptn as the bit pattern of the target eventflag.
The following describes an example for coding these service calls.
 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600*/
 
 void task (VP_INT exinf)
 {
     ID      flgid = 1;              /*Declares and initializes variable*/
     FLGPTN  clrptn = 0xFFFFFFFEUL;  /*Declares and initializes variable*/
 
     /* ......... */
 
     clr_flg (flgid, clrptn);        /*Clear eventflag*/
 
     /* ......... */
 }

5.3.4 Check bit pattern
A bit pattern is checked (waiting forever, polling, or with time-out) by issuing the following service call from the processing program.
- wai_flg (Wait)
- pol_flg, ipol_flg (Polling)
- twai_flg (Wait with time-out)
- wai_flg (Wait)
This service call checks whether the bit pattern specified by parameter waiptn and the bit pattern that satisfies the required condition specified by parameter wfmode are set to the eventflag specified by parameter flgid.
If a bit pattern that satisfies the required condition has been set for the target eventflag, the bit pattern of the target eventflag is stored in the area specified by parameter p_flgptn.
If the bit pattern of the target eventflag does not satisfy the required condition when this service call is issued, the invoking task is queued to the target eventflag wait queue.
As a result, the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state (WAITING state for an eventflag).
The WAITING state for an eventflag is cancelled in the following cases.
WAITING State for an Eventflag Cancel Operation
Return Value
A bit pattern that satisfies the required condition was set to the target eventflag as a result of issuing set_flg.
E_OK
A bit pattern that satisfies the required condition was set to the target eventflag as a result of issuing iset_flg.
E_OK
Forced release from waiting (accept rel_wai while waiting).
E_RLWAI
Forced release from waiting (accept irel_wai while waiting).
E_RLWAI

The following shows the specification format of required condition wfmode.
- wfmode = TWF_ANDW
Checks whether all of the bits to which 1 is set by parameter waiptn are set as the target eventflag.
- wfmode = TWF_ORW
Checks which bit, among bits to which 1 is set by parameter waiptn, is set as the target eventflag.
The following describes an example for coding this service call.
 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      flgid = 1;              /*Declares and initializes variable*/
     FLGPTN  waiptn = 14;            /*Declares and initializes variable*/
     MODE    wfmode = TWF_ANDW;      /*Declares and initializes variable*/
     FLGPTN  p_flgptn;               /*Declares variable*/
 
     /* ......... */
 
                                     /*Wait for eventflag*/
     ercd = wai_flg (flgid, waiptn, wfmode, &p_flgptn);
 
     if (ercd == E_OK) {
         /* ......... */             /*Normal termination processing*/
     } else if (ercd == E_RLWAI) {
         /* ......... */             /*Forced termination processing*/
     }
 
     /* ......... */

Note 1 With the RI600V4, whether to enable queuing of multiple tasks to the event flag wait queue is defined during configuration. If this service call is issued for the event flag (TA_WSGL attribute) to which a wait task is queued, therefore, "E_ILUSE" is returned regardless of whether the required condition is immediately satisfied.
TA_WSGL: Only one task is allowed to be in the WAITING state for the eventflag.
TA_WMUL: Multiple tasks are allowed to be in the WAITING state for the eventflag.
Note 2 Invoking tasks are queued to the target event flag (TA_WMUL attribute) wait queue in the order defined during configuration (FIFO order or current priority order).
However, when the TA_CLR attribute is not specified, the wait queue is managed in the FIFO order even if the priority order is specified. This behavior falls outside mITRON4.0 specification.
Note 3 The RI600V4 performs bit pattern clear processing (0 setting) when the required condition of the target eventflag (TA_CLR attribute) is satisfied.
- pol_flg, ipol_flg (Polling)
This service call checks whether the bit pattern specified by parameter waiptn and the bit pattern that satisfies the required condition specified by parameter wfmode are set to the eventflag specified by parameter flgid.
If the bit pattern that satisfies the required condition has been set to the target eventflag, the bit pattern of the target eventflag is stored in the area specified by parameter p_flgptn.
If the bit pattern of the target eventflag does not satisfy the required condition when this service call is issued, E_TMOUT is returned.
The following shows the specification format of required condition wfmode.
- wfmode = TWF_ANDW
Checks whether all of the bits to which 1 is set by parameter waiptn are set as the target eventflag.
- wfmode = TWF_ORW
Checks which bit, among bits to which 1 is set by parameter waiptn, is set as the target eventflag.
The following describes an example for coding these service calls.
 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      flgid = 1;              /*Declares and initializes variable*/
     FLGPTN  waiptn = 14;            /*Declares and initializes variable*/
     MODE    wfmode = TWF_ANDW;      /*Declares and initializes variable*/
     FLGPTN  p_flgptn;               /*Declares variable*/
 
     /* ......... */
 
                                     /*Wait for eventflag*/
     ercd = pol_flg (flgid, waiptn, wfmode, &p_flgptn);
 
     if (ercd == E_OK) {
         /* ......... */             /*Polling success processing*/
     } else if (ercd == E_TMOUT) {
         /* ......... */             /*Polling failure processing*/
     }
 
     /* ......... */
 }

Note 1 With the RI600V4, whether to enable queuing of multiple tasks to the event flag wait queue is defined during configuration. If this service call is issued for the event flag (TA_WSGL attribute) to which a wait task is queued, therefore, "E_ILUSE" is returned regardless of whether the required condition is immediately satisfied.
TA_WSGL: Only one task is allowed to be in the WAITING state for the eventflag.
TA_WMUL: Multiple tasks are allowed to be in the WAITING state for the eventflag.
Note 2 The RI600V4 performs bit pattern clear processing (0 setting) when the required condition of the target eventflag (TA_CLR attribute) is satisfied.
- twai_flg (Wait with time-out)
This service call checks whether the bit pattern specified by parameter waiptn and the bit pattern that satisfies the required condition specified by parameter wfmode are set to the eventflag specified by parameter flgid.
If a bit pattern that satisfies the required condition has been set for the target eventflag, the bit pattern of the target eventflag is stored in the area specified by parameter p_flgptn.
If the bit pattern of the target eventflag does not satisfy the required condition when this service call is issued, the invoking task is queued to the target eventflag wait queue.
As a result, the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state (WAITING state for an eventflag).
The WAITING state for an eventflag is cancelled in the following cases.
WAITING State for an Eventflag Cancel Operation
Return Value
A bit pattern that satisfies the required condition was set to the target eventflag as a result of issuing set_flg.
E_OK
A bit pattern that satisfies the required condition was set to the target eventflag as a result of issuing iset_flg.
E_OK
Forced release from waiting (accept rel_wai while waiting).
E_RLWAI
Forced release from waiting (accept irel_wai while waiting).
E_RLWAI
The time specified by tmout has elapsed.
E_TMOUT

The following shows the specification format of required condition wfmode.
- wfmode = TWF_ANDW
Checks whether all of the bits to which 1 is set by parameter waiptn are set as the target eventflag.
- wfmode = TWF_ORW
Checks which bit, among bits to which 1 is set by parameter waiptn, is set as the target eventflag.
The following describes an example for coding this service call.
 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      flgid = 1;              /*Declares and initializes variable*/
     FLGPTN  waiptn = 14;            /*Declares and initializes variable*/
     MODE    wfmode = TWF_ANDW;      /*Declares and initializes variable*/
     FLGPTN  p_flgptn;               /*Declares variable*/
     TMO     tmout = 3600;           /*Declares and initializes variable*/
 
     /* ......... */
 
                                     /*Wait for eventflag*/
     ercd = twai_flg (flgid, waiptn, wfmode, &p_flgptn, tmout);
 
     if (ercd == E_OK) {
         /* ......... */             /*Normal termination processing*/
     } else if (ercd == E_RLWAI) {
         /* ......... */             /*Forced termination processing*/
     } else if (ercd == E_TMOUT) {
         /* ......... */             /*Time-out processing*/
     }
 
     /* ......... */
 }

Note 1 With the RI600V4, whether to enable queuing of multiple tasks to the event flag wait queue is defined during configuration. If this service call is issued for the event flag (TA_WSGL attribute) to which a wait task is queued, therefore, "E_ILUSE" is returned regardless of whether the required condition is immediately satisfied.
TA_WSGL: Only one task is allowed to be in the WAITING state for the eventflag.
TA_WMUL: Multiple tasks are allowed to be in the WAITING state for the eventflag.
Note 2 Invoking tasks are queued to the target event flag (TA_WMUL attribute) wait queue in the order defined during configuration (FIFO order or current priority order).
However, when the TA_CLR attribute is not specified, the wait queue is managed in the FIFO order even if the priority order is specified. This behavior falls outside mITRON4.0 specification.
Note 3 The RI600V4 performs bit pattern clear processing (0 setting) when the required condition of the target eventflag (TA_CLR attribute) is satisfied.
Note 4 TMO_FEVR is specified for wait time tmout, processing equivalent to wai_flg will be executed. When TMO_POL is specified, processing equivalent to pol_flg will be executed.
5.3.5 Reference eventflag state
An eventflag status is referenced by issuing the following service call from the processing program.
- ref_flg, iref_flg
Stores eventflag state packet (ID number of the task at the head of the wait queue, current bit pattern, etc.) of the eventflag specified by parameter flgid in the area specified by parameter pk_rflg.
The following describes an example for coding these service calls.
 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600*/
 
 void task (VP_INT exinf)
 {
     ID      flgid = 1;              /*Declares and initializes variable*/
     T_RFLG  pk_rflg;                /*Declares data structure*/
     ID      wtskid;                 /*Declares variable*/
     FLGPTN  flgptn;                 /*Declares variable*/
 
     /* ......... */
 
     ref_flg (flgid, &pk_rflg);      /*Reference eventflag state*/
 
     wtskid = pk_rflg.wtskid;        /*Reference ID number of the task at the */
                                     /*head of the wait queue*/
     flgptn = pk_rflg.flgptn;        /*Reference current bit pattern*/
 
     /* ......... */
 }

Note For details about the eventflag state packet, refer to "[Eventflag state packet: T_RFLG]".