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

📄 os_mem.lst

📁 UCOSii for c8051f020
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   OS_MEM                                                                03/05/2008 20:23:54 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE OS_MEM
OBJECT MODULE PLACED IN .\obj\OS_MEM.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE uCosii\OS_MEM.C LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\lst\OS_MEM.lst) OBJ
                    -ECT(.\obj\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-2001, 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 "source\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 
  49          {
  50   1      #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr;
              #endif    
  53   1          OS_MEM    *pmem;
  54   1          INT8U     *pblk;
C51 COMPILER V7.06   OS_MEM                                                                03/05/2008 20:23:54 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  = (void **)pblk;
  88   2              pblk   = pblk + blksize;
  89   2          }
  90   1          *plink = (void *)0;                               /* Last memory block points to NULL              */
  91   1          OS_ENTER_CRITICAL();
  92   1          pmem->OSMemAddr     = addr;                       /* Store start address of memory partition       */
  93   1          pmem->OSMemFreeList = addr;                       /* Initialize pointer to pool of free blocks     */
  94   1          pmem->OSMemNFree    = nblks;                      /* Store number of free blocks in MCB            */
  95   1          pmem->OSMemNBlks    = nblks;
  96   1          pmem->OSMemBlkSize  = blksize;                    /* Store block size of each memory blocks        */
  97   1          OS_EXIT_CRITICAL();
  98   1          *err   = OS_NO_ERR;
  99   1          return (pmem);
 100   1      }
 101          /*$PAGE*/
 102          /*
 103          *********************************************************************************************************
 104          *                                          GET A MEMORY BLOCK
 105          *
 106          * Description : Get a memory block from a partition
 107          *
 108          * Arguments   : pmem    is a pointer to the memory partition control block
 109          *
 110          *               err     is a pointer to a variable containing an error message which will be set by this
 111          *                       function to either:
 112          *
 113          *                       OS_NO_ERR           if the memory partition has been created correctly.
 114          *                       OS_MEM_NO_FREE_BLKS if there are no more free memory blocks to allocate to caller
 115          *                       OS_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
 116          *
C51 COMPILER V7.06   OS_MEM                                                                03/05/2008 20:23:54 PAGE 3   

 117          * Returns     : A pointer to a memory block if no error is detected
 118          *               A pointer to NULL if an error is detected
 119          *********************************************************************************************************
 120          */
 121          
 122          void  *OSMemGet (OS_MEM *pmem, INT8U *err) reentrant
 123          {
 124   1      #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr;
              #endif    
 127   1          void      *pblk;
 128   1      
 129   1      
 130   1      #if OS_ARG_CHK_EN > 0
 131   1          if (pmem == (OS_MEM *)0) {                        /* Must point to a valid memory partition         */
 132   2              *err = OS_MEM_INVALID_PMEM;
 133   2              return ((OS_MEM *)0);
 134   2          }
 135   1      #endif
 136   1          OS_ENTER_CRITICAL();
 137   1          if (pmem->OSMemNFree > 0) {                       /* See if there are any free memory blocks       */
 138   2              pblk                = pmem->OSMemFreeList;    /* Yes, point to next free memory block          */
 139   2              pmem->OSMemFreeList = *(void **)pblk;         /*      Adjust pointer to new free list          */
 140   2              pmem->OSMemNFree--;                           /*      One less memory block in this partition  */
 141   2              OS_EXIT_CRITICAL();
 142   2              *err = OS_NO_ERR;                             /*      No error                                 */
 143   2              return (pblk);                                /*      Return memory block to caller            */
 144   2          }
 145   1          OS_EXIT_CRITICAL();
 146   1          *err = OS_MEM_NO_FREE_BLKS;                       /* No,  Notify caller of empty memory partition  */
 147   1          return ((void *)0);                               /*      Return NULL pointer to caller            */
 148   1      }

⌨️ 快捷键说明

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