If an address of a variable or a function is not known by the application, for example, because the variable or function is part of another application that is linked separately, you can use LSL symbols to specify the address of those symbols during link time. This approach prevents a recompilation of the C source code when the address of the symbols changes.
For example:
/* var_1 defined in another application located at address 0x80001000 */
extern const unsigned int var_1;
/* func_1 defined in another application located at address 0x80007000 */
void func_1(void);
unsigned int res;
int main(void)
{
res = var_1; /* here the const value located at address 0x80001000 will be read */
func_1(); /* here the function located at address 0x80007000 will be called */
return 0;
}
LSL file content to assign the values to the symbols during the link stage:
section_layout :vtc:linear
{
/* const variable var_1 is included in another project and located at address
0x80001000 */
"var_1" = 0x80001000;
/* function func_1 is included in another project and located at address
0x80007000 */
"func_1" = 0x80007000;
}
It is also possible to use conditional symbols, which are only defined when they are referenced in the application code.
To define a
conditional symbol within an LSL file, ':=' is used instead of '=' in the
assignment. For example:
"func_1" := 0x80007000;
This example defines func_1 only when it is referred to in an object file.
As the debug information is missing for the LSL-defined symbols, it is not possible
to select a variable within the debugger's Variables window. A
mitigation is to define a pointer dereference in the Expressions view
of the TASKING C/C++ debugger.
For example, to read the content of variable var_1, you can use the following expression:
*(unsigned int *)0x80001000
The zip file creating_symbols_in_LSL_example includes a buildable example using a command line invocation.