MULTIPLE CALL TO SEGMENT

WARNING L15: MULTIPLE CALL TO SEGMENT

1. What is Function Multiple Call Warning

insert image description here

The explanation given by Keil C on this issue is as follows:
Simply put, when a function is called by the Main function, an interruption occurs at this time, and the function is called again during the interruption, which will result in the previous parameter passing. Temporary variables are replaced. It needs to be said that because the stack space of C51 is very small, it uses an Overlay mechanism to store the variables in the function not in the stack, but in the memory space. The advantage of this approach is to save stack space. The disadvantage is that the function is not reentrant and cannot be called by multiple calls.
If it is a high-end MCU, there will be no such problem.
insert image description here

2, Function Multiple Call cause

There are two situations:
1. The same function (non-reentrant) is interrupted and called during normal execution, that is, the situation described above. At this time, the original variables and parameters may be destroyed.
2. Two different functions a and b, but due to the above Overlay mechanism, the address space of the internal variables and parameters is the same (the Overlay mechanism believes that the two functions will not be called at the same time, so the same address space is allocated There is no problem), when a is executing, b is interrupted and called, at this time, the parameters and variables of a will be modified by b.
insert image description here

3. Solution
1. Ignore warnings (not recommended)

If the function will not be executed in a reentrant manner and does not use any memory space (neither parameter passing nor local variables are used), this warning can be ignored.

2. Overlay command

Use the OVERLAY directive of the linker to remove the function from the overlay analysis (overlay analysis)
This allows the function to exclusively occupy a certain memory area without participating in the overlay. This function is not reentrant, but can be called by multiple threads without affecting the memory of other functions. However, it is still necessary to ensure that this function is not called by multiple threads at the same time.
insert image description here

3. How to deal with complex situations

When a function is interrupted and called by other threads during execution, the following methods can be used: 1) Interruption is prohibited when main calls the function, and the purpose of prohibiting interruption can be achieved by using the statement
when the function is called .
#pragma disableThe function must be removed from coverage analysis using the OVERLAY directive.
Interrupts are disabled when calling, rather than interrupts are disabled in the function, because the function parameter transfer may also use memory, and the OVERLAY instruction is required.

2) Copy the code of this function twice, one to the main program, and the other to the interrupt service routine.
The most simple and reliable implementation, the code size will increase.

3) Make the function reentrant
For example:

 void myfunc(void) reentrant 
 {  		
 ... 		
 }

This setting will generate a reentrant stack, which is used to store function values ​​and local variables. When using this method, the reentrant stack must be configured in the STARTUP.A51 file. This approach consumes more RAM and slows down the execution of reentrant functions.

4. The reference documents are as follows:

https://www.keil.com/support/docs/805.htm
Overly mechanism reference:
https://blog.csdn.net/shenjin_s/article/details/107212719

Guess you like

Origin blog.csdn.net/shenjin_s/article/details/108585518