OSFlagCreate

Description

Creates and initialize an event flag group. µC/OS-III allows the user to create an unlimited number of event flag groups (limited only by the amount of RAM in the system).

Files

os.h/os_flag.c

Prototype

void  OSFlagCreate (OS_FLAG_GRP  *p_grp,
                    CPU_CHAR     *p_name,
                    OS_FLAGS      flags,
                    OS_ERR       *p_err)

Arguments

p_grp

This is a pointer to an event flag group that must be allocated in the application. The user will need to declare a “global” variable as shown, and pass a pointer to this variable to OSFlagCreate():

OS_FLAG_GRP MyEventFlag;

p_name

This is a pointer to an ASCII string used for the name of the event flag group. The name can be displayed by debuggers or by µC/Probe.

flags

This contains the initial value of the flags to store in the event flag group. Typically, you would set all flags to 0 events correspond to set bits and all 1s if events correspond to cleared bits.

p_err

This is a pointer to a variable that is used to hold an error code. The error code can be one of the following:

OS_ERR_NONE

If the call is successful and the event flag group has been created.

OS_ERR_CREATE_ISR

If OS_CFG_CALLED_FROM_ISR_CHK_EN set to DEF_ENABLED in os_cfg.h: If attempting to create an event flag group from an ISR, w is not allowed.

OS_ERR_ILLEGAL_CREATE_RUN_TIME

If OS_SAFETY_CRITICAL_IEC61508 is defined: you called this after calling OSStart() and thus you are no longer allowed to create additional kernel objects.

OS_ERR_OBJ_PTR_NULL

If OS_CFG_ARG_CHK_EN is set to DEF_ENABLED in os_cfg.h: If p_grp is a NULL pointer.

Returned Values

None

Required Configuration

OS_CFG_FLAG_EN must be enabled in os_cfg.h. Refer to uC-OS-III Configuration Manual.

Callers

Application.

Notes/Warnings

  1. Event flag groups must be created by this function before they can be used by the other event flag group services.

Example Usage

OSFlagCreate() example usage
          OS_FLAG_GRP  EngineStatus;
           
           
          void main (void)
          {
              OS_ERR  err;
             
              OSInit(&err);                    /* Initialize µC/OS-III                             */
              :
              :
              OSFlagCreate(&EngineStatus,
                           "Engine Status",
                           (OS_FLAGS)0,
                           &err);              /* Create a flag grp containing the engine's status */
              /* Check "err" */
              :
              :
              OSStart();                       /* Start Multitasking                               */

Related pages