Event Flags


Detailed Description

Event flags allow tasks to wait for a specific combination of events.

An event flag is a bitmask. Waiting tasks can specify a subset of the bitmask as events of interest. They can either wait for ALL of the events to occur or ANY of the events to occur.

NOTE: Always initialize before use.

 eflag_t notification;   // Previously initialized
 #define ALERT0  0x01
 #define ALERT1  0x02
 void task1(void *dummy)
 {
   int8_t rc;
   while(1) {
       rc = eflag_wait( &notification, ALERT0, 0, 0, );
       if (rc == SUCCESS) {
          do_something();
       }
   }
 }
 void task2(void *dummy)
 {
   int8_t rc;
   while(1) {
       // Trigger event
       rc = eflag_set(&notification, ALERT0|ALERT1, O_EFLAG_TRIGGER); 
       do_other_stuff();
   }
 }
 *


Functions

void eflag_init (eflag_t *ef, flag_t initval)
int8_t eflag_set (eflag_t *ef, flag_t setbits, uint8_t options)
flag_t eflag_get (eflag_t *ef)
int8_t eflag_wait (eflag_t *ef, flag_t checkbits, const trtime_t *timeout, uint8_t options)


Function Documentation

void eflag_init ( eflag_t ef,
flag_t  initval 
)

Initialize an event flag.

*

Calling Context:

  1. Before os_start().
  2. From within a task.
  3. From an ISR.

Parameters:
ef Pointer to the event flag.
initval Initial value for the event flag

int8_t eflag_set ( eflag_t ef,
flag_t  setbits,
uint8_t  options 
)

Set an event flag.

Calling Context:

  1. From within a task.
  2. From an ISR.

Parameters:
ef Pointer to the event flag.
setbits The new bitvalues to be set or cleared.
options [O_EFLAG_CLEAR, O_EFLAG_TRIGGER]
   O_EFLAG_CLEAR   : Clear the specified bits.  Default is to set them. 
   O_EFLAG_TRIGGER : Just pulse the values in the prescribed
                     fashion. Don't set them permanently.  If any of the 
                     flag values were set before the trigger, they stay
                     set after the call.
 
Returns:
{SUCCESS, ERR_FAILED}

flag_t eflag_get ( eflag_t ef  ) 

Peek at the value of an event flag.

This can be used for polling.

Calling Context:

  1. Before os_start().
  2. From within a task.
  3. From an ISR.

Parameters:
ef Pointer to the flag.
Returns:
Current setting for the event flag

int8_t eflag_wait ( eflag_t ef,
flag_t  checkbits,
const trtime_t timeout,
uint8_t  options 
)

Wait for an event flag.

A blocking call from an ISR will result in an error. So, there is usually no need to call this from an ISR. eflag_get may be preferable.

Calling Context:

  1. From within a task.
  2. From an ISR (error if blocking needed).

Parameters:
ef Pointer to the event flag.
checkbits Bits to be checked.
[in] timeout Timeout. This can be 0 for infinite timeout.
options [O_NONBLOCKING | O_RELATIVE_TIME | O_EFLAG_AND | O_EFLAG_OR ].
Returns:
{SUCCESS, ERR_WOULDBLOCK_ISR, ERR_WOULDBLOCK_MUTEX, ERR_TIMEOUT, ERR_RESUMED}


TiROS User Manual: Last Updated on Fri Jul 20 10:52:24 2007