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

📄 os_sem.lst

📁 在C8051F120内移植uCOS-II
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.08   OS_SEM                                                                04/13/2009 13:31:22 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE OS_SEM
OBJECT MODULE PLACED IN OS_SEM.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE OS_SEM.C BROWSE DEBUG OBJECTEXTEND

line 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          #define OS_SEM_GLOBALS
  19          #include "includes.h"
  20          //#endif
  21          
  22          #if OS_Sem_EN
  23          /*
  24          *********************************************************************************************************
  25          *                                           ACCEPT SEMAPHORE
  26          *
  27          * Description: This function checks the semaphore to see if a resource is available or, if an event
  28          *              occurred.  Unlike OSSemPend(), OSSemAccept() does not suspend the calling task if the
  29          *              resource is not available or the event did not occur.
  30          *
  31          * Arguments  : pevent     is a pointer to the event control block
  32          *
  33          * Returns    : >  0       if the resource is available or the event did not occur the semaphore is
  34          *                         decremented to obtain the resource.
  35          *              == 0       if the resource is not available or the event did not occur or,
  36          *                         you didn't pass a pointer to a semaphore
  37          *********************************************************************************************************
  38          */
  39          #if OS_Sem_Accept_EN
              INT16U OSSemAccept (OS_EVENT *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 V8.08   OS_SEM                                                                04/13/2009 13:31:22 PAGE 2   

              }
              #endif
  58          
  59          /*$PAGE*/
  60          /*
  61          *********************************************************************************************************
  62          *                                           CREATE A SEMAPHORE
  63          *
  64          * Description: This function creates a semaphore.
  65          *
  66          * Arguments  : cnt           is the initial value for the semaphore.  If the value is 0, no resource is
  67          *                            available (or no event has occurred).  You initialize the semaphore to a 
  68          *                            non-zero value to specify how many resources are available (e.g. if you have
  69          *                            10 resources, you would initialize the semaphore to 10).
  70          *
  71          * Returns    : != (void *)0  is a pointer to the event control clock (OS_EVENT) associated with the
  72          *                            created semaphore
  73          *              == (void *)0  if no event control blocks were available
  74          *********************************************************************************************************
  75          */
  76          #if OS_Sem_Create_EN
  77          OS_EVENT *OSSemCreate (INT16U cnt)reentrant
  78          {
  79   1          #if OS_CRITICAL_METHOD == 2
  80   1              unsigned DTYPE int_ss;
  81   1              #endif 
  82   1      
  83   1              OS_EVENT *pevent;
  84   1      
  85   1      
  86   1          OS_ENTER_CRITICAL();
  87   1          pevent = OSEventFreeList;                              /* Get next free event control block        */
  88   1          if (OSEventFreeList != (OS_EVENT *)0) 
  89   1          {                /* See if pool of free ECB pool was empty   */
  90   2              OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
  91   2          }
  92   1          OS_EXIT_CRITICAL();
  93   1          if (pevent != (OS_EVENT *)0) 
  94   1          {                         /* Get an event control block               */
  95   2              pevent->OSEventType = OS_EVENT_TYPE_SEM;
  96   2              pevent->OSEventCnt  = cnt;                         /* Set semaphore value                      */
  97   2              OSEventWaitListInit(pevent);
  98   2          }
  99   1          return (pevent);
 100   1      }
 101          #endif
 102          
 103          /*$PAGE*/
 104          /*
 105          *********************************************************************************************************
 106          *                                           PEND ON SEMAPHORE
 107          *
 108          * Description: This function waits for a semaphore.
 109          *
 110          * Arguments  : pevent        is a pointer to the event control block associated with the desired 
 111          *                            semaphore.
 112          *
 113          *              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
 114          *                            wait for the resource up to the amount of time specified by this argument.  
 115          *                            If you specify 0, however, your task will wait forever at the specified 
 116          *                            semaphore or, until the resource becomes available (or the event occurs).
 117          *
C51 COMPILER V8.08   OS_SEM                                                                04/13/2009 13:31:22 PAGE 3   

 118          *              err           is a pointer to where an error message will be deposited.  Possible error
 119          *                            messages are:
 120          *
 121          *                            OS_NO_ERR          The call was successful and your task owns the resource 
 122          *                                               or, the event you are waiting for occurred.
 123          *                            OS_TIMEOUT         The semaphore was not received within the specified 
 124          *                                               timeout.
 125          *                            OS_ERR_EVENT_TYPE  If you didn't pass a pointer to a semaphore.
 126          *                            OS_ERR_PEND_ISR    If you called this function from an ISR and the result
 127          *                                               would lead to a suspension.
 128          *
 129          * Returns    : none
 130          *********************************************************************************************************
 131          */
 132          #if OS_Sem_Pend_EN
 133          void OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)reentrant
 134          {
 135   1              #if OS_CRITICAL_METHOD == 2
 136   1              unsigned DTYPE int_ss;
 137   1              #endif 

⌨️ 快捷键说明

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