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

📄 os_sem.lst

📁 该源码是本人经调试通过的UCOS2操作系统在51单片机上移植好的源代码
💻 LST
📖 第 1 页 / 共 2 页
字号:
 214          /*
 215          *********************************************************************************************************
 216          *                                           PEND ON SEMAPHORE
 217          *
 218          * Description: This function waits for a semaphore.
 219          *
 220          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 221          *                            semaphore.
 222          *
 223          *              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
 224          *                            wait for the resource up to the amount of time specified by this argument.
 225          *                            If you specify 0, however, your task will wait forever at the specified
 226          *                            semaphore or, until the resource becomes available (or the event occurs).
 227          *
 228          *              err           is a pointer to where an error message will be deposited.  Possible error
 229          *                            messages are:
 230          *
 231          *                            OS_NO_ERR           The call was successful and your task owns the resource
 232          *                                                or, the event you are waiting for occurred.
 233          *                            OS_TIMEOUT          The semaphore was not received within the specified
 234          *                                                timeout.
 235          *                            OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore.
 236          *                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
 237          *                                                would lead to a suspension.
 238          *                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
 239          *
 240          * Returns    : none
 241          *********************************************************************************************************
C51 COMPILER V7.20   OS_SEM                                                                06/14/2006 20:19:47 PAGE 5   

 242          */
 243          #if OS_SEM_PEND_EN>0
 244          void  OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)  reentrant
 245          {
 246   1      #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr;
              #endif    
 249   1      
 250   1      
 251   1          if (OSIntNesting > 0) {                           /* See if called from ISR ...                    */
 252   2              *err = OS_ERR_PEND_ISR;                       /* ... can't PEND from an ISR                    */
 253   2              return;
 254   2          }
 255   1      #if OS_ARG_CHK_EN > 0
                  if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
                      *err = OS_ERR_PEVENT_NULL;
                      return;
                  }
                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
                      *err = OS_ERR_EVENT_TYPE;
                      return;
                  }
              #endif
 265   1          OS_ENTER_CRITICAL();
 266   1          if (pevent->OSEventCnt > 0) {                     /* If sem. is positive, resource available ...   */
 267   2              pevent->OSEventCnt--;                         /* ... decrement semaphore only if positive.     */
 268   2              OS_EXIT_CRITICAL();
 269   2              *err = OS_NO_ERR;
 270   2              return;
 271   2          }
 272   1                                                            /* Otherwise, must wait until event occurs       */
 273   1          OSTCBCur->OSTCBStat |= OS_STAT_SEM;               /* Resource not available, pend on semaphore     */
 274   1          OSTCBCur->OSTCBDly   = timeout;                   /* Store pend timeout in TCB                     */
 275   1          OS_EventTaskWait(pevent);                         /* Suspend task until event or timeout occurs    */
 276   1          OS_EXIT_CRITICAL();
 277   1          OS_Sched();                                       /* Find next highest priority task ready         */
 278   1          OS_ENTER_CRITICAL();
 279   1          if (OSTCBCur->OSTCBStat & OS_STAT_SEM) {          /* Must have timed out if still waiting for event*/
 280   2              OS_EventTO(pevent);
 281   2              OS_EXIT_CRITICAL();
 282   2              *err = OS_TIMEOUT;                            /* Indicate that didn't get event within TO      */
 283   2              return;
 284   2          }
 285   1          OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
 286   1          OS_EXIT_CRITICAL();
 287   1          *err = OS_NO_ERR;
 288   1      }
 289          #endif 
 290          /*$PAGE*/
 291          /*
 292          *********************************************************************************************************
 293          *                                         POST TO A SEMAPHORE
 294          *
 295          * Description: This function signals a semaphore
 296          *
 297          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 298          *                            semaphore.
 299          *
 300          * Returns    : OS_NO_ERR           The call was successful and the semaphore was signaled.
 301          *              OS_SEM_OVF          If the semaphore count exceeded its limit.  In other words, you have
 302          *                                  signalled the semaphore more often than you waited on it with either
 303          *                                  OSSemAccept() or OSSemPend().
C51 COMPILER V7.20   OS_SEM                                                                06/14/2006 20:19:47 PAGE 6   

 304          *              OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore
 305          *              OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
 306          *********************************************************************************************************
 307          */
 308          #if OS_SEM_PEND_EN>0
 309          
 310          INT8U  OSSemPost (OS_EVENT *pevent)  reentrant
 311          {
 312   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr;                               
              #endif    
 315   1      
 316   1      
 317   1      #if OS_ARG_CHK_EN > 0
                  if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
                      return (OS_ERR_PEVENT_NULL);
                  }
                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
                      return (OS_ERR_EVENT_TYPE);
                  }
              #endif
 325   1          OS_ENTER_CRITICAL();
 326   1          if (pevent->OSEventGrp != 0x00) {                      /* See if any task waiting for semaphore    */
 327   2              OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM);   /* Ready highest prio task waiting on event */
 328   2              OS_EXIT_CRITICAL();
 329   2              OS_Sched();                                        /* Find highest priority task ready to run  */
 330   2              return (OS_NO_ERR);
 331   2          }
 332   1          if (pevent->OSEventCnt < 65535) {                 /* Make sure semaphore will not overflow         */
 333   2              pevent->OSEventCnt++;                         /* Increment semaphore count to register event   */
 334   2              OS_EXIT_CRITICAL();
 335   2              return (OS_NO_ERR);
 336   2          }
 337   1          OS_EXIT_CRITICAL();                               /* Semaphore value has reached its maximum       */
 338   1          return (OS_SEM_OVF);
 339   1      }
 340          #endif
 341          /*$PAGE*/
 342          /*
 343          *********************************************************************************************************
 344          *                                          QUERY A SEMAPHORE
 345          *
 346          * Description: This function obtains information about a semaphore
 347          *
 348          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 349          *                            semaphore
 350          *
 351          *              pdata         is a pointer to a structure that will contain information about the
 352          *                            semaphore.
 353          *
 354          * Returns    : OS_NO_ERR           The call was successful and the message was sent
 355          *              OS_ERR_EVENT_TYPE   If you are attempting to obtain data from a non semaphore.
 356          *              OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
 357          *********************************************************************************************************
 358          */
 359          
 360          #if OS_SEM_QUERY_EN > 0
              INT8U  OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *ppdata)  reentrant
              {
              #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr;
              #endif    
C51 COMPILER V7.20   OS_SEM                                                                06/14/2006 20:19:47 PAGE 7   

                  INT8U     *psrc;
                  INT8U     *pdest;
              
              
              #if OS_ARG_CHK_EN > 0
                  if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
                      return (OS_ERR_PEVENT_NULL);
                  }
                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
                      return (OS_ERR_EVENT_TYPE);
                  }
              #endif
                  OS_ENTER_CRITICAL();
                  ppdata->OSEventGrp = pevent->OSEventGrp;                /* Copy message mailbox wait list           */
                  psrc              = &pevent->OSEventTbl[0];
                  pdest             = &ppdata->OSEventTbl[0];
              #if OS_EVENT_TBL_SIZE > 0
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 1
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 2
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 3
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 4
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 5
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 6
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 7
                  *pdest            = *psrc;
              #endif
                  ppdata->OSCnt      = pevent->OSEventCnt;                /* Get semaphore count                      */
                  OS_EXIT_CRITICAL();
                  return (OS_NO_ERR);
              }
              #endif                                                     /* OS_SEM_QUERY_EN                          */
 418          #endif                                                     /* OS_SEM_EN                                */


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    712    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
C51 COMPILER V7.20   OS_SEM                                                                06/14/2006 20:19:47 PAGE 8   

   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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