cmemory-managementlinkerembeddedautosar

Linker and Memory map for shared memory in autosar embedded environment


I am trying to understand the Autosar memory map concept. I have two core micro controller which will send some datas to each other. So I have a shared memory for IPC communication. In my project, I can able to see some of the area they have reserved for the shared memory.

Linker file:

MEMORY {
 CORE_SHARED_RAM  : org = 0x200C1020, len = 0x00000FA0
}

 GROUP : {
    __CORE_SHARED_RAM_START = .;
    .CoreIpcRAM_noinit ALIGN(4): { *(.CoreIpcRAM_noinit) }
    __CORE_SHARED_RAM_END = .;
  } > CORE_SHARED_RAM

MemMap.h

#ifdef M1_START_SEC_CONST_UNSPECIFIED
   #undef M1_START_SEC_CONST_UNSPECIFIED
   #undef MEMMAP_ERROR 
   #pragma section DATA  ""  "CoreIpcRAM_noinit"
   #pragma section SDATA ""  "CoreIpcRAM_noinit"
#endif

#ifdef M2_START_SEC_IPC_MEMORY_VAR_NOINIT_32BIT
   #undef M2_START_SEC_IPC_MEMORY_VAR_NOINIT_32BIT
   #undef MEMMAP_ERROR 
   #pragma section DATA "" ".CoreIpcRAM_noinit"
   #pragma use_section DATA m2_Ipc_Memory
#endif

Since I am new to these linker and memory map concept, I would like to understand what is this code exactly do in the memory.

  1. What is MEMORY, GROUP tag in the linker file and what is the purpose of *(.CoreIpcRAM_noinit) variable ?

  2. In the Memap file, why CoreIpcRAM_noinit defined twice ?

    #pragma section DATA "" "CoreIpcRAM_noinit"

    #pragma section SDATA "" "CoreIpcRAM_noinit"

  3. In the memmap file, why CoreIpcRAM_noinit used in the both M1_START_SEC_CONST_UNSPECIFIED and M2_START_SEC_IPC_MEMORY_VAR_NOINIT_32BIT definitions ?

  4. What is the use of #pragma use_section DATA m2_Ipc_Memory command ?

If anybody knows, It would be helpful to understand the concepts.


Solution

  • I'm also new beginner about pragmas, linker and compiler sections concept. I learned on my own and tried to figure out how things worked on these sections. (refer to GNU LD Linker, and other documentations )

    What is MEMORY, GROUP tag in the linker file and what is the purpose of *(.CoreIpcRAM_noinit) variable ?

    MEMORY section defines the memory regions available on the microcontroller. Each memory region has a starting address (org) and length (len).

    GROUP sections or variables that should be placed in a specific memory region.

    .CoreIpcRAM_noinit ALIGN(4) section contains variables that should be placed in the CORE_SHARED_RAM and aligned to 4 bytes.

    In the Memap file, why CoreIpcRAM_noinit defined twice ?

    This is the way memory sections are handled for different data types or use cases in embedded systems.

    In the memmap file, why CoreIpcRAM_noinit used in the both M1_START_SEC_CONST_UNSPECIFIED and M2_START_SEC_IPC_MEMORY_VAR_NOINIT_32BIT definitions ?

    Both cores are likely sharing data via inter-processor communication (IPC) and need access to the same region of memory.

    What is the use of #pragma use_section DATA m2_Ipc_Memory command ?

    It tells the compiler to place all subsequent variable declarations in a section named m2_Ipc_Memory.