ADS中堆地址的设置方法

在使用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坠落尘埃

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值