Everything

twai_flg

Outline
Wait for eventflag (with timeout).
C format
 ER      twai_flg ( ID flgid, FLGPTN waiptn, MODE wfmode, FLGPTN *p_flgptn, TMO tmout 
);

Assembly format
 MOVW    AX, #tmout_hi
 PUSH    AX
 MOVW    AX, #tmout_lo
 PUSH    AX
 MOVW    DE, #LOWW(_p_flgptn)
 MOVW    BC, #waiptn
 MOVW    AX, #(flgid | wfmode)
 CALL    !!_twai_flg
 addw    sp, #0x0004

Parameter(s)
I/O
Parameter
Description
I
 ID      flgid;
ID number of the eventflag wait for.
I
 FLGPTN  waiptn;
Wait bit pattern (16 bits).
I
 MODE    wfmode;
Wait mode.
TWF_ANDW: AND waiting condition.
TWF_ORW: OR waiting condition.
O
 FLGPTN  *p_flgptn;
Bit pattern causing a task to be released from waiting.
I
 TMO     tmout;
Specified timeout (unit: ticks).
TMO_FEVR: Waiting forever.
TMO_POL: Polling.
Value: Specified timeout.

Explanation
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, 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, and then moved to the READY state.
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
Polling failure or timeout.
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.
Note 1 In the RI78V4, the number of tasks that can be queued to the eventflag wait queue is one. If this service call is issued for the eventflag to which a task is queued, therefore, "E_ILUSE" is returned regardless of whether or not the required condition is immediately satisfied.
Note 2 The RI78V4 performs bit pattern clear processing (0x0 setting) when the required condition of the target eventflag (TA_CLR attribute) is satisfied.
Note 3 When 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.
Return value
Macro
Value
Description
E_OK
0
Normal completion.
E_ILUSE
-28
Illegal service call use (there is already a task waiting for an eventflag with the TA_WSGL attribute).
E_RLWAI
-49
Forced release from waiting (accept rel_wai/irel_wai while waiting).
E_TMOUT
-50
Polling failure or timeout.