OS_FLAG.lst
上传用户:tzjinxin1
上传日期:2022-08-08
资源大小:272k
文件大小:59k
开发平台:

Visual C++

  1. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 1   
  2. C51 COMPILER V8.02, COMPILATION OF MODULE OS_FLAG
  3. OBJECT MODULE PLACED IN .objOS_FLAG.obj
  4. COMPILER INVOKED BY: C:KeilC51BINC51.EXE uCosiiOS_FLAG.C LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.lstOS_FLAG.lst) O
  5.                     -BJECT(.objOS_FLAG.obj)
  6. line level    source
  7.    1          /*
  8.    2          *********************************************************************************************************
  9.    3          *                                                uC/OS-II
  10.    4          *                                          The Real-Time Kernel
  11.    5          *                                         EVENT FLAG  MANAGEMENT
  12.    6          *
  13.    7          *                            (c) Copyright 2001, Jean J. Labrosse, Weston, FL
  14.    8          *                                           All Rights Reserved
  15.    9          *
  16.   10          * File : OS_FLAG.C
  17.   11          * By   : Jean J. Labrosse
  18.   12          *********************************************************************************************************
  19.   13          */
  20.   14          
  21.   15          #ifndef  OS_MASTER_FILE
  22.   16          #include "sourceincludes.h"
  23.   17          #endif
  24.   18          
  25.   19          #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
  26.               /*
  27.               *********************************************************************************************************
  28.               *                                            LOCAL PROTOTYPES
  29.               *********************************************************************************************************
  30.               */
  31.               
  32.               static  void     OS_FlagBlock(OS_FLAG_GRP *pgrp, OS_FLAG_NODE *pnode, OS_FLAGS flags, INT8U wait_type, INT
  33.              -16U timeout) reentrant;
  34.               static  BOOLEAN  OS_FlagTaskRdy(OS_FLAG_NODE *pnode, OS_FLAGS flags_rdy) reentrant;
  35.               
  36.               /*$PAGE*/
  37.               /*
  38.               *********************************************************************************************************
  39.               *                              CHECK THE STATUS OF FLAGS IN AN EVENT FLAG GROUP
  40.               *
  41.               * Description: This function is called to check the status of a combination of bits to be set or cleared
  42.               *              in an event flag group.  Your application can check for ANY bit to be set/cleared or ALL 
  43.               *              bits to be set/cleared.
  44.               *
  45.               *              This call does not block if the desired flags are not present.
  46.               *
  47.               * Arguments  : pgrp          is a pointer to the desired event flag group.
  48.               *
  49.               *              flags         Is a bit pattern indicating which bit(s) (i.e. flags) you wish to check.  
  50.               *                            The bits you want are specified by setting the corresponding bits in 
  51.               *                            'flags'.  e.g. if your application wants to wait for bits 0 and 1 then 
  52.               *                            'flags' would contain 0x03.
  53.               *
  54.               *              wait_type     specifies whether you want ALL bits to be set/cleared or ANY of the bits 
  55.               *                            to be set/cleared.
  56.               *                            You can specify the following argument:
  57.               *
  58.               *                            OS_FLAG_WAIT_CLR_ALL   You will check ALL bits in 'flags' to be clear (0)
  59.               *                            OS_FLAG_WAIT_CLR_ANY   You will check ANY bit  in 'flags' to be clear (0)
  60.               *                            OS_FLAG_WAIT_SET_ALL   You will check ALL bits in 'flags' to be set   (1)
  61. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 2   
  62.               *                            OS_FLAG_WAIT_SET_ANY   You will check ANY bit  in 'flags' to be set   (1)
  63.               *
  64.               *                            NOTE: Add OS_FLAG_CONSUME if you want the event flag to be 'consumed' by
  65.               *                                  the call.  Example, to wait for any flag in a group AND then clear
  66.               *                                  the flags that are present, set 'wait_type' to:
  67.               *
  68.               *                                  OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME
  69.               *
  70.               *              err           is a pointer to an error code and can be:
  71.               *                            OS_NO_ERR              No error
  72.               *                            OS_ERR_EVENT_TYPE      You are not pointing to an event flag group
  73.               *                            OS_FLAG_ERR_WAIT_TYPE  You didn't specify a proper 'wait_type' argument.
  74.               *                            OS_FLAG_INVALID_PGRP   You passed a NULL pointer instead of the event flag
  75.               *                                                   group handle.
  76.               *                            OS_FLAG_ERR_NOT_RDY    The desired flags you are waiting for are not 
  77.               *                                                   available.
  78.               *
  79.               * Returns    : The state of the flags in the event flag group.
  80.               *
  81.               * Called from: Task or ISR
  82.               *********************************************************************************************************
  83.               */
  84.               
  85.               #if OS_FLAG_ACCEPT_EN > 0
  86.               OS_FLAGS  OSFlagAccept (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U wait_type, INT8U *err) reentrant
  87.               {
  88.               #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
  89.                   OS_CPU_SR     cpu_sr;
  90.               #endif    
  91.                   OS_FLAGS      flags_cur;
  92.                   OS_FLAGS      flags_rdy;
  93.                   BOOLEAN       consume;
  94.               
  95.               
  96.               #if OS_ARG_CHK_EN > 0
  97.                   if (pgrp == (OS_FLAG_GRP *)0) {                        /* Validate 'pgrp'                          */
  98.                       *err = OS_FLAG_INVALID_PGRP;
  99.                       return ((OS_FLAGS)0);
  100.                   }
  101.                   if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {          /* Validate event block type                */
  102.                       *err = OS_ERR_EVENT_TYPE;
  103.                       return ((OS_FLAGS)0);
  104.                   }
  105.               #endif
  106.                   if (wait_type & OS_FLAG_CONSUME) {                     /* See if we need to consume the flags      */
  107.                       wait_type &= ~OS_FLAG_CONSUME;
  108.                       consume    = TRUE;
  109.                   } else {
  110.                       consume    = FALSE;
  111.                   }
  112.               /*$PAGE*/
  113.                   *err = OS_NO_ERR;                                      /* Assume NO error until proven otherwise.  */
  114.                   OS_ENTER_CRITICAL();
  115.                   switch (wait_type) {
  116.                       case OS_FLAG_WAIT_SET_ALL:                         /* See if all required flags are set        */
  117.                            flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we want            */
  118.                            if (flags_rdy == flags) {                     /* Must match ALL the bits that we want     */
  119.                                if (consume == TRUE) {                    /* See if we need to consume the flags      */
  120.                                    pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we wanted      */
  121.                                }
  122.                            } else {
  123.                                *err  = OS_FLAG_ERR_NOT_RDY;
  124. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 3   
  125.                            }
  126.                            flags_cur = pgrp->OSFlagFlags;                /* Will return the state of the group       */
  127.                            OS_EXIT_CRITICAL();
  128.                            break;
  129.               
  130.                       case OS_FLAG_WAIT_SET_ANY:
  131.                            flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we want            */
  132.                            if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag set                      */
  133.                                if (consume == TRUE) {                    /* See if we need to consume the flags      */
  134.                                    pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we got         */
  135.                                }
  136.                            } else {
  137.                                *err  = OS_FLAG_ERR_NOT_RDY;
  138.                            }
  139.                            flags_cur = pgrp->OSFlagFlags;                /* Will return the state of the group       */
  140.                            OS_EXIT_CRITICAL();
  141.                            break;
  142.               
  143.               #if OS_FLAG_WAIT_CLR_EN > 0
  144.                       case OS_FLAG_WAIT_CLR_ALL:                         /* See if all required flags are cleared    */
  145.                            flags_rdy = ~pgrp->OSFlagFlags & flags;       /* Extract only the bits we want            */
  146.                            if (flags_rdy == flags) {                     /* Must match ALL the bits that we want     */
  147.                                if (consume == TRUE) {                    /* See if we need to consume the flags      */
  148.                                    pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we wanted        */
  149.                                }
  150.                            } else {
  151.                                *err  = OS_FLAG_ERR_NOT_RDY;
  152.                            }
  153.                            flags_cur = pgrp->OSFlagFlags;                /* Will return the state of the group       */
  154.                            OS_EXIT_CRITICAL();
  155.                            break;
  156.               
  157.                       case OS_FLAG_WAIT_CLR_ANY:
  158.                            flags_rdy = ~pgrp->OSFlagFlags & flags;       /* Extract only the bits we want            */
  159.                            if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag cleared                  */
  160.                                if (consume == TRUE) {                    /* See if we need to consume the flags      */
  161.                                    pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we got           */
  162.                                }
  163.                            } else {
  164.                                *err  = OS_FLAG_ERR_NOT_RDY;
  165.                            }
  166.                            flags_cur = pgrp->OSFlagFlags;                /* Will return the state of the group       */
  167.                            OS_EXIT_CRITICAL();
  168.                            break;
  169.               #endif
  170.               
  171.                       default:
  172.                            OS_EXIT_CRITICAL();
  173.                            flags_cur = (OS_FLAGS)0;
  174.                            *err      = OS_FLAG_ERR_WAIT_TYPE;
  175.                            break;
  176.                   }
  177.                   return (flags_cur);
  178.               }
  179.               #endif    
  180.               
  181.               /*$PAGE*/
  182.               /*
  183.               *********************************************************************************************************
  184.               *                                           CREATE AN EVENT FLAG
  185.               *
  186.               * Description: This function is called to create an event flag group.
  187. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 4   
  188.               *
  189.               * Arguments  : flags         Contains the initial value to store in the event flag group.
  190.               *
  191.               *              err           is a pointer to an error code which will be returned to your application:
  192.               *                               OS_NO_ERR                if the call was successful.
  193.               *                               OS_ERR_CREATE_ISR        if you attempted to create an Event Flag from an 
  194.               *                                                        ISR.
  195.               *                               OS_FLAG_GRP_DEPLETED     if there are no more event flag groups
  196.               *
  197.               * Returns    : A pointer to an event flag group or a NULL pointer if no more groups are available.
  198.               *
  199.               * Called from: Task ONLY
  200.               *********************************************************************************************************
  201.               */
  202.               
  203.               OS_FLAG_GRP  *OSFlagCreate (OS_FLAGS flags, INT8U *err) reentrant
  204.               {
  205.               #if OS_CRITICAL_METHOD == 3                         /* Allocate storage for CPU status register        */
  206.                   OS_CPU_SR    cpu_sr;
  207.               #endif    
  208.                   OS_FLAG_GRP *pgrp;
  209.               
  210.               
  211.                   if (OSIntNesting > 0) {                         /* See if called from ISR ...                      */
  212.                       *err = OS_ERR_CREATE_ISR;                   /* ... can't CREATE from an ISR                    */
  213.                       return ((OS_FLAG_GRP *)0);               
  214.                   }
  215.                   OS_ENTER_CRITICAL();
  216.                   pgrp = OSFlagFreeList;                          /* Get next free event flag                        */
  217.                   if (pgrp != (OS_FLAG_GRP *)0) {                 /* See if we have event flag groups available      */
  218.                                                                   /* Adjust free list                                */
  219.                       OSFlagFreeList       = (OS_FLAG_GRP *)OSFlagFreeList->OSFlagWaitList;
  220.                       pgrp->OSFlagType     = OS_EVENT_TYPE_FLAG;  /* Set to event flag group type                    */
  221.                       pgrp->OSFlagFlags    = flags;               /* Set to desired initial value                    */
  222.                       pgrp->OSFlagWaitList = (void *)0;           /* Clear list of tasks waiting on flags            */
  223.                       OS_EXIT_CRITICAL();
  224.                       *err                 = OS_NO_ERR;
  225.                   } else {
  226.                       OS_EXIT_CRITICAL();
  227.                       *err                 = OS_FLAG_GRP_DEPLETED;
  228.                   }
  229.                   return (pgrp);                                  /* Return pointer to event flag group              */
  230.               }
  231.               
  232.               /*$PAGE*/
  233.               /*
  234.               *********************************************************************************************************
  235.               *                                     DELETE AN EVENT FLAG GROUP
  236.               *
  237.               * Description: This function deletes an event flag group and readies all tasks pending on the event flag
  238.               *              group.
  239.               *
  240.               * Arguments  : pgrp          is a pointer to the desired event flag group.
  241.               *
  242.               *              opt           determines delete options as follows:
  243.               *                            opt == OS_DEL_NO_PEND   Deletes the event flag group ONLY if no task pending
  244.               *                            opt == OS_DEL_ALWAYS    Deletes the event flag group even if tasks are 
  245.               *                                                    waiting.  In this case, all the tasks pending will be
  246.              - 
  247.               *                                                    readied.
  248.               *
  249.               *              err           is a pointer to an error code that can contain one of the following values:
  250. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 5   
  251.               *                            OS_NO_ERR               The call was successful and the event flag group was 
  252.               *                                                    deleted
  253.               *                            OS_ERR_DEL_ISR          If you attempted to delete the event flag group from 
  254.               *                                                    an ISR
  255.               *                            OS_FLAG_INVALID_PGRP    If 'pgrp' is a NULL pointer.
  256.               *                            OS_ERR_EVENT_TYPE       You are not pointing to an event flag group
  257.               *                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to an event flag group
  258.               *                            OS_ERR_INVALID_OPT      An invalid option was specified
  259.               *                            OS_ERR_TASK_WAITING     One or more tasks were waiting on the event flag 
  260.               *                                                    group.
  261.               *
  262.               * Returns    : pevent        upon error
  263.               *              (OS_EVENT *)0 if the semaphore was successfully deleted.
  264.               *
  265.               * Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
  266.               *                 the event flag group MUST check the return code of OSFlagAccept() and OSFlagPend().
  267.               *              2) This call can potentially disable interrupts for a long time.  The interrupt disable
  268.               *                 time is directly proportional to the number of tasks waiting on the event flag group.
  269.               *********************************************************************************************************
  270.               */
  271.               
  272.               #if OS_FLAG_DEL_EN > 0
  273.               OS_FLAG_GRP  *OSFlagDel (OS_FLAG_GRP *pgrp, INT8U opt, INT8U *err) reentrant
  274.               {
  275.               #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
  276.                   OS_CPU_SR     cpu_sr;
  277.               #endif    
  278.                   BOOLEAN       tasks_waiting;
  279.                   OS_FLAG_NODE *pnode;
  280.               
  281.               
  282.                   if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
  283.                       *err = OS_ERR_DEL_ISR;                             /* ... can't DELETE from an ISR             */
  284.                       return (pgrp);
  285.                   }
  286.               #if OS_ARG_CHK_EN > 0
  287.                   if (pgrp == (OS_FLAG_GRP *)0) {                        /* Validate 'pgrp'                          */
  288.                       *err = OS_FLAG_INVALID_PGRP;
  289.                       return (pgrp);
  290.                   }
  291.                   if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {          /* Validate event group type                */
  292.                       *err = OS_ERR_EVENT_TYPE;
  293.                       return (pgrp);
  294.                   }
  295.               #endif
  296.                   OS_ENTER_CRITICAL();
  297.                   if (pgrp->OSFlagWaitList != (void *)0) {               /* See if any tasks waiting on event flags  */
  298.                       tasks_waiting = TRUE;                              /* Yes                                      */
  299.                   } else {
  300.                       tasks_waiting = FALSE;                             /* No                                       */
  301.                   }
  302.                   switch (opt) {
  303.                       case OS_DEL_NO_PEND:                               /* Delete group if no task waiting          */
  304.                            if (tasks_waiting == FALSE) {
  305.                                pgrp->OSFlagType     = OS_EVENT_TYPE_UNUSED;
  306.                                pgrp->OSFlagWaitList = (void *)OSFlagFreeList; /* Return group to free list           */
  307.                                OSFlagFreeList       = pgrp;
  308.                                OS_EXIT_CRITICAL();
  309.                                *err                 = OS_NO_ERR;
  310.                                return ((OS_FLAG_GRP *)0);                /* Event Flag Group has been deleted        */
  311.                            } else {
  312.                                OS_EXIT_CRITICAL();
  313. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 6   
  314.                                *err                 = OS_ERR_TASK_WAITING;
  315.                                return (pgrp);
  316.                            }
  317.               
  318.                       case OS_DEL_ALWAYS:                                /* Always delete the event flag group       */
  319.                            pnode = pgrp->OSFlagWaitList;
  320.                            while (pnode != (OS_FLAG_NODE *)0) {          /* Ready ALL tasks waiting for flags        */
  321.                                OS_FlagTaskRdy(pnode, (OS_FLAGS)0);
  322.                                pnode = pnode->OSFlagNodeNext;
  323.                            }
  324.                            pgrp->OSFlagType     = OS_EVENT_TYPE_UNUSED;
  325.                            pgrp->OSFlagWaitList = (void *)OSFlagFreeList;/* Return group to free list                */
  326.                            OSFlagFreeList       = pgrp;
  327.                            OS_EXIT_CRITICAL();
  328.                            if (tasks_waiting == TRUE) {                  /* Reschedule only if task(s) were waiting  */
  329.                                OS_Sched();                               /* Find highest priority task ready to run  */
  330.                            }
  331.                            *err = OS_NO_ERR;
  332.                            return ((OS_FLAG_GRP *)0);                    /* Event Flag Group has been deleted        */
  333.               
  334.                       default:
  335.                            OS_EXIT_CRITICAL();
  336.                            *err = OS_ERR_INVALID_OPT;
  337.                            return (pgrp);
  338.                   }
  339.               }
  340.               #endif
  341.               /*$PAGE*/
  342.               /*
  343.               *********************************************************************************************************
  344.               *                                        WAIT ON AN EVENT FLAG GROUP
  345.               *
  346.               * Description: This function is called to wait for a combination of bits to be set in an event flag 
  347.               *              group.  Your application can wait for ANY bit to be set or ALL bits to be set.
  348.               *
  349.               * Arguments  : pgrp          is a pointer to the desired event flag group.
  350.               *
  351.               *              flags         Is a bit pattern indicating which bit(s) (i.e. flags) you wish to wait for.  
  352.               *                            The bits you want are specified by setting the corresponding bits in 
  353.               *                            'flags'.  e.g. if your application wants to wait for bits 0 and 1 then 
  354.               *                            'flags' would contain 0x03.
  355.               *
  356.               *              wait_type     specifies whether you want ALL bits to be set or ANY of the bits to be set.
  357.               *                            You can specify the following argument:
  358.               *
  359.               *                            OS_FLAG_WAIT_CLR_ALL   You will wait for ALL bits in 'mask' to be clear (0)
  360.               *                            OS_FLAG_WAIT_SET_ALL   You will wait for ALL bits in 'mask' to be set   (1)
  361.               *                            OS_FLAG_WAIT_CLR_ANY   You will wait for ANY bit  in 'mask' to be clear (0)
  362.               *                            OS_FLAG_WAIT_SET_ANY   You will wait for ANY bit  in 'mask' to be set   (1)
  363.               *
  364.               *                            NOTE: Add OS_FLAG_CONSUME if you want the event flag to be 'consumed' by
  365.               *                                  the call.  Example, to wait for any flag in a group AND then clear
  366.               *                                  the flags that are present, set 'wait_type' to:
  367.               *
  368.               *                                  OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME
  369.               *
  370.               *              timeout       is an optional timeout (in clock ticks) that your task will wait for the
  371.               *                            desired bit combination.  If you specify 0, however, your task will wait
  372.               *                            forever at the specified event flag group or, until a message arrives.
  373.               *
  374.               *              err           is a pointer to an error code and can be:
  375.               *                            OS_NO_ERR              The desired bits have been set within the specified
  376. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 7   
  377.               *                                                   'timeout'.
  378.               *                            OS_ERR_PEND_ISR        If you tried to PEND from an ISR
  379.               *                            OS_FLAG_INVALID_PGRP   If 'pgrp' is a NULL pointer.
  380.               *                            OS_ERR_EVENT_TYPE      You are not pointing to an event flag group
  381.               *                            OS_TIMEOUT             The bit(s) have not been set in the specified 
  382.               *                                                   'timeout'.
  383.               *                            OS_FLAG_ERR_WAIT_TYPE  You didn't specify a proper 'wait_type' argument.
  384.               *
  385.               * Returns    : The new state of the flags in the event flag group when the task is resumed or,
  386.               *              0 if a timeout or an error occurred.
  387.               *
  388.               * Called from: Task ONLY
  389.               *********************************************************************************************************
  390.               */
  391.               
  392.               OS_FLAGS  OSFlagPend (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U wait_type, INT16U timeout, INT8U *err) reen
  393.              -trant
  394.               {
  395.               #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
  396.                   OS_CPU_SR     cpu_sr;
  397.               #endif    
  398.                   OS_FLAG_NODE  node;
  399.                   OS_FLAGS      flags_cur;
  400.                   OS_FLAGS      flags_rdy;
  401.                   BOOLEAN       consume;
  402.               
  403.               
  404.                   if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
  405.                       *err = OS_ERR_PEND_ISR;                            /* ... can't PEND from an ISR               */
  406.                       return ((OS_FLAGS)0);
  407.                   }
  408.               #if OS_ARG_CHK_EN > 0
  409.                   if (pgrp == (OS_FLAG_GRP *)0) {                        /* Validate 'pgrp'                          */
  410.                       *err = OS_FLAG_INVALID_PGRP;
  411.                       return ((OS_FLAGS)0);
  412.                   }
  413.                   if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {          /* Validate event block type                */
  414.                       *err = OS_ERR_EVENT_TYPE;
  415.                       return ((OS_FLAGS)0);
  416.                   }
  417.               #endif
  418.                   if (wait_type & OS_FLAG_CONSUME) {                     /* See if we need to consume the flags      */
  419.                       wait_type &= ~OS_FLAG_CONSUME;
  420.                       consume    = TRUE;
  421.                   } else {
  422.                       consume    = FALSE;
  423.                   }
  424.               /*$PAGE*/
  425.                   OS_ENTER_CRITICAL();
  426.                   switch (wait_type) {
  427.                       case OS_FLAG_WAIT_SET_ALL:                         /* See if all required flags are set        */
  428.                            flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we want            */
  429.                            if (flags_rdy == flags) {                     /* Must match ALL the bits that we want     */
  430.                                if (consume == TRUE) {                    /* See if we need to consume the flags      */
  431.                                    pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we wanted      */
  432.                                }
  433.                                flags_cur = pgrp->OSFlagFlags;            /* Will return the state of the group       */
  434.                                OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
  435.                                *err      = OS_NO_ERR;
  436.                                return (flags_cur);
  437.                            } else {                                      /* Block task until events occur or timeout */
  438.                                OS_FlagBlock(pgrp, &node, flags, wait_type, timeout); 
  439. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 8   
  440.                                OS_EXIT_CRITICAL();
  441.                            }
  442.                            break;
  443.               
  444.                       case OS_FLAG_WAIT_SET_ANY:
  445.                            flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we want            */
  446.                            if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag set                      */
  447.                                if (consume == TRUE) {                    /* See if we need to consume the flags      */
  448.                                    pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we got         */
  449.                                }
  450.                                flags_cur = pgrp->OSFlagFlags;            /* Will return the state of the group       */
  451.                                OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
  452.                                *err      = OS_NO_ERR;
  453.                                return (flags_cur);
  454.                            } else {                                      /* Block task until events occur or timeout */
  455.                                OS_FlagBlock(pgrp, &node, flags, wait_type, timeout); 
  456.                                OS_EXIT_CRITICAL();
  457.                            }
  458.                            break;
  459.               
  460.               #if OS_FLAG_WAIT_CLR_EN > 0
  461.                       case OS_FLAG_WAIT_CLR_ALL:                         /* See if all required flags are cleared    */
  462.                            flags_rdy = ~pgrp->OSFlagFlags & flags;       /* Extract only the bits we want            */
  463.                            if (flags_rdy == flags) {                     /* Must match ALL the bits that we want     */
  464.                                if (consume == TRUE) {                    /* See if we need to consume the flags      */
  465.                                    pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we wanted        */
  466.                                }
  467.                                flags_cur = pgrp->OSFlagFlags;            /* Will return the state of the group       */
  468.                                OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
  469.                                *err      = OS_NO_ERR;
  470.                                return (flags_cur);
  471.                            } else {                                      /* Block task until events occur or timeout */
  472.                                OS_FlagBlock(pgrp, &node, flags, wait_type, timeout); 
  473.                                OS_EXIT_CRITICAL();
  474.                            }
  475.                            break;
  476.               
  477.                       case OS_FLAG_WAIT_CLR_ANY:
  478.                            flags_rdy = ~pgrp->OSFlagFlags & flags;       /* Extract only the bits we want            */
  479.                            if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag cleared                  */
  480.                                if (consume == TRUE) {                    /* See if we need to consume the flags      */
  481.                                    pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we got           */
  482.                                }
  483.                                flags_cur = pgrp->OSFlagFlags;            /* Will return the state of the group       */
  484.                                OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
  485.                                *err      = OS_NO_ERR;
  486.                                return (flags_cur);
  487.                            } else {                                      /* Block task until events occur or timeout */
  488.                                OS_FlagBlock(pgrp, &node, flags, wait_type, timeout); 
  489.                                OS_EXIT_CRITICAL();
  490.                            }
  491.                            break;
  492.               #endif
  493.               
  494.                       default:
  495.                            OS_EXIT_CRITICAL();
  496.                            flags_cur = (OS_FLAGS)0;
  497.                            *err      = OS_FLAG_ERR_WAIT_TYPE;
  498.                            return (flags_cur);
  499.                   }
  500.                   OS_Sched();                                            /* Find next HPT ready to run               */
  501.                   OS_ENTER_CRITICAL();
  502. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 9   
  503.                   if (OSTCBCur->OSTCBStat & OS_STAT_FLAG) {              /* Have we timed-out?                       */
  504.                       OS_FlagUnlink(&node);
  505.                       OSTCBCur->OSTCBStat = OS_STAT_RDY;                 /* Yes, make task ready-to-run              */
  506.                       OS_EXIT_CRITICAL();
  507.                       flags_cur           = (OS_FLAGS)0;
  508.                       *err                = OS_TIMEOUT;                  /* Indicate that we timed-out waiting       */
  509.                   } else {
  510.                       if (consume == TRUE) {                             /* See if we need to consume the flags      */
  511.                           switch (wait_type) {
  512.                               case OS_FLAG_WAIT_SET_ALL:
  513.                               case OS_FLAG_WAIT_SET_ANY:                 /* Clear ONLY the flags we got              */
  514.                                    pgrp->OSFlagFlags &= ~OSTCBCur->OSTCBFlagsRdy;
  515.                                    break;
  516.                                    
  517.               #if OS_FLAG_WAIT_CLR_EN > 0
  518.                               case OS_FLAG_WAIT_CLR_ALL:
  519.                               case OS_FLAG_WAIT_CLR_ANY:                 /* Set   ONLY the flags we got              */
  520.                                    pgrp->OSFlagFlags |= OSTCBCur->OSTCBFlagsRdy;
  521.                                    break;
  522.               #endif
  523.                           }
  524.                       }
  525.                       flags_cur = pgrp->OSFlagFlags;
  526.                       OS_EXIT_CRITICAL();
  527.                       *err      = OS_NO_ERR;                             /* Event(s) must have occurred              */
  528.                   }
  529.                   return (flags_cur);
  530.               }
  531.               /*$PAGE*/
  532.               /*
  533.               *********************************************************************************************************
  534.               *                                         POST EVENT FLAG BIT(S)
  535.               *
  536.               * Description: This function is called to set or clear some bits in an event flag group.  The bits to 
  537.               *              set or clear are specified by a 'bit mask'.
  538.               *
  539.               * Arguments  : pgrp          is a pointer to the desired event flag group.
  540.               *
  541.               *              flags         If 'opt' (see below) is OS_FLAG_SET, each bit that is set in 'flags' will 
  542.               *                            set the corresponding bit in the event flag group.  e.g. to set bits 0, 4 
  543.               *                            and 5 you would set 'flags' to:
  544.               *
  545.               *                                0x31     (note, bit 0 is least significant bit)
  546.               *
  547.               *                            If 'opt' (see below) is OS_FLAG_CLR, each bit that is set in 'flags' will 
  548.               *                            CLEAR the corresponding bit in the event flag group.  e.g. to clear bits 0, 
  549.               *                            4 and 5 you would specify 'flags' as:
  550.               *
  551.               *                                0x31     (note, bit 0 is least significant bit)
  552.               *
  553.               *              opt           indicates whether the flags will be:
  554.               *                                set     (OS_FLAG_SET) or 
  555.               *                                cleared (OS_FLAG_CLR)
  556.               *
  557.               *              err           is a pointer to an error code and can be:
  558.               *                            OS_NO_ERR              The call was successfull
  559.               *                            OS_FLAG_INVALID_PGRP   You passed a NULL pointer
  560.               *                            OS_ERR_EVENT_TYPE      You are not pointing to an event flag group
  561.               *                            OS_FLAG_INVALID_OPT    You specified an invalid option
  562.               *
  563.               * Returns    : the new value of the event flags bits that are still set.
  564.               *
  565. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 10  
  566.               * Called From: Task or ISR
  567.               *
  568.               * WARNING(s) : 1) The execution time of this function depends on the number of tasks waiting on the event 
  569.               *                 flag group.
  570.               *              2) The amount of time interrupts are DISABLED depends on the number of tasks waiting on
  571.               *                 the event flag group.        
  572.               *********************************************************************************************************
  573.               */
  574.               OS_FLAGS  OSFlagPost (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U opt, INT8U *err) reentrant
  575.               {
  576.               #if OS_CRITICAL_METHOD == 3                          /* Allocate storage for CPU status register       */
  577.                   OS_CPU_SR     cpu_sr;
  578.               #endif    
  579.                   OS_FLAG_NODE *pnode;
  580.                   BOOLEAN       sched;
  581.                   OS_FLAGS      flags_cur;
  582.                   OS_FLAGS      flags_rdy;
  583.               
  584.               
  585.               #if OS_ARG_CHK_EN > 0
  586.                   if (pgrp == (OS_FLAG_GRP *)0) {                  /* Validate 'pgrp'                                */
  587.                       *err = OS_FLAG_INVALID_PGRP;
  588.                       return ((OS_FLAGS)0);
  589.                   }
  590.                   if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {    /* Make sure we are pointing to an event flag grp */
  591.                       *err = OS_ERR_EVENT_TYPE;
  592.                       return ((OS_FLAGS)0);
  593.                   }
  594.               #endif
  595.               /*$PAGE*/
  596.                   OS_ENTER_CRITICAL();
  597.                   switch (opt) {
  598.                       case OS_FLAG_CLR:
  599.                            pgrp->OSFlagFlags &= ~flags;            /* Clear the flags specified in the group         */
  600.                            break;
  601.                            
  602.                       case OS_FLAG_SET:
  603.                            pgrp->OSFlagFlags |=  flags;            /* Set   the flags specified in the group         */
  604.                            break;
  605.                         
  606.                       default:
  607.                            OS_EXIT_CRITICAL();                     /* INVALID option                                 */
  608.                            *err = OS_FLAG_INVALID_OPT;
  609.                            return ((OS_FLAGS)0);
  610.                   }
  611.                   sched = FALSE;                                   /* Indicate that we don't need rescheduling       */
  612.                   pnode = pgrp->OSFlagWaitList;                
  613.                   while (pnode != (OS_FLAG_NODE *)0) {             /* Go through all tasks waiting on event flag(s)  */
  614.                       switch (pnode->OSFlagNodeWaitType) {
  615.                           case OS_FLAG_WAIT_SET_ALL:               /* See if all req. flags are set for current node */
  616.                                flags_rdy = pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
  617.                                if (flags_rdy == pnode->OSFlagNodeFlags) {     
  618.                                    if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, event(s) Rx'd   */
  619.                                        sched = TRUE;                               /* When done we will reschedule   */
  620.                                    }
  621.                                }
  622.                                break;
  623.               
  624.                           case OS_FLAG_WAIT_SET_ANY:               /* See if any flag set                            */
  625.                                flags_rdy = pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
  626.                                if (flags_rdy != (OS_FLAGS)0) {    
  627.                                    if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, event(s) Rx'd   */
  628. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 11  
  629.                                        sched = TRUE;                               /* When done we will reschedule   */
  630.                                    }
  631.                                }
  632.                                break;
  633.               
  634.               #if OS_FLAG_WAIT_CLR_EN > 0
  635.                           case OS_FLAG_WAIT_CLR_ALL:               /* See if all req. flags are set for current node */
  636.                                flags_rdy = ~pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
  637.                                if (flags_rdy == pnode->OSFlagNodeFlags) {     
  638.                                    if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, event(s) Rx'd   */
  639.                                        sched = TRUE;                               /* When done we will reschedule   */
  640.                                    }
  641.                                }
  642.                                break;
  643.               
  644.                           case OS_FLAG_WAIT_CLR_ANY:               /* See if any flag set                            */
  645.                                flags_rdy = ~pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
  646.                                if (flags_rdy != (OS_FLAGS)0) {    
  647.                                    if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, event(s) Rx'd   */
  648.                                        sched = TRUE;                               /* When done we will reschedule   */
  649.                                    }
  650.                                }
  651.                                break;
  652.               #endif                 
  653.                       }
  654.                       pnode = pnode->OSFlagNodeNext;               /* Point to next task waiting for event flag(s)   */
  655.                   }
  656.                   OS_EXIT_CRITICAL();
  657.                   if (sched == TRUE) {
  658.                       OS_Sched();
  659.                   }
  660.                   OS_ENTER_CRITICAL();
  661.                   flags_cur = pgrp->OSFlagFlags;
  662.                   OS_EXIT_CRITICAL();
  663.                   *err      = OS_NO_ERR;
  664.                   return (flags_cur);
  665.               }
  666.               /*$PAGE*/
  667.               /*
  668.               *********************************************************************************************************
  669.               *                                           QUERY EVENT FLAG 
  670.               *
  671.               * Description: This function is used to check the value of the event flag group.
  672.               *
  673.               * Arguments  : pgrp         is a pointer to the desired event flag group.
  674.               *
  675.               *              err           is a pointer to an error code returned to the called:
  676.               *                            OS_NO_ERR              The call was successfull
  677.               *                            OS_FLAG_INVALID_PGRP   You passed a NULL pointer
  678.               *                            OS_ERR_EVENT_TYPE      You are not pointing to an event flag group
  679.               *
  680.               * Returns    : The current value of the event flag group.
  681.               *
  682.               * Called From: Task or ISR
  683.               *********************************************************************************************************
  684.               */
  685.               
  686.               #if OS_FLAG_QUERY_EN > 0
  687.               OS_FLAGS  OSFlagQuery (OS_FLAG_GRP *pgrp, INT8U *err) reentrant
  688.               {
  689.               #if OS_CRITICAL_METHOD == 3                       /* Allocate storage for CPU status register          */
  690.                   OS_CPU_SR  cpu_sr;
  691. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 12  
  692.               #endif    
  693.                   OS_FLAGS   flags;
  694.               
  695.               
  696.               #if OS_ARG_CHK_EN > 0
  697.                   if (pgrp == (OS_FLAG_GRP *)0) {               /* Validate 'pgrp'                                   */
  698.                       *err = OS_FLAG_INVALID_PGRP;
  699.                       return ((OS_FLAGS)0);
  700.                   }
  701.                   if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) { /* Validate event block type                         */
  702.                       *err = OS_ERR_EVENT_TYPE;
  703.                       return ((OS_FLAGS)0);
  704.                   }
  705.               #endif    
  706.                   OS_ENTER_CRITICAL();
  707.                   flags = pgrp->OSFlagFlags;
  708.                   OS_EXIT_CRITICAL();
  709.                   *err = OS_NO_ERR;
  710.                   return (flags);                               /* Return the current value of the event flags       */
  711.               }
  712.               #endif
  713.               
  714.               /*$PAGE*/
  715.               /*
  716.               *********************************************************************************************************
  717.               *                         SUSPEND TASK UNTIL EVENT FLAG(s) RECEIVED OR TIMEOUT OCCURS
  718.               *
  719.               * Description: This function is internal to uC/OS-II and is used to put a task to sleep until the desired
  720.               *              event flag bit(s) are set.
  721.               *
  722.               * Arguments  : pgrp          is a pointer to the desired event flag group.
  723.               *
  724.               *              pnode         is a pointer to a structure which contains data about the task waiting for 
  725.               *                            event flag bit(s) to be set.
  726.               *
  727.               *              flags         Is a bit pattern indicating which bit(s) (i.e. flags) you wish to check.  
  728.               *                            The bits you want are specified by setting the corresponding bits in 
  729.               *                            'flags'.  e.g. if your application wants to wait for bits 0 and 1 then 
  730.               *                            'flags' would contain 0x03.
  731.               *
  732.               *              wait_type     specifies whether you want ALL bits to be set/cleared or ANY of the bits 
  733.               *                            to be set/cleared.
  734.               *                            You can specify the following argument:
  735.               *
  736.               *                            OS_FLAG_WAIT_CLR_ALL   You will check ALL bits in 'mask' to be clear (0)
  737.               *                            OS_FLAG_WAIT_CLR_ANY   You will check ANY bit  in 'mask' to be clear (0)
  738.               *                            OS_FLAG_WAIT_SET_ALL   You will check ALL bits in 'mask' to be set   (1)
  739.               *                            OS_FLAG_WAIT_SET_ANY   You will check ANY bit  in 'mask' to be set   (1)
  740.               *
  741.               *              timeout       is the desired amount of time that the task will wait for the event flag 
  742.               *                            bit(s) to be set.
  743.               *
  744.               * Returns    : none
  745.               *
  746.               * Called by  : OSFlagPend()  OS_FLAG.C
  747.               *
  748.               * Note(s)    : This function is INTERNAL to uC/OS-II and your application should not call it.
  749.               *********************************************************************************************************
  750.               */
  751.               
  752.               static  void  OS_FlagBlock (OS_FLAG_GRP *pgrp, OS_FLAG_NODE *pnode, OS_FLAGS flags, INT8U wait_type, INT16
  753.              -U timeout) reentrant
  754. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 13  
  755.               {
  756.                   OS_FLAG_NODE  *pnode_next;
  757.               
  758.               
  759.                   OSTCBCur->OSTCBStat      |= OS_STAT_FLAG;
  760.                   OSTCBCur->OSTCBDly        = timeout;              /* Store timeout in task's TCB                   */
  761.               #if OS_TASK_DEL_EN > 0
  762.                   OSTCBCur->OSTCBFlagNode   = pnode;                /* TCB to link to node                           */
  763.               #endif    
  764.                   pnode->OSFlagNodeFlags    = flags;                /* Save the flags that we need to wait for       */
  765.                   pnode->OSFlagNodeWaitType = wait_type;            /* Save the type of wait we are doing            */
  766.                   pnode->OSFlagNodeTCB      = (void *)OSTCBCur;     /* Link to task's TCB                            */
  767.                   pnode->OSFlagNodeNext     = pgrp->OSFlagWaitList; /* Add node at beginning of event flag wait list */
  768.                   pnode->OSFlagNodePrev     = (void *)0;
  769.                   pnode->OSFlagNodeFlagGrp  = (void *)pgrp;         /* Link to Event Flag Group                      */
  770.                   pnode_next                = pgrp->OSFlagWaitList;
  771.                   if (pnode_next != (void *)0) {                    /* Is this the first NODE to insert?             */
  772.                       pnode_next->OSFlagNodePrev = pnode;           /* No, link in doubly linked list                */
  773.                   } 
  774.                   pgrp->OSFlagWaitList = (void *)pnode;
  775.                                                                     /* Suspend current task until flag(s) received   */
  776.                   if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0) {
  777.                       OSRdyGrp &= ~OSTCBCur->OSTCBBitY;
  778.                   }
  779.               }
  780.               
  781.               /*$PAGE*/
  782.               /*
  783.               *********************************************************************************************************
  784.               *                                    INITIALIZE THE EVENT FLAG MODULE
  785.               *
  786.               * Description: This function is called by uC/OS-II to initialize the event flag module.  Your application
  787.               *              MUST NOT call this function.  In other words, this function is internal to uC/OS-II.
  788.               *
  789.               * Arguments  : none
  790.               *
  791.               * Returns    : none
  792.               *
  793.               * WARNING    : You MUST NOT call this function from your code.  This is an INTERNAL function to uC/OS-II.
  794.               *********************************************************************************************************
  795.               */
  796.               
  797.               void  OS_FlagInit (void) reentrant
  798.               {
  799.               #if OS_MAX_FLAGS == 1
  800.                   OSFlagFreeList                 = (OS_FLAG_GRP *)&OSFlagTbl[0];  /* Only ONE event flag group!      */
  801.                   OSFlagFreeList->OSFlagType     = OS_EVENT_TYPE_UNUSED;
  802.                   OSFlagFreeList->OSFlagWaitList = (void *)0;
  803.               #endif
  804.               
  805.               #if OS_MAX_FLAGS >= 2
  806.                   INT8U        i;
  807.                   OS_FLAG_GRP *pgrp1;
  808.                   OS_FLAG_GRP *pgrp2;
  809.               
  810.               
  811.                   pgrp1 = &OSFlagTbl[0];
  812.                   pgrp2 = &OSFlagTbl[1];
  813.                   for (i = 0; i < (OS_MAX_FLAGS - 1); i++) {                      /* Init. list of free EVENT FLAGS  */
  814.                       pgrp1->OSFlagType     = OS_EVENT_TYPE_UNUSED;
  815.                       pgrp1->OSFlagWaitList = (void *)pgrp2;
  816.                       pgrp1++;
  817. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 14  
  818.                       pgrp2++;
  819.                   }
  820.                   pgrp1->OSFlagWaitList = (void *)0;
  821.                   OSFlagFreeList        = (OS_FLAG_GRP *)&OSFlagTbl[0];
  822.               #endif    
  823.               }
  824.               
  825.               /*$PAGE*/
  826.               /*
  827.               *********************************************************************************************************
  828.               *                              MAKE TASK READY-TO-RUN, EVENT(s) OCCURRED
  829.               *
  830.               * Description: This function is internal to uC/OS-II and is used to make a task ready-to-run because the
  831.               *              desired event flag bits have been set.
  832.               *
  833.               * Arguments  : pnode         is a pointer to a structure which contains data about the task waiting for 
  834.               *                            event flag bit(s) to be set.
  835.               *
  836.               *              flags_rdy     contains the bit pattern of the event flags that cause the task to become
  837.               *                            ready-to-run.
  838.               *
  839.               * Returns    : none
  840.               *
  841.               * Called by  : OSFlagsPost() OS_FLAG.C
  842.               *
  843.               * Note(s)    : 1) This function assumes that interrupts are disabled.
  844.               *              2) This function is INTERNAL to uC/OS-II and your application should not call it.
  845.               *********************************************************************************************************
  846.               */
  847.               
  848.               static  BOOLEAN  OS_FlagTaskRdy (OS_FLAG_NODE *pnode, OS_FLAGS flags_rdy) reentrant
  849.               {
  850.                   OS_TCB   *ptcb;
  851.                   BOOLEAN   sched;
  852.                         
  853.                                                                       
  854.                   ptcb                = (OS_TCB *)pnode->OSFlagNodeTCB;  /* Point to TCB of waiting task             */
  855.                   ptcb->OSTCBDly      = 0;
  856.                   ptcb->OSTCBFlagsRdy = flags_rdy;
  857.                   ptcb->OSTCBStat    &= ~OS_STAT_FLAG;
  858.                   if (ptcb->OSTCBStat == OS_STAT_RDY) {                  /* Put task into ready list                 */
  859.                       OSRdyGrp               |= ptcb->OSTCBBitY;
  860.                       OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
  861.                       sched                   = TRUE;
  862.                   } else {
  863.                       sched                   = FALSE;
  864.                   }
  865.                   OS_FlagUnlink(pnode);
  866.                   return (sched);
  867.               }
  868.               
  869.               /*$PAGE*/
  870.               /*
  871.               *********************************************************************************************************
  872.               *                                  UNLINK EVENT FLAG NODE FROM WAITING LIST
  873.               *
  874.               * Description: This function is internal to uC/OS-II and is used to unlink an event flag node from a
  875.               *              list of tasks waiting for the event flag.
  876.               *
  877.               * Arguments  : pnode         is a pointer to a structure which contains data about the task waiting for 
  878.               *                            event flag bit(s) to be set.
  879.               *
  880. C51 COMPILER V8.02   OS_FLAG                                                               06/22/2006 11:44:36 PAGE 15  
  881.               * Returns    : none
  882.               *
  883.               * Called by  : OS_FlagTaskRdy() OS_FLAG.C
  884.               *              OSFlagPend()     OS_FLAG.C
  885.               *              OSTaskDel()      OS_TASK.C
  886.               *
  887.               * Note(s)    : 1) This function assumes that interrupts are disabled.
  888.               *              2) This function is INTERNAL to uC/OS-II and your application should not call it.
  889.               *********************************************************************************************************
  890.               */
  891.               
  892.               void  OS_FlagUnlink (OS_FLAG_NODE *pnode) reentrant
  893.               {
  894.                   OS_TCB       *ptcb;
  895.                   OS_FLAG_GRP  *pgrp;
  896.                   OS_FLAG_NODE *pnode_prev;
  897.                   OS_FLAG_NODE *pnode_next;
  898.                   
  899.                   
  900.                   pnode_prev = pnode->OSFlagNodePrev;
  901.                   pnode_next = pnode->OSFlagNodeNext;
  902.                   if (pnode_prev == (OS_FLAG_NODE *)0) {                      /* Is it first node in wait list?      */
  903.                       pgrp                 = pnode->OSFlagNodeFlagGrp;        /* Yes, Point to event flag group      */
  904.                       pgrp->OSFlagWaitList = (void *)pnode_next;              /*      Update list for new 1st node   */
  905.                       if (pnode_next != (OS_FLAG_NODE *)0) {       
  906.                           pnode_next->OSFlagNodePrev = (OS_FLAG_NODE *)0;     /*      Link new 1st node PREV to NULL */
  907.                       }
  908.                   } else {                                                    /* No,  A node somewhere in the list   */
  909.                       pnode_prev->OSFlagNodeNext = pnode_next;                /*      Link around the node to unlink */
  910.                       if (pnode_next != (OS_FLAG_NODE *)0) {                  /*      Was this the LAST node?        */
  911.                           pnode_next->OSFlagNodePrev = pnode_prev;            /*      No, Link around current node   */
  912.                       }
  913.                   }
  914.                   ptcb                = (OS_TCB *)pnode->OSFlagNodeTCB;
  915.               #if OS_TASK_DEL_EN > 0
  916.                   ptcb->OSTCBFlagNode = (void *)0;
  917.               #endif
  918.               }
  919.               #endif
  920. MODULE INFORMATION:   STATIC OVERLAYABLE
  921.    CODE SIZE        =   ----    ----
  922.    CONSTANT SIZE    =   ----    ----
  923.    XDATA SIZE       =   ----    ----
  924.    PDATA SIZE       =   ----    ----
  925.    DATA SIZE        =   ----    ----
  926.    IDATA SIZE       =   ----    ----
  927.    BIT SIZE         =   ----    ----
  928. END OF MODULE INFORMATION.
  929. C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)