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

📄 os_mem.lst

📁 ucosII在51单片机上的移植
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.02   OS_MEM                                                                02/06/2009 09:22:29 PAGE 1   


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

line level    source

   1          /*
   2          *********************************************************************************************************
   3          *                                                uC/OS-II
   4          *                                          The Real-Time Kernel
   5          *                                            MEMORY MANAGEMENT
   6          *
   7          *                        (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
   8          *                                           All Rights Reserved
   9          *
  10          *                                                  V2.00
  11          *
  12          * File : OS_MEM.C
  13          * By   : Jean J. Labrosse
  14          *********************************************************************************************************
  15          */
  16          
  17          #ifndef  OS_MASTER_FILE
  18          #include "includes.h"
  19          #endif
  20          
  21          #if OS_MEM_EN && OS_MAX_MEM_PART >= 2
  22          /*
  23          *********************************************************************************************************
  24          *                                         LOCAL GLOBAL VARIABLES
  25          *********************************************************************************************************
  26          */
  27          
  28          static  OS_MEM  DT_XDATA        *       DT_XDATA        OSMemFreeList;            /* Pointer to free list of memory partitions 
             -           */
  29          static  OS_MEM  DT_XDATA        OSMemTbl[OS_MAX_MEM_PART];/* Storage for memory partition manager                 
             -*/
  30          /*$PAGE*/
  31          /*
  32          *********************************************************************************************************
  33          *                                        CREATE A MEMORY PARTITION
  34          *
  35          * Description : Create a fixed-sized memory partition that will be managed by uC/OS-II.
  36          *
  37          * Arguments   : addr     is the starting address of the memory partition
  38          *
  39          *               nblks    is the number of memory blocks to create from the partition.
  40          *
  41          *               blksize  is the size (in bytes) of each block in the memory partition.
  42          *
  43          *               err      is a pointer to a variable containing an error message which will be set by
  44          *                        this function to either:
  45          *             
  46          *                        OS_NO_ERR            if the memory partition has been created correctly.
  47          *                        OS_MEM_INVALID_PART  no free partitions available
  48          *                        OS_MEM_INVALID_BLKS  user specified an invalid number of blocks (must be >= 2)
  49          *                        OS_MEM_INVALID_SIZE  user specified an invalid block size 
  50          *                                             (must be greater than the size of a pointer)
  51          * Returns    : != (OS_MEM *)0  is the partition was created 
  52          *              == (OS_MEM *)0  if the partition was not created because of invalid arguments or, no
C51 COMPILER V8.02   OS_MEM                                                                02/06/2009 09:22:29 PAGE 2   

  53          *                              free partition is available.
  54          *********************************************************************************************************
  55          */
  56          
  57          OS_MEM DT_XDATA *OSMemCreate (void DT_XDATA *addr, INT32U nblks, INT32U blksize, INT8U DT_XDATA *err) REEN
             -TRANT
  58          {
  59   1          OS_MEM DT_XDATA *pmem;
  60   1          INT8U  DT_XDATA *pblk;
  61   1          void    DT_XDATA *  DT_XDATA * plink;
  62   1          INT32U   i;
  63   1      
  64   1      
  65   1          if (nblks < 2) {                                  /* Must have at least 2 blocks per partition      */
  66   2              *err = OS_MEM_INVALID_BLKS;
  67   2              return ((OS_MEM DT_XDATA *)0);
  68   2          }
  69   1          if (blksize < sizeof(void DT_XDATA *)) {                   /* Must contain space for at least a pointe
             -r      */
  70   2              *err = OS_MEM_INVALID_SIZE;
  71   2              return ((OS_MEM DT_XDATA *)0);
  72   2          }
  73   1          OS_ENTER_CRITICAL();
  74   1          pmem = OSMemFreeList;                             /* Get next free memory partition                */
  75   1          if (OSMemFreeList != (OS_MEM DT_XDATA *)0) {               /* See if pool of free partitions was empty
             -      */
  76   2              OSMemFreeList = (OS_MEM DT_XDATA *)OSMemFreeList->OSMemFreeList;
  77   2          }
  78   1          OS_EXIT_CRITICAL();
  79   1          if (pmem == (OS_MEM DT_XDATA *)0) {                        /* See if we have a memory partition       
             -      */
  80   2              *err = OS_MEM_INVALID_PART;
  81   2              return ((OS_MEM DT_XDATA *)0);
  82   2          }
  83   1          plink = (void DT_XDATA * DT_XDATA *)addr;                            /* Create linked list of free mem
             -ory blocks      */
  84   1          pblk  = (INT8U DT_XDATA *)addr + blksize;
  85   1          for (i = 0; i < (nblks - 1); i++) {
  86   2              *plink = (void DT_XDATA *)pblk;
  87   2              plink  = (void DT_XDATA * DT_XDATA *)pblk;
  88   2              pblk   = pblk + blksize;
  89   2          }
  90   1          *plink = (void DT_XDATA *)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
C51 COMPILER V8.02   OS_MEM                                                                02/06/2009 09:22:29 PAGE 3   

 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          *
 116          * Returns     : A pointer to a memory block if no error is detected
 117          *               A pointer to NULL if an error is detected

⌨️ 快捷键说明

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