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

📄 os_mem.lst

📁 uCOS 嵌入式操作系统的改进版,增加了网络通讯.
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   OS_MEM                                                                07/18/2003 11:06:00 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE OS_MEM
OBJECT MODULE PLACED IN .\os_mem.obj
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE ..\keilc51\os_mem.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\os_mem.lst) OBJ
                    -ECT(.\os_mem.obj)

stmt level    source

   1          /*
   2          *********************************************************************************************************
   3          *                                                uC/OS-II
   4          *                                          The Real-Time Kernel
   5          *                                            MEMORY MANAGEMENT
   6          *
   7          *                          (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
   8          *                                           All Rights Reserved
   9          *
  10          * File : OS_MEM.C
  11          * By   : Jean J. Labrosse
  12          *********************************************************************************************************
  13          */
  14          
  15          #ifndef  OS_MASTER_FILE
  16          #include "includes.h"
  17          #endif
  18          
  19          #if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
  20          /*
  21          *********************************************************************************************************
  22          *                                        CREATE A MEMORY PARTITION
  23          *
  24          * Description : Create a fixed-sized memory partition that will be managed by uC/OS-II.
  25          *
  26          * Arguments   : addr     is the starting address of the memory partition
  27          *
  28          *               nblks    is the number of memory blocks to create from the partition.
  29          *
  30          *               blksize  is the size (in bytes) of each block in the memory partition.
  31          *
  32          *               err      is a pointer to a variable containing an error message which will be set by
  33          *                        this function to either:
  34          *
  35          *                        OS_NO_ERR            if the memory partition has been created correctly.
  36          *                        OS_MEM_INVALID_ADDR  you are specifying an invalid address for the memory 
  37          *                                             storage of the partition.
  38          *                        OS_MEM_INVALID_PART  no free partitions available
  39          *                        OS_MEM_INVALID_BLKS  user specified an invalid number of blocks (must be >= 2)
  40          *                        OS_MEM_INVALID_SIZE  user specified an invalid block size
  41          *                                             (must be greater than the size of a pointer)
  42          * Returns    : != (OS_MEM *)0  is the partition was created
  43          *              == (OS_MEM *)0  if the partition was not created because of invalid arguments or, no
  44          *                              free partition is available.
  45          *********************************************************************************************************
  46          */
  47          
  48          OS_MEM  *OSMemCreate (void *addr, INT32U nblks, INT32U blksize, INT8U *err) reentrant //using 0
  49          {
  50   1      #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
  51   1          OS_CPU_SR  cpu_sr;
  52   1      #endif    
  53   1          OS_MEM    *pmem;
  54   1          INT8U     *pblk;
C51 COMPILER V7.06   OS_MEM                                                                07/18/2003 11:06:00 PAGE 2   

  55   1          void     **plink;
  56   1          INT32U     i;
  57   1      
  58   1      
  59   1      #if OS_ARG_CHK_EN > 0
  60   1          if (addr == (void *)0) {                          /* Must pass a valid address for the memory part. */
  61   2              *err = OS_MEM_INVALID_ADDR;
  62   2              return ((OS_MEM *)0);
  63   2          }
  64   1          if (nblks < 2) {                                  /* Must have at least 2 blocks per partition      */
  65   2              *err = OS_MEM_INVALID_BLKS;
  66   2              return ((OS_MEM *)0);
  67   2          }
  68   1          if (blksize < sizeof(void *)) {                   /* Must contain space for at least a pointer      */
  69   2              *err = OS_MEM_INVALID_SIZE;
  70   2              return ((OS_MEM *)0);
  71   2          }
  72   1      #endif
  73   1          OS_ENTER_CRITICAL();
  74   1          pmem = OSMemFreeList;                             /* Get next free memory partition                */
  75   1          if (OSMemFreeList != (OS_MEM *)0) {               /* See if pool of free partitions was empty      */
  76   2              OSMemFreeList = (OS_MEM *)OSMemFreeList->OSMemFreeList;
  77   2          }
  78   1          OS_EXIT_CRITICAL();
  79   1          if (pmem == (OS_MEM *)0) {                        /* See if we have a memory partition             */
  80   2              *err = OS_MEM_INVALID_PART;
  81   2              return ((OS_MEM *)0);
  82   2          }
  83   1          plink = (void **)addr;                            /* Create linked list of free memory blocks      */
  84   1          pblk  = (INT8U *)addr + blksize;
  85   1          for (i = 0; i < (nblks - 1); i++) {
  86   2              *plink = (void *)pblk;
  87   2              plink  = *plink;
  88   2              pblk   = pblk + blksize;
  89   2          }
  90   1          *plink              = (void *)0;                  /* Last memory block points to NULL              */
  91   1          pmem->OSMemAddr     = addr;                       /* Store start address of memory partition       */
  92   1          pmem->OSMemFreeList = addr;                       /* Initialize pointer to pool of free blocks     */
  93   1          pmem->OSMemNFree    = nblks;                      /* Store number of free blocks in MCB            */
  94   1          pmem->OSMemNBlks    = nblks;
  95   1          pmem->OSMemBlkSize  = blksize;                    /* Store block size of each memory blocks        */
  96   1          *err                = OS_NO_ERR;
  97   1          return (pmem);
  98   1      }
  99          /*$PAGE*/
 100          /*
 101          *********************************************************************************************************
 102          *                                          GET A MEMORY BLOCK
 103          *
 104          * Description : Get a memory block from a partition
 105          *
 106          * Arguments   : pmem    is a pointer to the memory partition control block
 107          *
 108          *               err     is a pointer to a variable containing an error message which will be set by this
 109          *                       function to either:
 110          *
 111          *                       OS_NO_ERR           if the memory partition has been created correctly.
 112          *                       OS_MEM_NO_FREE_BLKS if there are no more free memory blocks to allocate to caller
 113          *                       OS_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
 114          *
 115          * Returns     : A pointer to a memory block if no error is detected
 116          *               A pointer to NULL if an error is detected
C51 COMPILER V7.06   OS_MEM                                                                07/18/2003 11:06:00 PAGE 3   

 117          *********************************************************************************************************
 118          */
 119          
 120          void  *OSMemGet (OS_MEM *pmem, INT8U *err) reentrant //using 0
 121          {
 122   1      #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
 123   1          OS_CPU_SR  cpu_sr;
 124   1      #endif    
 125   1          void      *pblk;
 126   1      
 127   1      
 128   1      #if OS_ARG_CHK_EN > 0
 129   1          if (pmem == (OS_MEM *)0) {                        /* Must point to a valid memory partition         */
 130   2              *err = OS_MEM_INVALID_PMEM;
 131   2              return ((OS_MEM *)0);
 132   2          }
 133   1      #endif
 134   1          OS_ENTER_CRITICAL();
 135   1          if (pmem->OSMemNFree > 0) {                       /* See if there are any free memory blocks       */
 136   2              pblk                = pmem->OSMemFreeList;    /* Yes, point to next free memory block          */
 137   2              pmem->OSMemFreeList = *(void **)pblk;         /*      Adjust pointer to new free list          */
 138   2              pmem->OSMemNFree--;                           /*      One less memory block in this partition  */
 139   2              OS_EXIT_CRITICAL();
 140   2              *err = OS_NO_ERR;                             /*      No error                                 */
 141   2              return (pblk);                                /*      Return memory block to caller            */
 142   2          }
 143   1          OS_EXIT_CRITICAL();
 144   1          *err = OS_MEM_NO_FREE_BLKS;                       /* No,  Notify caller of empty memory partition  */
 145   1          return ((void *)0);                               /*      Return NULL pointer to caller            */
 146   1      }
 147          /*$PAGE*/
 148          /*
 149          *********************************************************************************************************
 150          *                                   GET THE NAME OF A MEMORY PARTITION
 151          *
 152          * Description: This function is used to obtain the name assigned to a memory partition.
 153          *
 154          * Arguments  : pmem      is a pointer to the memory partition
 155          *
 156          *              pname     is a pointer to an ASCII string that will receive the name of the memory partitio
             -n.
 157          *
 158          *              err       is a pointer to an error code that can contain one of the following values:
 159          *
 160          *                        OS_NO_ERR                  if the name was copied to 'pname'
 161          *                        OS_MEM_INVALID_PMEM        if you passed a NULL pointer for 'pmem'
 162          *                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
 163          *
 164          * Returns    : The length of the string or 0 if 'pmem' is a NULL pointer.
 165          *********************************************************************************************************
 166          */
 167          
 168          #if OS_MEM_NAME_SIZE > 0
 169          INT8U  OSMemNameGet (OS_MEM *pmem, char *pname, INT8U *err) reentrant //using 0
 170          {
 171   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
 172   1          OS_CPU_SR  cpu_sr;
 173   1      #endif
 174   1          INT8U      len;
 175   1      
 176   1      
 177   1          OS_ENTER_CRITICAL();
C51 COMPILER V7.06   OS_MEM                                                                07/18/2003 11:06:00 PAGE 4   

 178   1      #if OS_ARG_CHK_EN > 0
 179   1          if (pmem == (OS_MEM *)0) {                   /* Is 'pmem' a NULL pointer?                          */
 180   2              OS_EXIT_CRITICAL();                      /* Yes                                                */
 181   2              *err = OS_MEM_INVALID_PMEM;
 182   2              return (0);
 183   2          }
 184   1          if (pname == (char *)0) {                    /* Is 'pname' a NULL pointer?                         */
 185   2              OS_EXIT_CRITICAL();                      /* Yes                                                */
 186   2              *err = OS_ERR_PNAME_NULL;
 187   2              return (0);
 188   2          }
 189   1      #endif
 190   1          (void)strcpy(pname, pmem->OSMemName);        /* Yes, copy name from OS_MEM                         */
 191   1          len  = strlen(pname);
 192   1          OS_EXIT_CRITICAL();
 193   1          *err = OS_NO_ERR;
 194   1          return (len);
 195   1      }
 196          #endif
 197          
 198          /*$PAGE*/

⌨️ 快捷键说明

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