ADS中堆地址的设置方法

来源:互联网 发布:2016最新淘宝刷单技巧 编辑:程序博客网 时间:2024/06/06 00:04

在使用ADS编译器进行ARM开发时,如果程序需要一块内存,在不上OS的情况下,一般调用malloc()函数。然而在调用之前必须保证你已经为程序分配了堆内存。有的汇编引导代码替你完成了这一步,比如本人以前用过的ZLG系列的工程模板,有的需要自己设定堆内存。

查看ADS的inline books有如下描述:

Using a heap implementation from bare machine C

To use a heap implementation in an application that does not define main() and does not
initialize the C library:

1. Call _init_alloc(base, top) to define the base and top of the memory you want
   to manage as a heap.
2. Define the function unsigned __rt_heap_extend(unsigned size, void ** block)
   to handle calls to extend the heap when it becomes full.

以上说明如果入口函数为标准的C库入口_main函数,则_main函数会帮助我们初始化堆的基地址,比如ZLG的模板。很多时候我们会自定义入口函数_Main,这种情况下就需要我们自己定义堆的基地址,注意堆的地址范围不要和复制的向量中断表的地址空间冲突。

从online books中看到要定义堆空间,要调用_init_alloc(base,top)函数。_rt_heap_extend()用来扩展堆空间。其他堆操作函数可以在ADS的online books中找到。注意在调用这些函数是要包含头文件#inciude <rt_heap.h>。

附本人在44b0中应用的一段代码:

#include <stdlib.h>
#include <rt_heap.h>

#include "44B.h"
#include "def.h"
#include "Option.h"
#include "44blib.h"


#define  SIZE    3072

U8 *pblock=NULL;

void Main(void)
{

      _init_alloc(0xc7fe000, 0xc7ff000);           //申请4K空间的对内存,0xc7ff000为中断向量表起始地址

       pblock=(U8*)malloc(SIZE);
       /*memory use*/
       free(pblock);
  
       pblock=NULL;
 }
本文转载自
博客ID坠落尘埃

原创粉丝点击