Our TriCore tools feature the language extensions __share, __private0, __private1, __private2, and __clone to assign a code or data section to multiple cores or a single core only. You can achieve the same goal with the following pragmas:
#pragma code_core_association share | private{012} | clone
#pragma data_core_association share | private{012} | clone
This approach has an impact on the section name which the C compiler
generates to have the linker assign the section appropriately. The C
compiler adds the core association name to the section name. For example,
.bss.private1.module_name.variable_name
for a non-initialized variable which must be placed in core 1 local
memory.
When the C source code is not available for adaption and
recompilation (for example, because a third party library is used or an
object file is already certified and thus the C source may not be modified),
the core assignment using the above-mentioned C language extensions or the
pragmas is no longer possible.
To assign a section to a different core, you can use the linker LSL
language keyword
modify input.
Consider the example:
/*
* file_1.c
*
* functions and data sections are defined without any core assignment in the C source
* Core assignment is made using the LSL keyword modify input for function 'init_func'
*
*/
int my_var_1;
void init_func(void);
void main(void)
{
init_func();
while(1)
__nop();
}
void init_func(void)
{
my_var_1 = 0x1234;
}
When compiled with the default options and the addition of the -N0 option to prevent default near allocation of variables, the variable my_var_1 will be placed in the section .bss.file_1.my_var_1, while the code for init_func will be placed in the section .text.file_1.init_func.
To change the core association for the function init_func and the variable my_var_1 from any core (shared) to a single core only (here core0), you can use the following entries in the LSL file. The startup code handles copying the flash image of the function code to the core 0 local PSPR0 RAM:
// section_setup entry for the source location (here virtual linear memory, vtc)
section_setup mpe:vtc:linear
{
// Link time code core association private to assign the section to core0 memory
modify input ( space = mpe:tc0:linear )
{
select ".text.file_1.init_func";
select ".bss.file_1.my_var_1";
}
}
// section_layout entry for the placement of the section .text.file_1.init_func in TC0 local PSPR0 memory plus having the linker create
// a ROM copy section for the initialized code using the 'copy' keyword
section_layout :tc0:linear
{
group TC0_FUNCTIONS ( ordered, run_addr=mem:mpe:pspr0, copy )
{
select ".text.file_1.init_func";
}
// section_layout entry for the placement of the section .bss.file_1.my_var_1 in TC0 local DSPR0 memory
group TC0_DATA ( ordered, run_addr=mem:mpe:dspr0)
{
select ".bss.file_1.my_var_1";
}
}
The linker-generated map file shows the result.
The ROM copy of the
initialized section including the function code for
init_func in flash memory:
+ Space mpe:vtc:linear (MAU = 8bit)
+----------------------------------------------------------------------------------------------------------------------------+
| Chip | Group | Section | Size (MAU) | Space addr | Chip addr | Alignment |
|============================================================================================================================|
...
| mpe:pflash0 | | [.text.file_1.init_func] (367) | 0x0000000e | 0x800000ac | 0x000000ac | 0x00000002 |
...
The placement of the code section for the function init_func in the core local PSPR0 memory and the placement of the data section for the variable my_var_1 in the core local DSPR0 memory:
+ Space mpe:tc0:linear (MAU = 8bit)
+----------------------------------------------------------------------------------------------------------------------------+
| Chip | Group | Section | Size (MAU) | Space addr | Chip addr | Alignment |
|============================================================================================================================|
| mpe:dspr0 | TC0_DATA | .bss.file_1.my_var_1 (3) | 0x00000004 | 0x70000000 | 0x0 | 0x00000002 |
...
| mpe:pspr0 | TC0_FUNCTIONS | .text.file_1.init_func (169) | 0x0000000e | 0x70100000 | 0x0 | 0x00000002 |
...
The zip file code_core_association includes a buildable example using a command line invocation.