/*
*********************************************************************************************************
* 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. */