C 函数的内存位置 [英] Memory placements of C-function

查看:30
本文介绍了C 函数的内存位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个软件,稍后可以在我的微控制器上对某些功能(或块)进行编程,而无需再次重新刷新整个软件(刷新将由通信接口完成,例如 SPI).新块都将具有相同的 API(例如,5 个字节作为参数,1 个字节返回).

I would like a create a software where some functions (or block) can be programmed later on my micro controller without having to re-flash the entire software again (flash will be done by a communication interface e.g. SPI). The new blocks will all have the same API (e.g. 5 bytes as arguments, 1 byte returned).

内存架构的组织方式如下图所示:内存架构

Memory architecture will be organized as shown on this picture: memory architecture

总而言之,FBL 和 APPL 块将在 MCU 上仅编程 1 次.在此过程的后期,我希望有可能在创建的块(BLOCK 1、BLOCK 2 ...)中编程或更改某些功能

To summarize, the FBL and APPL blocks will be programmed only 1 time on the MCU. Later in the process, I want to have the possibility to program or change some functions in the created blocks (BLOCK 1, BLOCK 2 ...)

对于每个块,我有:

  • 2 个 flash 部分(一个用于 init 函数,一个用于task"函数).
  • 1 个 RAM 部分,我可以在其中放置静态变量.

目前,我的问题是我无法创建单个内存块,其中包含我的函数的所有内容.例如,如果我想在我的新块中使用 math.h 中的函数,链接器会将 math.h 函数放在我的 APPL 扇区中,而不是在专用于该块的已分配内存扇区中.但正如我所说,我的 APPL 部门不应该改变,因为它只会被编程 1 次.所以我想知道如何写一些独立"块...

Currently, my issue is that I cannot create a single memory block with all the content of my function in it. For example if I want to use a function from math.h in my new block, the linker will place the math.h functions in my APPL sector and not in the allocated memory sector dedicated for this block. But as I said, my APPL sector should not change because it will be programmed only 1 time. So I would like to know how I can write some "independents" blocks...

非常感谢!

推荐答案

您必须确保您需要的标准库的所有函数至少被调用一次,因此将包含在您的二进制基本代码中.

You must make sure all functions of the standard library you ever need are called at least once and so will be included in your binary base code.

对于你的变量"代码,你必须在块的开头有一种跳转表.你的基本代码调用变量代码中的函数,跳转表跳转到实际的函数入口点(或者你可以有包装函数),例如:

For your "variable" code, you must have a kind of jump table at the beginning of the block. Your base code calls the function in the variable code and the jump table jumps to the actual function enrty point (or you can have wrapper functions), for example:

char f1(int a, int b) { return _f1(a,b)}
char f2(int a, int b) { return _f2(a,b)}

char _f1(int a, int b) { return 0;} /* function not yet developed */
char _f2(int a, int b) { return 0;} /* function not yet developed */

在开发过的代码中:

char f1(int a, int b) { return _f1(a,b)}
char f2(int a, int b) { return _f2(a,b)}

char _f1(int a, int b) {
   /* lots of complex stuff */
   return result;
}
char _f2(int a, int b) {
   /* lots of complex stuff */
   return result;
}

这里,f1f2等函数都在可变代码的固定位置,因此可以从基础代码中调用.一旦代码块的最终版本被刷出,他们就会调用他们的最终版本.

Here, the functions f1, f2 etc will all be in a fixed place of the variable code and so can be called from the base code. Once the final version of the code block is flashed, they call their final version.

<小时>注意:我不确定如何处理来自标准库的变量代码调用函数,这些函数放置在您的基本代码区域中.变量块的链接器必须在变量代码中重复加载函数,或者必须知道它在基本代码区域中的绝对位置.您应该检查链接器/加载器文档.


Note: I am not sure how to handle the variable code calling functions from the standard library that are placed in your base code area. The linker for the variable block must either duplicate loading the function in the variable code or must know its absolute location in the base code area. You should check the linker/loader documentation for that.

这篇关于C 函数的内存位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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