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

📄 os_flag.lst

📁 uCos-ii 2.86 在C8051F410单片机上移植成功!!! 其中包括:UART驱动
💻 LST
📖 第 1 页 / 共 5 页
字号:
              * Arguments  : flags         Contains the initial value to store in the event flag group.
              *
              *              perr          is a pointer to an error code which will be returned to your application:
              *                               OS_ERR_NONE               if the call was successful.
              *                               OS_ERR_CREATE_ISR         if you attempted to create an Event Flag from an
              *                                                         ISR.
              *                               OS_ERR_FLAG_GRP_DEPLETED  if there are no more event flag groups
              *
              * Returns    : A pointer to an event flag group or a NULL pointer if no more groups are available.
              *
              * Called from: Task ONLY
              *********************************************************************************************************
              */
              
              OS_FLAG_GRP  *OSFlagCreate (OS_FLAGS flags, INT8U *perr) reentrant
              {
                  OS_FLAG_GRP *pgrp;
              #if OS_CRITICAL_METHOD == 3                         /* Allocate storage for CPU status register        */
                  OS_CPU_SR    cpu_sr = 0;
              #endif
              
              
              
              #if OS_ARG_CHK_EN > 0
                  if (perr == (INT8U *)0) {                       /* Validate 'perr'                                 */
                      return ((OS_FLAG_GRP *)0);
                  }
              #endif
                  if (OSIntNesting > 0) {                         /* See if called from ISR ...                      */
                      *perr = OS_ERR_CREATE_ISR;                  /* ... can't CREATE from an ISR                    */
                      return ((OS_FLAG_GRP *)0);
                  }
                  OS_ENTER_CRITICAL();
                  pgrp = OSFlagFreeList;                          /* Get next free event flag                        */
                  if (pgrp != (OS_FLAG_GRP *)0) {                 /* See if we have event flag groups available      */
                                                                  /* Adjust free list                                */
                      OSFlagFreeList       = (OS_FLAG_GRP *)OSFlagFreeList->OSFlagWaitList;
                      pgrp->OSFlagType     = OS_EVENT_TYPE_FLAG;  /* Set to event flag group type                    */
                      pgrp->OSFlagFlags    = flags;               /* Set to desired initial value                    */
                      pgrp->OSFlagWaitList = (void *)0;           /* Clear list of tasks waiting on flags            */
              #if OS_FLAG_NAME_SIZE > 1
                      pgrp->OSFlagName[0]  = '?';
                      pgrp->OSFlagName[1]  = OS_ASCII_NUL;
              #endif
                      OS_EXIT_CRITICAL();
C51 COMPILER V8.17   OS_FLAG                                                               03/26/2009 14:24:24 PAGE 5   

                      *perr                = OS_ERR_NONE;
                  } else {
                      OS_EXIT_CRITICAL();
                      *perr                = OS_ERR_FLAG_GRP_DEPLETED;
                  }
                  return (pgrp);                                  /* Return pointer to event flag group              */
              }
              
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                     DELETE AN EVENT FLAG GROUP
              *
              * Description: This function deletes an event flag group and readies all tasks pending on the event flag
              *              group.
              *
              * Arguments  : pgrp          is a pointer to the desired event flag group.
              *
              *              opt           determines delete options as follows:
              *                            opt == OS_DEL_NO_PEND   Deletes the event flag group ONLY if no task pending
              *                            opt == OS_DEL_ALWAYS    Deletes the event flag group even if tasks are
              *                                                    waiting.  In this case, all the tasks pending will be
              *                                                    readied.
              *
              *              perr          is a pointer to an error code that can contain one of the following values:
              *                            OS_ERR_NONE               The call was successful and the event flag group wa
             -s
              *                                                      deleted
              *                            OS_ERR_DEL_ISR            If you attempted to delete the event flag group fro
             -m
              *                                                      an ISR
              *                            OS_ERR_FLAG_INVALID_PGRP  If 'pgrp' is a NULL pointer.
              *                            OS_ERR_EVENT_TYPE         If you didn't pass a pointer to an event flag group
              *                            OS_ERR_INVALID_OPT        An invalid option was specified
              *                            OS_ERR_TASK_WAITING       One or more tasks were waiting on the event flag
              *                                                      group.
              *
              * Returns    : pgrp          upon error
              *              (OS_EVENT *)0 if the event flag group was successfully deleted.
              *
              * Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
              *                 the event flag group MUST check the return code of OSFlagAccept() and OSFlagPend().
              *              2) This call can potentially disable interrupts for a long time.  The interrupt disable
              *                 time is directly proportional to the number of tasks waiting on the event flag group.
              *********************************************************************************************************
              */
              
              #if OS_FLAG_DEL_EN > 0
              OS_FLAG_GRP  *OSFlagDel (OS_FLAG_GRP *pgrp, INT8U opt, INT8U *perr) reentrant
              {
                  BOOLEAN       tasks_waiting;
                  OS_FLAG_NODE *pnode;
                  OS_FLAG_GRP  *pgrp_return;
              #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR     cpu_sr = 0;
              #endif
              
              
              
              #if OS_ARG_CHK_EN > 0
                  if (perr == (INT8U *)0) {                              /* Validate 'perr'                          */
                      return (pgrp);
C51 COMPILER V8.17   OS_FLAG                                                               03/26/2009 14:24:24 PAGE 6   

                  }
                  if (pgrp == (OS_FLAG_GRP *)0) {                        /* Validate 'pgrp'                          */
                      *perr = OS_ERR_FLAG_INVALID_PGRP;
                      return (pgrp);
                  }
              #endif
                  if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
                      *perr = OS_ERR_DEL_ISR;                            /* ... can't DELETE from an ISR             */
                      return (pgrp);
                  }
                  if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {          /* Validate event group type                */
                      *perr = OS_ERR_EVENT_TYPE;
                      return (pgrp);
                  }
                  OS_ENTER_CRITICAL();
                  if (pgrp->OSFlagWaitList != (void *)0) {               /* See if any tasks waiting on event flags  */
                      tasks_waiting = OS_TRUE;                           /* Yes                                      */
                  } else {
                      tasks_waiting = OS_FALSE;                          /* No                                       */
                  }
                  switch (opt) {
                      case OS_DEL_NO_PEND:                               /* Delete group if no task waiting          */
                           if (tasks_waiting == OS_FALSE) {
              #if OS_FLAG_NAME_SIZE > 1
                               pgrp->OSFlagName[0]  = '?';               /* Unknown name                             */
                               pgrp->OSFlagName[1]  = OS_ASCII_NUL;
              #endif
                               pgrp->OSFlagType     = OS_EVENT_TYPE_UNUSED;
                               pgrp->OSFlagWaitList = (void *)OSFlagFreeList; /* Return group to free list           */
                               pgrp->OSFlagFlags    = (OS_FLAGS)0;
                               OSFlagFreeList       = pgrp;
                               OS_EXIT_CRITICAL();
                               *perr                = OS_ERR_NONE;
                               pgrp_return          = (OS_FLAG_GRP *)0;  /* Event Flag Group has been deleted        */
                           } else {
                               OS_EXIT_CRITICAL();
                               *perr                = OS_ERR_TASK_WAITING;
                               pgrp_return          = pgrp;
                           }
                           break;
              
                      case OS_DEL_ALWAYS:                                /* Always delete the event flag group       */
                           pnode = (OS_FLAG_NODE *)pgrp->OSFlagWaitList;
                           while (pnode != (OS_FLAG_NODE *)0) {          /* Ready ALL tasks waiting for flags        */
                               (void)OS_FlagTaskRdy(pnode, (OS_FLAGS)0);
                               pnode = (OS_FLAG_NODE *)pnode->OSFlagNodeNext;
                           }
              #if OS_FLAG_NAME_SIZE > 1
                           pgrp->OSFlagName[0]  = '?';                   /* Unknown name                             */
                           pgrp->OSFlagName[1]  = OS_ASCII_NUL;
              #endif
                           pgrp->OSFlagType     = OS_EVENT_TYPE_UNUSED;
                           pgrp->OSFlagWaitList = (void *)OSFlagFreeList;/* Return group to free list                */
                           pgrp->OSFlagFlags    = (OS_FLAGS)0;
                           OSFlagFreeList       = pgrp;
                           OS_EXIT_CRITICAL();
                           if (tasks_waiting == OS_TRUE) {               /* Reschedule only if task(s) were waiting  */
                               OS_Sched();                               /* Find highest priority task ready to run  */
                           }
                           *perr = OS_ERR_NONE;
                           pgrp_return          = (OS_FLAG_GRP *)0;      /* Event Flag Group has been deleted        */
                           break;
C51 COMPILER V8.17   OS_FLAG                                                               03/26/2009 14:24:24 PAGE 7   

              
                      default:
                           OS_EXIT_CRITICAL();
                           *perr                = OS_ERR_INVALID_OPT;
                           pgrp_return          = pgrp;
                           break;
                  }
                  return (pgrp_return);
              }
              #endif
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                 GET THE NAME OF AN EVENT FLAG GROUP
              *
              * Description: This function is used to obtain the name assigned to an event flag group
              *
              * Arguments  : pgrp      is a pointer to the event flag group.
              *
              *              pname     is a pointer to an ASCII string that will receive the name of the event flag
              *                        group.  The string must be able to hold at least OS_FLAG_NAME_SIZE characters.
              *
              *              perr      is a pointer to an error code that can contain one of the following values:
              *
              *                        OS_ERR_NONE                if the requested task is resumed
              *                        OS_ERR_EVENT_TYPE          if 'pevent' is not pointing to an event flag group
              *                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
              *                        OS_ERR_FLAG_INVALID_PGRP   if you passed a NULL pointer for 'pgrp'
              *                        OS_ERR_NAME_GET_ISR        if you called this function from an ISR
              *
              * Returns    : The length of the string or 0 if the 'pgrp' is a NULL pointer.
              *********************************************************************************************************
              */
              
              #if OS_FLAG_NAME_SIZE > 1
              INT8U  OSFlagNameGet (OS_FLAG_GRP *pgrp, INT8U *pname, INT8U *perr) reentrant

⌨️ 快捷键说明

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