C功能的内存位置 [英] Memory placements of C-function

查看:252
本文介绍了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次.在此过程的后面,我希望可以对已创建的块(块1,块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 ...)

对于每个区块,我都有:

For each block, I have:

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

当前,我的问题是我无法创建一个包含所有函数内容的内存块.例如,如果我想在新块中使用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 */

,并在开发后的代码中:

and in the code once 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天全站免登陆