⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_flag.lst

📁 在51上运行的小的OS系统
💻 LST
📖 第 1 页 / 共 5 页
字号:
 134                           if (consume == TRUE) {                    /* See if we need to consume the flags      */
 135                               pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we got         */
 136                           }
 137                       } else {
 138                           *err  = OS_FLAG_ERR_NOT_RDY;
 139                       }
 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 = (OS_FLAGS)~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                       OS_EXIT_CRITICAL();
 154                       break;
 155          
 156                  case OS_FLAG_WAIT_CLR_ANY:
 157                       flags_rdy = (OS_FLAGS)~pgrp->OSFlagFlags & flags; /* Extract only the bits we want        */
 158                       if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag cleared                  */
 159                           if (consume == TRUE) {                    /* See if we need to consume the flags      */
 160                               pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we got           */
 161                           }
 162                       } else {
 163                           *err  = OS_FLAG_ERR_NOT_RDY;
 164                       }
 165                       OS_EXIT_CRITICAL();
 166                       break;
 167          #endif
 168          
 169                  default:
 170                       OS_EXIT_CRITICAL();
 171                       flags_rdy = (OS_FLAGS)0;
 172                       *err      = OS_FLAG_ERR_WAIT_TYPE;
 173                       break;
 174              }
 175              return (flags_rdy);
 176          }
 177          #endif
 178          
 179          /*$PAGE*/
 180          /*
 181          *********************************************************************************************************
 182          *                                           CREATE AN EVENT FLAG
C51 COMPILER V8.08   OS_FLAG                                                               08/04/2008 21:49:51 PAGE 5   

 183          *
 184          * Description: This function is called to create an event flag group.
 185          *
 186          * Arguments  : flags         Contains the initial value to store in the event flag group.
 187          *
 188          *              err           is a pointer to an error code which will be returned to your application:
 189          *                               OS_NO_ERR                if the call was successful.
 190          *                               OS_ERR_CREATE_ISR        if you attempted to create an Event Flag from an
 191          *                                                        ISR.
 192          *                               OS_FLAG_GRP_DEPLETED     if there are no more event flag groups
 193          *
 194          * Returns    : A pointer to an event flag group or a NULL pointer if no more groups are available.
 195          *
 196          * Called from: Task ONLY
 197          *********************************************************************************************************
 198          */
 199          
 200          OS_FLAG_GRP  *OSFlagCreate (OS_FLAGS flags, INT8U *err)
 201          {
 202              OS_FLAG_GRP *pgrp;
 203          #if OS_CRITICAL_METHOD == 3                         /* Allocate storage for CPU status register        */
                  OS_CPU_SR    cpu_sr = 0;
              #endif
 206          
 207          
 208          
 209          #if OS_ARG_CHK_EN > 0
 210              if (err == (INT8U *)0) {                        /* Validate 'err'                                  */
 211                  return ((OS_FLAG_GRP *)0);
 212              }
 213          #endif
 214              if (OSIntNesting > 0) {                         /* See if called from ISR ...                      */
 215                  *err = OS_ERR_CREATE_ISR;                   /* ... can't CREATE from an ISR                    */
 216                  return ((OS_FLAG_GRP *)0);
 217              }
 218              OS_ENTER_CRITICAL();
 219              pgrp = OSFlagFreeList;                          /* Get next free event flag                        */
 220              if (pgrp != (OS_FLAG_GRP *)0) {                 /* See if we have event flag groups available      */
 221                                                              /* Adjust free list                                */
 222                  OSFlagFreeList       = (OS_FLAG_GRP *)OSFlagFreeList->OSFlagWaitList;
 223                  pgrp->OSFlagType     = OS_EVENT_TYPE_FLAG;  /* Set to event flag group type                    */
 224                  pgrp->OSFlagFlags    = flags;               /* Set to desired initial value                    */
 225                  pgrp->OSFlagWaitList = (void *)0;           /* Clear list of tasks waiting on flags            */
 226          #if OS_FLAG_NAME_SIZE > 1
 227                  pgrp->OSFlagName[0]  = '?';
 228                  pgrp->OSFlagName[1]  = OS_ASCII_NUL;
 229          #endif
 230                  OS_EXIT_CRITICAL();
 231                  *err                 = OS_NO_ERR;
 232              } else {
 233                  OS_EXIT_CRITICAL();
 234                  *err                 = OS_FLAG_GRP_DEPLETED;
 235              }
 236              return (pgrp);                                  /* Return pointer to event flag group              */
 237          }
 238          
 239          /*$PAGE*/
 240          /*
 241          *********************************************************************************************************
 242          *                                     DELETE AN EVENT FLAG GROUP
 243          *
 244          * Description: This function deletes an event flag group and readies all tasks pending on the event flag
C51 COMPILER V8.08   OS_FLAG                                                               08/04/2008 21:49:51 PAGE 6   

 245          *              group.
 246          *
 247          * Arguments  : pgrp          is a pointer to the desired event flag group.
 248          *
 249          *              opt           determines delete options as follows:
 250          *                            opt == OS_DEL_NO_PEND   Deletes the event flag group ONLY if no task pending
 251          *                            opt == OS_DEL_ALWAYS    Deletes the event flag group even if tasks are
 252          *                                                    waiting.  In this case, all the tasks pending will be
 253          *                                                    readied.
 254          *
 255          *              err           is a pointer to an error code that can contain one of the following values:
 256          *                            OS_NO_ERR               The call was successful and the event flag group was
 257          *                                                    deleted
 258          *                            OS_ERR_DEL_ISR          If you attempted to delete the event flag group from
 259          *                                                    an ISR
 260          *                            OS_FLAG_INVALID_PGRP    If 'pgrp' is a NULL pointer.
 261          *                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to an event flag group
 262          *                            OS_ERR_INVALID_OPT      An invalid option was specified
 263          *                            OS_ERR_TASK_WAITING     One or more tasks were waiting on the event flag
 264          *                                                    group.
 265          *
 266          * Returns    : pgrp          upon error
 267          *              (OS_EVENT *)0 if the event flag group was successfully deleted.
 268          *
 269          * Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
 270          *                 the event flag group MUST check the return code of OSFlagAccept() and OSFlagPend().
 271          *              2) This call can potentially disable interrupts for a long time.  The interrupt disable
 272          *                 time is directly proportional to the number of tasks waiting on the event flag group.
 273          *********************************************************************************************************
 274          */
 275          
 276          #if OS_FLAG_DEL_EN > 0
 277          OS_FLAG_GRP  *OSFlagDel (OS_FLAG_GRP *pgrp, INT8U opt, INT8U *err)
 278          {
 279              BOOLEAN       tasks_waiting;
 280              OS_FLAG_NODE *pnode;
 281              OS_FLAG_GRP  *pgrp_return;
 282          #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR     cpu_sr = 0;
              #endif
 285          
 286          
 287          
 288          #if OS_ARG_CHK_EN > 0
 289              if (err == (INT8U *)0) {                               /* Validate 'err'                           */
 290                  return (pgrp);
 291              }
 292              if (pgrp == (OS_FLAG_GRP *)0) {                        /* Validate 'pgrp'                          */
 293                  *err = OS_FLAG_INVALID_PGRP;
 294                  return (pgrp);
 295              }
 296          #endif
 297              if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
 298                  *err = OS_ERR_DEL_ISR;                             /* ... can't DELETE from an ISR             */
 299                  return (pgrp);
 300              }
 301              if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {          /* Validate event group type                */
 302                  *err = OS_ERR_EVENT_TYPE;
 303                  return (pgrp);
 304              }
 305              OS_ENTER_CRITICAL();
 306              if (pgrp->OSFlagWaitList != (void *)0) {               /* See if any tasks waiting on event flags  */
C51 COMPILER V8.08   OS_FLAG                                                               08/04/2008 21:49:51 PAGE 7   

 307                  tasks_waiting = TRUE;                              /* Yes                                      */
 308              } else {
 309                  tasks_waiting = FALSE;                             /* No                                       */
 310              }
 311              switch (opt) {
 312                  case OS_DEL_NO_PEND:                               /* Delete group if no task waiting          */
 313                       if (tasks_waiting == FALSE) {
 314          #if OS_FLAG_NAME_SIZE > 1
 315                           pgrp->OSFlagName[0]  = '?';               /* Unknown name                             */
 316                           pgrp->OSFlagName[1]  = OS_ASCII_NUL;
 317          #endif
 318                           pgrp->OSFlagType     = OS_EVENT_TYPE_UNUSED;
 319                           pgrp->OSFlagWaitList = (void *)OSFlagFreeList; /* Return group to free list           */
 320                           pgrp->OSFlagFlags    = (OS_FLAGS)0;
 321                           OSFlagFreeList       = pgrp;
 322                           OS_EXIT_CRITICAL();
 323                           *err                 = OS_NO_ERR;
 324                           pgrp_return          = (OS_FLAG_GRP *)0;  /* Event Flag Group has been deleted        */
 325                       } else {
 326                           OS_EXIT_CRITICAL();
 327                           *err                 = OS_ERR_TASK_WAITING;
 328                           pgrp_return          = pgrp;
 329                       }
 330                       break;
 331          
 332                  case OS_DEL_ALWAYS:                                /* Always delete the event flag group       */
 333                       pnode = (OS_FLAG_NODE *)pgrp->OSFlagWaitList;
 334                       while (pnode != (OS_FLAG_NODE *)0) {          /* Ready ALL tasks waiting for flags        */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -