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

📄 os_mem.lst

📁 AT89C55WD上移植的ucos-ii, 非常有用, 串口观看输出与调试。
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.20   OS_MEM                                                                04/25/2005 23:03:46 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE OS_MEM
OBJECT MODULE PLACED IN OS_MEM.obj
COMPILER INVOKED BY: D:\tools\Keil\C51\BIN\C51.EXE SOURCE\OS_MEM.C LARGE BROWSE INCDIR(D:\MY\empolder\uCOS-II\MCS-51\AT8
                    -9C55WD\Keil 7_5\) 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-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)
              /*
              *********************************************************************************************************
              *                                        CREATE A MEMORY PARTITION
              *
              * Description : Create a fixed-sized memory partition that will be managed by uC/OS-II.
              *
              * Arguments   : addr     is the starting address of the memory partition
              *
              *               nblks    is the number of memory blocks to create from the partition.
              *
              *               blksize  is the size (in bytes) of each block in the memory partition.
              *
              *               err      is a pointer to a variable containing an error message which will be set by
              *                        this function to either:
              *
              *                        OS_NO_ERR            if the memory partition has been created correctly.
              *                        OS_MEM_INVALID_ADDR  you are specifying an invalid address for the memory 
              *                                             storage of the partition.
              *                        OS_MEM_INVALID_PART  no free partitions available
              *                        OS_MEM_INVALID_BLKS  user specified an invalid number of blocks (must be >= 2)
              *                        OS_MEM_INVALID_SIZE  user specified an invalid block size
              *                                             (must be greater than the size of a pointer)
              * Returns    : != (OS_MEM *)0  is the partition was created
              *              == (OS_MEM *)0  if the partition was not created because of invalid arguments or, no
              *                              free partition is available.
              *********************************************************************************************************
              */
              
              OS_MEM  *OSMemCreate (void *addr, INT32U nblks, INT32U blksize, INT8U *err)
              {
              #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr;
              #endif    
                  OS_MEM    *pmem;
                  INT8U     *pblk;
C51 COMPILER V7.20   OS_MEM                                                                04/25/2005 23:03:46 PAGE 2   

                  void     **plink;
                  INT32U     i;
              
              
              #if OS_ARG_CHK_EN > 0
                  if (addr == (void *)0) {                          /* Must pass a valid address for the memory part. */
                      *err = OS_MEM_INVALID_ADDR;
                      return ((OS_MEM *)0);
                  }
                  if (nblks < 2) {                                  /* Must have at least 2 blocks per partition      */
                      *err = OS_MEM_INVALID_BLKS;
                      return ((OS_MEM *)0);
                  }
                  if (blksize < sizeof(void *)) {                   /* Must contain space for at least a pointer      */
                      *err = OS_MEM_INVALID_SIZE;
                      return ((OS_MEM *)0);
                  }
              #endif
                  OS_ENTER_CRITICAL();
                  pmem = OSMemFreeList;                             /* Get next free memory partition                */
                  if (OSMemFreeList != (OS_MEM *)0) {               /* See if pool of free partitions was empty      */
                      OSMemFreeList = (OS_MEM *)OSMemFreeList->OSMemFreeList;
                  }
                  OS_EXIT_CRITICAL();
                  if (pmem == (OS_MEM *)0) {                        /* See if we have a memory partition             */
                      *err = OS_MEM_INVALID_PART;
                      return ((OS_MEM *)0);
                  }
                  plink = (void **)addr;                            /* Create linked list of free memory blocks      */
                  pblk  = (INT8U *)addr + blksize;
                  for (i = 0; i < (nblks - 1); i++) {
                      *plink = (void *)pblk;
                      plink  = (void **)pblk;
                      pblk   = pblk + blksize;
                  }
                  *plink              = (void *)0;                  /* Last memory block points to NULL              */
                  pmem->OSMemAddr     = addr;                       /* Store start address of memory partition       */
                  pmem->OSMemFreeList = addr;                       /* Initialize pointer to pool of free blocks     */
                  pmem->OSMemNFree    = nblks;                      /* Store number of free blocks in MCB            */
                  pmem->OSMemNBlks    = nblks;
                  pmem->OSMemBlkSize  = blksize;                    /* Store block size of each memory blocks        */
                  *err                = OS_NO_ERR;
                  return (pmem);
              }
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                          GET A MEMORY BLOCK
              *
              * Description : Get a memory block from a partition
              *
              * Arguments   : pmem    is a pointer to the memory partition control block
              *
              *               err     is a pointer to a variable containing an error message which will be set by this
              *                       function to either:
              *
              *                       OS_NO_ERR           if the memory partition has been created correctly.
              *                       OS_MEM_NO_FREE_BLKS if there are no more free memory blocks to allocate to caller
              *                       OS_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
              *
              * Returns     : A pointer to a memory block if no error is detected
              *               A pointer to NULL if an error is detected
C51 COMPILER V7.20   OS_MEM                                                                04/25/2005 23:03:46 PAGE 3   

              *********************************************************************************************************
              */
              
              void  *OSMemGet (OS_MEM *pmem, INT8U *err)
              {
              #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr;
              #endif    
                  void      *pblk;
              
              
              #if OS_ARG_CHK_EN > 0
                  if (pmem == (OS_MEM *)0) {                        /* Must point to a valid memory partition         */
                      *err = OS_MEM_INVALID_PMEM;
                      return ((OS_MEM *)0);
                  }
              #endif
                  OS_ENTER_CRITICAL();
                  if (pmem->OSMemNFree > 0) {                       /* See if there are any free memory blocks       */
                      pblk                = pmem->OSMemFreeList;    /* Yes, point to next free memory block          */
                      pmem->OSMemFreeList = *(void **)pblk;         /*      Adjust pointer to new free list          */
                      pmem->OSMemNFree--;                           /*      One less memory block in this partition  */
                      OS_EXIT_CRITICAL();
                      *err = OS_NO_ERR;                             /*      No error                                 */
                      return (pblk);                                /*      Return memory block to caller            */
                  }
                  OS_EXIT_CRITICAL();
                  *err = OS_MEM_NO_FREE_BLKS;                       /* No,  Notify caller of empty memory partition  */
                  return ((void *)0);                               /*      Return NULL pointer to caller            */
              }
              /*$PAGE*/

⌨️ 快捷键说明

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