单片机简单内存管理器
本代码基于无操作系统的STM32单片机开发,功能强大,可申请到地址空间连续的不同大小的内存空间,且用户接口简单,使用方便
转载请注明出处:http://blog.csdn.net/u011833609/article/details/46834203
memory.h
[cpp] view
plain copy
print?
-
#ifndef __MEMORY_H__
-
#define __MEMORY_H__
-
-
#include "stdio.h"
-
#include "string.h"
-
#include "includes.h"
-
-
typedef struct
-
{
-
void *addr;
-
uint32_t size;
-
uint16_t tb;
-
}DMEM;
-
-
-
DMEM *DynMemGet(uint32_t size);
-
-
void DynMemPut(DMEM *pDmem);
-
-
-
#endif //__MEMORY_H__
memory.c
[html] view
plain copy
print?
-
#include "memory.h"
-
-
#define DMEM_BLOCK_SIZE 256 //内存块大小为128字节
-
#define DMEM_BLOCK_NUM 20 //内存块个数为40个
-
#define DMEM_TOTAL_SIZE (DMEM_BLOCK_SIZE*DMEM_BLOCK_NUM) //内存总大小
-
-
typedef enum
-
{
-
DMEM_FREE = 0,
-
DMEM_USED = 1,
-
}DMEM_USED_ITEM;
-
-
typedef struct
-
{
-
DMEM_USED_ITEM used; //使用状态
-
uint16_t blk_s; //起始块序号
-
uint16_t blk_num; //块个数
-
}DMEM_APPLY;
-
-
typedef struct
-
{
-
DMEM_USED_ITEM tb_blk[DMEM_BLOCK_NUM];
-
DMEM tb_user[DMEM_BLOCK_NUM]; //用户申请内存信息
-
DMEM_APPLY tb_apply[DMEM_BLOCK_NUM]; //系统分配内存信息
-
uint16_t apply_num; //内存申请表占用数目
-
uint16_