variables in LCF

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

variables in LCF

1,166 Views
Malban
Contributor I
Hello,
 
I'm sorry, but I do not often use all functionality of the linker. Is there someone who can explain me the advantage to declare some variables into the Linker File rather than into header file itself ?
Thanks in advance for your reply.
0 Kudos
2 Replies

440 Views
CompilerGuru
NXP Employee
NXP Employee
I think you refer to some labels, and not to actual variables. Variables are usually defined in source code and placed by the linker to a free location.
For special things like the stack or other objects which need to have a fixed location, one possible reasoning is to have all the address values together in the lcf file so the full memory layout is defined in a single file.

If I missed the question, please add some example-variable/labels you are referring too :smileywink:

Daniel
0 Kudos

440 Views
Malban
Contributor I
Hello,

Please find here after more details about my question:

MEMORY
{
    # [...]
  .xIntRam              (RW)  : ORIGIN = 0x0004,    LENGTH = 0x1FFC
    # [...]
}
 
SECTIONS
{
  .dataInIntXRam :
  {
    # [...]
    F_MeasureBufferLen = 256;          # The size of the buffer.
    . = ALIGN(F_MeasureBufferLen);
    F_MeasureBufferBegin = .;    # This buffer begins at the location of the address location current counter.
    . = . + F_MeasureeBufferLen;
    F_MeasureBufferEnd = .;
    # [...]
  } > .xIntRam
}
 
And here a sample of how they are used in the source code:
 
// [...]
extern _MeasureBufferLen;
extern _MeasureBufferBegin;
extern _MeasureBufferEnd;
static S16* MeasureBufferDataArea = NULL;
 
void init (void)
{
  MeasureBufferDataArea = (S16*)&_MeasureBufferBegin;
  // For the rest of the program, we use "MeasureBufferDataArea"
  // [...]
}

Do you know what is the interest to declare these variables into the linker file rather than into the header file ? Maybe the reason is to have a fixed address for this buffer, but in that case why ?
In addition, despite of the datasheet of the device and the Codewarrior help, I didn't well understand the use of the "ALIGN" keyword. What is the interest to align ? What is the consequence for the RAM and the address of the variable following an "align variable" ?


Thanks in advance for your help.
Best Regards.
Vincent.
0 Kudos