Available Languages?:

This is an old revision of the document!


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.

The using of flags can be usefull when task requires the results of several tasks. For example to calculate some physical parameters task needs information about the temperature, pressure and humidity. Each of these parameters is measured in it's own task and set flag when measuring 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 measurings complete
        OS_Flag_Wait_11(F_Sensors, TEMPERATURE_MEASURED | PRESSURE_MEASURED | HUMIDITY_MEASURED);
        OS_Flag_Set_0(F_Sensors, TEMPERATURE_MEASURED | PRESSURE_MEASURED | HUMIDITY_MEASURED);
 
        // Now we can to 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 defferent size of flags at one time.

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

bank2    OST_FLAG16   MyFlag;

Services

Service Arguments Description Properties
Creating
OS_Flag_Create (flags) (flag = 0) Create flag and clear all it's bits (flag = 0)
Menagement
OS_Flag_Init (flags, value) (flag = value) Set flag to givel value Have alternate service for work in ISR (suffix "_I")
OS_Flag_Set_1 (flags, mask) (flag = flags | mask) Set bits in flag by given mask Have alternate service for work in ISR (suffix "_I")
OS_Flag_Set_0 (flags, mask) (flag &= ~mask) Clear bits in flag by given mask Have alternate service for work in ISR (suffix "_I")
Checking
bool
OS_Flag_Check_11
(flags, mask) ( if ((flag & mask)==mask) ) Check for all bits in flags are set by given mask Have alternate service for work in ISR (suffix "_I")
bool
OS_Flag_Check_1x
(flags, mask) ( if ((flag & mask)!=0) ) Check for any bit in flags is set by given mask Have alternate service for work in ISR (suffix "_I")
bool
OS_Flag_Check_00
(flags, mask) ( if ((flag & mask)==0) ) Check for all bits in flag are cleared by given mask Have alternate service for work in ISR (suffix "_I")
bool
OS_Flag_Check_0x
(flags, mask) ( if ((flag & mask)!=mask) ) Check for any bit in flag is cleared by given mask Have alternate service for work in ISR (suffix "_I")
Waiting
OS_Flag_Wait_11 (flags, mask) ( if ((flag & mask)==mask) ) Wait for all bits in flags are set by given mask Allowed only in taskSwitches contexts
OS_Flag_Wait_1x (flags, mask) ( wait ((flag & mask)!=0) ) Wait for any bit in flags is set by given mask Allowed only in taskSwitches contexts
OS_Flag_Wait_00 (flags, mask) ( wait ((flag & mask)==0) ) Wait for all bits in flag are cleared by given mask Allowed only in taskSwitches contexts
OS_Flag_Wait_0x (flags, mask) ( wait ((flag & mask)!=mask) ) Wait for any bit in flag is cleared by given mask Allowed only in taskSwitches contexts
OS_Flag_Wait_11_TO (flags, mask, timeout) ( wait ((flag & mask)==mask) ) Wait for all bits in flags are set by given mask. Exit if timeout expired. Allowed only in taskSwitches contextsService uses system timer
OS_Flag_Wait_1x_TO (flags, mask, timeout) ( wait ((flag & mask)!=0) ) Wait for any bit in flags is set by given mask. Exit if timeout expired. Allowed only in taskSwitches contextsService uses system timer
OS_Flag_Wait_00_TO (flags, mask, timeout) ( wait ((flag & mask)==0) ) Wait for all bits in flag are cleared by given mask. Exit if timeout expired. Allowed only in taskSwitches contextsService uses system timer
OS_Flag_Wait_0x_TO (flags, mask, timeout) ( wait ((flag & mask)!=mask) ) Wait for any bit in flag is cleared by given mask. Exit if timeout expired. Allowed only in taskSwitches contextsService uses system timer
 
en/osa/ref/services/flags.1267250632.txt.gz · Last modified: 27.02.2010 09:03 by osa_chief
 
Creative Commons License Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki