Hello,
we are working on a C51 project using code banking with 2 code banks(105k code)
This is the map file generated for my compiled project...
TYPE BASE LENGTH RELOCATION SEGMENT NAME ----------------------------------------------------- * * * * * * * D A T A M E M O R Y * * * * * * * REG 0000H 0008H ABSOLUTE "REG BANK 0" //for main code REG 0008H 0008H ABSOLUTE "REG BANK 1" //Timer 0 ISR REG 0010H 0008H ABSOLUTE "REG BANK 2" //Kernel functions REG 0018H 0008H ABSOLUTE "REG BANK 3" //Serial ISR DATA 0020H 0008H BIT_ADDR ?BA?MIC40 DATA 0028H 0001H BIT_ADDR ?BA?LINE40 BIT 0029H.0 0000H.7 UNIT ?BI?MIC40 0029H.7 0006H.1 *** GAP *** DATA 0030H 001FH UNIT _DATA_GROUP_ DATA 004FH 0012H UNIT ?DT?MIC40 IDATA 0061H 0001H UNIT ?ID?LINE40 IDATA 0062H 0001H UNIT ?STACK
When I cross-checked the allocation of local variables in this _DATA_GROUP_ overlay range for registers usage (R0 - R7 in reg bank 0), the compiler used each register memory location for 30-35 local variables storage as shown:
D:0001H SYMBOL lid D:0001H SYMBOL dt D:0001H SYMBOL m D:0001H SYMBOL tof D:0001H SYMBOL hold_lid D:0001H SYMBOL i D:0001H SYMBOL string D:0001H SYMBOL at D:0001H SYMBOL j D:0001H SYMBOL tid D:0001H SYMBOL ev D:0001H SYMBOL dtmf D:0001H SYMBOL rid D:0001H SYMBOL i D:0001H SYMBOL lid D:0001H SYMBOL sig D:0001H SYMBOL ocall
Is this reliable for me to trust the optimization done by the compiler? I am facing some data corruption and wrong operations in my project. What is the better way to decrease this overlay process at the cost of losing code as well as xdata space?
Consider the following code:
extern void runLineManager(unsigned char volatile); //external function prototype void runLineManager(unsigned char volatile i) { while(1) { // // piece of code } }
Q: Is it necessary to include 'volatile' in function prototype also?
Please advise..
volatile is an attribute for variables, since it is a request that the variable may never be cached.
The processor does not have a "normal" stack for storing auto variables, so the compiler/linker just have to analyse the call tree and figure out a mapping of auto variables to static locations.
Do you have any recursive functions, or functions that are called both from interrupt handlers and from the normal code? Have you specified that these functions are reentrant? If not, the you may get data corruption since static variables does not work with multiple concurrently active instances of the same function.
Is this reliable for me to trust the optimization done by the compiler?
Usually, yes. The compiler is merely placing local variables in registers that do not need to be assigned actual data memory (because their lifetime/scope is too limited).
Before suspecting the optimizer, there are other, much more likely suspects for data corruption.
Keywords should be in the prototype and the declaration. However, having a volatile function argument is very, very unusual and, ultimately, does not make sense.