OS_MEM.C文件解析

/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*                                            MEMORY MANAGEMENT
*
*                          (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
*                                           All Rights Reserved
*
* File : OS_MEM.C
* By   : Jean J. Labrosse
*********************************************************************************************************
*/

#ifndef  OS_MASTER_FILE
#include "includes.h"
#endif

#if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)//允许包含内在管理代码且内在分区数大于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.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
                                                           建立一个内存分区
描述:建立一个可由ucosII管理的大小固定的内存块
参数:addr :内存分区的起始地址
          nblks:从分割区中要建立内在块的数目
          blksize:内在分割区中每块内存的大小(用字节表示)
           err:是由下列函数决定的,包含错误信息的可变指针:
               OS_NO_ERR:如果内存块建立正确
               OS_MEM_INVALID_ADDR:你为分割区的内在空间指定了不可用地址
               OS_MEM_INVALID_PART:没有多余的区域了。
               OS_MEM_INVALID_BLKS:用户指定分割数目不合法(必须大于等于2)
               OS_MEM_INVALID_SIZE:用户指定了非法的内存块大小(必须大于指针的大小)
返回: != (OS_MEM *)0:分区已经建立
            == (OS_MEM *)0:因为非法参数或者没有空余块而没有建立分区

*********************************************************************************************************
*/

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;//typedef unsigned int OS_CPU_SR
#endif   
    OS_MEM    *pmem;//内存控制块数据结构
    INT8U     *pblk;
    void     **plink;//指向指针的指针
    INT32U     i;

#if OS_ARG_CHK_EN > 0//允许参数检验
    if (addr == (void *)0) {                          /* Must pass a valid address for the memory part. */

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值