如何指定将存储功能的内存位置? [英] How to specify a memory location at which function will get stored?

查看:195
本文介绍了如何指定将存储功能的内存位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以让我知道我们可以在固定内存位置存储函数(C)的可能方式。



我正在使用IAR IDE为ARM皮质m3核心。

解决方案

如何将功能和数据放置在内存中,请参见IAR中的控制内存中的数据和功能放置一节手册IAR C / C ++开发指南。



我在特定地址放置特定功能的唯一方法是在内存中定义一个部分只有这个功能。
示例:

  void MyFunction(void)@MyFunctionsSection
{
..
}

在链接器文件中,您必须定义MyFunctionsSection部分。您可以在此定义此部分应放在何处。您的功能将被放置在那里。



此方法的缺点是您必须为此功能保留内存。所以你必须知道这个函数的大小,如果函数的大小增加并且比保留的内存大,就必须调整这个内存部分。另一个缺点是,您只能在本节中放置一个功能,以确保您的功能位于希望的地址。



但除此之外:放置在特定地址的功能一般是奇数。更好的是定义一个指向此函数的指针,并将指针放在一个修复地址上,就像在中断向量表中完成一样。如果您有更多的功能指针,则可以轻松扩展列表。


Can anyone please let me know what are the possible ways in which we can store a function(in C) at a fixed memory location.

I am using IAR IDE for ARM cortex m3 core.

解决方案

How functions and data can be placed in memory is described in section "Controlling data and function placement in memory" of the IAR manual "IAR C/C++ Development Guide".

The only way I see to place a specific function at a specific address is to define a section in memory where to place this and only this function. Example:

void MyFunction( void ) @ "MyFunctionsSection"
{
...
}

In the linker file you have to define the section "MyFunctionsSection". There you can define where this section should be placed. Your function will then be placed there.

The disadvantage of this method is that you have to reserve memory for this function. So you must know the size of the function and have to adapt this memory section if the size of the function increases and gets bigger than the reserved memory. Another drawback is that you can only place one function in this section to be sure that your function is placed at the wished address.

But besides this: The idea to place a function at a specific address is generally odd. Better would be to define a pointer to this function and place the pointer at a fix address as it is done in interrupt vector tables. If you have more function pointers the list can easily be expanded.

这篇关于如何指定将存储功能的内存位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆