Command disabled: backlink
 
Available Languages?:
Table of Contents

OSA : Flags

Intro

Flags are similar to binary semaphores. There are two differences:

  1. you can wait, check, set or reset several flags at one time;
  2. after accepting flags their values do not change.

Flags can be useful when a task requires the results of several tasks. For example: to calculate some physical parameters a task needs information about the temperature, pressure and humidity. Each of these parameters is measured in its own task which sets a flag when measurement is complete.

#include <osa.h>
 
OST_FLAG8   F_Sensors;
 
#define  TEMPERATURE_MEASURED   0x01
#define  PRESSURE_MEASURED      0x02
#define  HUMIDITY_MEASURED      0x04
 
void Task_Calc (void)
{
    for (;;) {
        // Wait for all measurements complete
        OS_Flag_Wait_AllOn(F_Sensors, TEMPERATURE_MEASURED | PRESSURE_MEASURED | HUMIDITY_MEASURED);
        OS_Flag_Clear(F_Sensors, TEMPERATURE_MEASURED | PRESSURE_MEASURED | HUMIDITY_MEASURED);
 
        // Now we can calculate
        ...
    }
}

Definition

There are three types of flags: 8-, 16- and 32-bit.

OST_FLAG      MyFlag1;	//  8-bit flags
OST_FLAG16    MyFlag2;	// 16-bit flags
OST_FLAG32    MyFlag3;	// 32-bit flags

It is possible to use different size of flags at the same time.

Flags can be allocated in any memory bank, e.g.:

bank2    OST_FLAG16   MyFlag;

Services

Service Arguments Description Properties
Creating
OS_Flag_Create (flag) (flag = 0) Create flag and clear all its bits
Management
OS_Flag_Init (flag, value) (flag = value) Set flag to given value Has alternate service for use in ISR (suffix "_I")
OS_Flag_Set (flag, mask) (flag = flag | mask) Set bits in flag according to mask Has alternate service for use in ISR (suffix "_I")
OS_Flag_Clear (flag, mask) (flag &= ~mask) Clear bits in flag according to mask Has alternate service for use in ISR (suffix "_I")
Checking
bool
OS_Flag_Check_AllOn
(flag, mask) ( if ((flag & mask)==mask) ) Check if all bits in flag specified by mask are set Has alternate service for use in ISR (suffix "_I")
bool
OS_Flag_Check_On
(flag, mask) ( if ((flag & mask)!=0) ) Check if any bit in flags specified by mask is set Has alternate service for use in ISR (suffix "_I")
bool
OS_Flag_Check_AllOff
(flag, mask) ( if ((flag & mask)==0) ) Check if all bits in flag specified by mask are clear Has alternate service for use in ISR (suffix "_I")
bool
OS_Flag_Check_Off
(flag, mask) ( if ((flag & mask)!=mask) ) Check if any bit in flag specified by mask is clear Has alternate service for use in ISR (suffix "_I")
Waiting
OS_Flag_Wait_AllOn (flag, mask) ( if ((flag & mask)==mask) ) Wait until all bits in flag specified by mask are set Allowed only in taskSwitches context
OS_Flag_Wait_On (flag, mask) ( wait ((flag & mask)!=0) ) Wait until any bit in flag specified by mask is set Allowed only in taskSwitches context
OS_Flag_Wait_AllOff (flag, mask) ( wait ((flag & mask)==0) ) Wait until all bits in flag specified by mask are clear Allowed only in taskSwitches context
OS_Flag_Wait_Off (flag, mask) ( wait ((flag & mask)!=mask) ) Wait until any bit in flag specified by mask is clear Allowed only in taskSwitches context
OS_Flag_Wait_AllOn_TO (flag, mask, timeout) ( wait ((flag & mask)==mask) ) Wait until all bits in flags specified by mask are set. Exit if timeout expired Allowed only in taskSwitches contextService uses system timer
OS_Flag_Wait_On_TO (flag, mask, timeout) ( wait ((flag & mask)!=0) ) Wait until any bit in flags specified by mask is set. Exit if timeout expired Allowed only in taskSwitches contextService uses system timer
OS_Flag_Wait_AllOff_TO (flag, mask, timeout) ( wait ((flag & mask)==0) ) Wait until all bits in flag specified by mask are clear. Exit if timeout expired Allowed only in taskSwitches contextService uses system timer
OS_Flag_Wait_Off_TO (flag, mask, timeout) ( wait ((flag & mask)!=mask) ) Wait until any bit in flag specified by mask is clear. Exit if timeout expired Allowed only in taskSwitches contextService uses system timer
 
en/osa/ref/services/flags.txt · Last modified: 07.10.2010 13:58 (external edit)
 
Creative Commons License Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki