keil如何设置overlay,避免局部变量覆盖.新手求助!!!
keil用变量覆盖的方法,分配局部变量.
我用SMALL RTOS51 写任务时,它会把我任务的局部变量分配到同一个内存中,程序就错了
在OVERLAY里边设置,可以分配在不同的空间,可是我不懂怎么设置!
有4个任务,LED0到LED3
为了防止keil使局部变量覆盖,设置overlay仿照例子,我填入的内容是main~LED1,main~LED2,main~LED3
程序是实时运行起来了,但是不知道上面填入的内容是什么意思.
英文有点差,下面是关于overlay的介绍
Removing Call References Between Segments
OVERLAY (sfname-caller ~ sfname-callee)
OVERLAY (sfname-caller ~ (sfname-callee, sfname-callee))
This form of the OVERLAY directive specifies that references from sfname-caller to sfname-callee are to be removed from overlay analysis.
Function references are automatically added to overlay analysis when you reference one function inside another (typically, these references are function calls). If you reference the address of a function (without calling the function), the linker considers this to be a reference between the two functions and it is included in overlay analysis. You may remove this reference manually using this form of the OVERLAY directive.
Referring to the following overlay map:
SEGMENT DATA_GROUP
+--> CALLED SEGMENT START LENGTH
----------------------------------------------
?PR?_FUNC?DMAIN ----- -----
+--> ?PR?_FUNC_A?DMAIN
+--> ?PR?_FUNC_B?DMAIN
You may remove the references from ?PR?_FUNC?DMAIN to ?PR?_FUNC_A?DMAIN and ?PR?_FUNC_B?DMAIN with the following OVERLAY command:
OVERLAY(?PR?_FUNC?DMAIN ~ (?PR?_FUNC_A?DMAIN,?PR?_FUNC_B?DMAIN))
[解决办法]
局部变量覆盖,指的是连接器利用函数/常数之间的静态调用拓扑结构,使得部分函数的局部变量可以使用相同的地址,而不会产生紊乱;
但他不能对函数指针做很好的处理,当使用了函数指针时,需要手动设置它们之间的调用拓扑结构;对于操作系统而言,每个任务的入口,最终在被调用的时候,都是以指针形势而调用的,所以,你必须手动设置每个任务的调用的拓扑结构,比较简单的处理,就是把每个任务函数,都设置为未被其他函数调用,它们的内部变量就不会相互覆盖了,比如三个任务,TSK_A(),TSK_B(),TSK_C();可用如下语句:
OVERLAY(* ~ (TSK_A,TSK_B,TSK_B))