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

📄 os_sem.lst

📁 uc/osII基于51单片机的时钟
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   OS_SEM                                                                03/04/2005 14:28:20 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE OS_SEM
OBJECT MODULE PLACED IN .\OS_SEM.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\uc_os_II\OS_SEM.C BROWSE DEBUG OBJECTEXTEND PRINT(.\OS_SEM.lst) OBJECT(.
                    -\OS_SEM.obj)

stmt level    source

   1          /*
   2          *********************************************************************************************************
   3          *                                                uC/OS-II
   4          *                                          The Real-Time Kernel
   5          *                                          SEMAPHORE MANAGEMENT
   6          *
   7          *                        (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
   8          *                                           All Rights Reserved
   9          *
  10          *                                                  V2.00
  11          *
  12          * File : OS_SEM.C
  13          * By   : Jean J. Labrosse
  14          *********************************************************************************************************
  15          */
  16          
  17          #ifndef  OS_MASTER_FILE
  18          #include "includes.h"
  19          #endif
  20          
  21          #if OS_SEM_EN
              /*
              *********************************************************************************************************
              *                                           ACCEPT SEMAPHORE
              *
              * Description: This function checks the semaphore to see if a resource is available or, if an event
              *              occurred.  Unlike OSSemPend(), OSSemAccept() does not suspend the calling task if the
              *              resource is not available or the event did not occur.
              *
              * Arguments  : pevent     is a pointer to the event control block
              *
              * Returns    : >  0       if the resource is available or the event did not occur the semaphore is
              *                         decremented to obtain the resource.
              *              == 0       if the resource is not available or the event did not occur or,
              *                         you didn't pass a pointer to a semaphore
              *********************************************************************************************************
              */
              
              INT16U OSSemAccept (OS_EVENT DT_XDATA *pevent) REENTRANT
              {
                  INT16U cnt;
              
              
                  OS_ENTER_CRITICAL();
                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
                      OS_EXIT_CRITICAL();
                      return (0);
                  }
                  cnt = pevent->OSEventCnt;
                  if (cnt > 0) {                                    /* See if resource is available                  */
                      pevent->OSEventCnt--;                         /* Yes, decrement semaphore and notify caller    */
                  }
                  OS_EXIT_CRITICAL();
                  return (cnt);                                     /* Return semaphore count                        */
C51 COMPILER V7.06   OS_SEM                                                                03/04/2005 14:28:20 PAGE 2   

              }
              
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                           CREATE A SEMAPHORE
              *
              * Description: This function creates a semaphore.
              *
              * Arguments  : cnt           is the initial value for the semaphore.  If the value is 0, no resource is
              *                            available (or no event has occurred).  You initialize the semaphore to a 
              *                            non-zero value to specify how many resources are available (e.g. if you have
              *                            10 resources, you would initialize the semaphore to 10).
              *
              * Returns    : != (void *)0  is a pointer to the event control clock (OS_EVENT) associated with the
              *                            created semaphore
              *              == (void *)0  if no event control blocks were available
              *********************************************************************************************************
              */
              
              OS_EVENT DT_XDATA *OSSemCreate (INT16U cnt) REENTRANT
              {
                  OS_EVENT DT_XDATA *pevent;
              
              
                  OS_ENTER_CRITICAL();
                  pevent = OSEventFreeList;                              /* Get next free event control block        */
                  if (OSEventFreeList != (OS_EVENT DT_XDATA *)0) {                /* See if pool of free ECB pool was em
             -pty   */
                      OSEventFreeList = (OS_EVENT DT_XDATA *)OSEventFreeList->OSEventPtr;
                  }
                  OS_EXIT_CRITICAL();
                  if (pevent != (OS_EVENT DT_XDATA *)0) {                         /* Get an event control block         
             -      */
                      pevent->OSEventType = OS_EVENT_TYPE_SEM;
                      pevent->OSEventCnt  = cnt;                         /* Set semaphore value                      */
                      OSEventWaitListInit(pevent);
                  }
                  return (pevent);
              }
              
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                           PEND ON SEMAPHORE
              *
              * Description: This function waits for a semaphore.
              *
              * Arguments  : pevent        is a pointer to the event control block associated with the desired 
              *                            semaphore.
              *
              *              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
              *                            wait for the resource up to the amount of time specified by this argument.  
              *                            If you specify 0, however, your task will wait forever at the specified 
              *                            semaphore or, until the resource becomes available (or the event occurs).
              *
              *              err           is a pointer to where an error message will be deposited.  Possible error
              *                            messages are:
              *
              *                            OS_NO_ERR          The call was successful and your task owns the resource 
              *                                               or, the event you are waiting for occurred.
              *                            OS_TIMEOUT         The semaphore was not received within the specified 
C51 COMPILER V7.06   OS_SEM                                                                03/04/2005 14:28:20 PAGE 3   

              *                                               timeout.
              *                            OS_ERR_EVENT_TYPE  If you didn't pass a pointer to a semaphore.
              *                            OS_ERR_PEND_ISR    If you called this function from an ISR and the result
              *                                               would lead to a suspension.
              *
              * Returns    : none

⌨️ 快捷键说明

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