Everything
7.3 Eventflags
The RI600PX 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 7-2 Processing Flow (Eventflag)
7.3.1 Create eventflag
Eventflags are created by one of the following methods.
1 ) Creation by the system configuration file
The static API flag[] described in the system configuration file creates a eventflag.
Refer to 20.12 Eventflag Information (flag[]) for the details of flag[].
2 ) Creation by cre_flg or acre_flg
The cre_flg creates a eventflag with eventflag ID indicated by parameter flgid according to the content of parameter pk_cflg.
The acre_flg creates a eventflag according to the content of parameter pk_cflg, and returns the created eventflag ID.
The information specified is shown below.
- Eventflag attribute (flgatr)
The following informations are specified as flgatr.
- The order of task wait queue (FIFO order or task current priority order)
- Whether multiple task can wait on the event flag.
- Whether the bit pattern of the event flag is cleared to 0 when a task is released from the WAITING state,
- Initial bit pattern (iflgptn)
These service calls can be called from tasks that belong to Trusted Domain.
The following describes an example for coding acre_flg as a representative.
 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600px*/
 #pragma task Task1                  /*Refer to note*/
 void Task1 (VP_INT exinf);          /*Refer to note*/
 void Task1 (VP_INT exinf)
 {
     ER      flgid;              /*Declares variable*/
     T_CFLG  pk_cflg = {         /*Declares and initializes variable*/
         TA_TFIFO|TA_WSGL|TA_CLR,    /*Eventflag attribute (flgatr)*/
         0UL                         /*Initial bit pattern (iflgptn)*/
     };
 
     /* ......... */
 
     flgid = acre_flg ( &pk_cflg ); /*Create eventflag/
 
     /* ......... */
 }

Note These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".
7.3.2 Delete Eventflag
- del_flg
This service call deletes the eventflag specified by parameter flgid.
When there are waiting tasks for the target eventflag by using wai_flg or twai_flg, this service call cancels the WAITING state of the tasks and returns E_DLT as a return value of the wai_flg or twai_flg.
This service call can be called from tasks that belong to Trusted Domain.
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 cfg600px*/
 #pragma task Task1                  /*Refer to note*/
 void Task1 (VP_INT exinf);          /*Refer to note*/
 void Task1 (VP_INT exinf)
 {
     ID      flgid = 8;          /*Declares and initializes variable*/
 
     /* ......... */
 
     ercd = del_flg ( flgid );   /*Delete semaphore*/
 
     /* ......... */
 }

Note These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".
7.3.3 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 cfg600px*/
 #pragma task Task1                  /*Refer to note*/
 void Task1 (VP_INT exinf);          /*Refer to note*/
 void Task1 (VP_INT exinf)
 {
     ID      flgid = 1;              /*Declares and initializes variable*/
     FLGPTN  setptn = 0x00000001UL;  /*Declares and initializes variable*/
 
     /* ......... */
 
     set_flg (flgid, setptn);        /*Set eventflag*/
 
     /* ......... */
 }

Note These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".
7.3.4 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 cfg600px*/
 #pragma task Task1                  /*Refer to note*/
 void Task1 (VP_INT exinf);          /*Refer to note*/
 void Task1 (VP_INT exinf)
 {
     ID      flgid = 1;              /*Declares and initializes variable*/
     FLGPTN  clrptn = 0xFFFFFFFEUL;  /*Declares and initializes variable*/
 
     /* ......... */
 
     clr_flg (flgid, clrptn);        /*Clear eventflag*/
 
     /* ......... */
 }

Note These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".
7.3.5 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
Forced release from waiting (accept del_flg while waiting).
E_DLT

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 cfg600px*/
 #pragma task Task1                  /*Refer to note 4*/
 void Task1 (VP_INT exinf);          /*Refer to note 4*/
 void Task1 (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 When a task has already waited on the eventflag which has been created with TA_WSGL attribute (only one task is allowed to be in the WAITING state for the eventflag), this service call returns E_ILUSE error.
Note 2 Invoking tasks are queued to the target event flag (TA_WMUL attribute) wait queue in the order defined at creating the eventflag (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 RI600PX performs bit pattern clear processing (0 setting) when the required condition of the target eventflag (TA_CLR attribute) is satisfied.
Note 4 These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".
- 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 cfg600px*/
 #pragma task Task1                  /*Refer to note 3*/
 void Task1 (VP_INT exinf);          /*Refer to note 3*/
 void Task1 (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 When a task has already waited on the eventflag which has been created with TA_WSGL attribute (only one task is allowed to be in the WAITING state for the eventflag), this service call returns E_ILUSE error.
Note 2 The RI600PX performs bit pattern clear processing (0 setting) when the required condition of the target eventflag (TA_CLR attribute) is satisfied.
Note 3 These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".
- 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
Forced release from waiting (accept del_flg while waiting).
E_DLT

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 cfg600px*/
 #pragma task Task1                  /*Refer to note 5*/
 void Task1 (VP_INT exinf);          /*Refer to note 5*/
 void Task1 (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 When a task has already waited on the eventflag which has been created with TA_WSGL attribute (only one task is allowed to be in the WAITING state for the eventflag), this service call returns E_ILUSE error.
Note 2 Invoking tasks are queued to the target event flag (TA_WMUL attribute) wait queue in the order defined at creating the eventflag (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 RI600PX 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.
Note 5 These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".
7.3.6 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 cfg600px*/
 #pragma task Task1                  /*Refer to note 2*/
 void Task1 (VP_INT exinf);          /*Refer to note 2*/
 void Task1 (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 1 For details about the eventflag state packet, refer to "[Eventflag state packet: T_RFLG]".
Note 2 These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".