1

i am new in AUTOSAR and embedded system my project defined variable along with memmap as part autosar standard as below

#define ABC_START_SEC_VAR_CLEARED_BOOLEAN
#include "abc_MemMap.h"
   boolean var1_b;   
   boolean var2_b;        
#define ABC_STOP_SEC_VAR_CLEARED_BOOLEAN
#include "abc_MemMap.h"

-> var1_b and var2_b will be arrange into specific memory so if someone did the mistake as below

boolean var1_b;   
boolean var2_b;

they forgot include ABC_START_SEC_VAR_CLEARED_BOOLEAN and STOP and when i do the build -> NO ERROR happen so what do you think about this point ?

where will var1 and var2 be arrange in Memory ? and do u have any way to detect this point because the build is pass and compiler cant recognize this ERROR

thank you

adragon
  • 11
  • 1
  • 6
  • If you don't use the macros or include the header file, all you have are two normal C variable definitions. There's no way for a standard compiler to detect that these shouldn't be normal global (I assume) variables. – Some programmer dude Dec 16 '19 at 12:01
  • Can you not use the [assert](https://www.tutorialspoint.com/c_standard_library/c_macro_assert.htm) macro? ( i.e. `assert (var1_b == FALSE)` ). If you are more concerned with _does the variable exist_ then [this may help](https://cboard.cprogramming.com/c-programming/59173-how-check-if-variable-exists.html). – ryyker Dec 16 '19 at 13:07
  • do u know how to know those variables are in normal or special memory ? – adragon Dec 17 '19 at 03:14

2 Answers2

1

You should initialize the variable properly, as per AUTOSAR. You can find the variable declaration prototype from the AUTOSAR Compiler Abstraction Specification document.

As per AUTOSAR, your variable declaration should be like below:

#define ABC_START_SEC_VAR_CLEARED_BOOLEAN
#include "abc_MemMap.h"
VAR(boolean, ABC_VAR_CLEARED) var1_b;
VAR(boolean, ABC_VAR_CLEARED) var2_b;
#define ABC_STOP_SEC_VAR_CLEARED_BOOLEAN
#include "abc_MemMap.h"

You have to add the ABC_VAR_CLEARED memory class into linker file and, once you've done your compilation process, var1_b and var2_b will be allocated under the ABC_VAR_CLEARED section in the map file.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
0

This is general problem for the Memory mapping in Autosar stack development.

Where will var1 and var2 be arrange in Memory ? :

It will be dummped into unmapped and uninitialize memory section usually non-bss or .data section. Based on your Microcontroller based memory alignment and Memory section size allocated in linker file, var1 and var2 will laydown on adjacent memory location. Best way to know where var1 and var2 located go to <project>.map generated after your compilation and you can find mapping section and addresses. To know more about memory type use this LINK

Do u have any way to detect this point ?:

I presume that current memory mapping is done in memmap.h in your project in which you are doing the Section mapping with tags like #define ABC_START_SEC_VAR_CLEARED_BOOLEAN Solution which I prefer is to have #ifdef condition under your memmap.h file. In this way at last of this memmap.h you will had #else condition you can introduce #error and its message and can create compilation error. You can see the syntax in this Pre-Processor error question.

There is one drawback in solution mentioned above i.e. This condition method do not indicate which mapping section has a problem but indicates one more sections are mis-mapped and then owner need to check manually where mis-mapping happened.

np2807
  • 1,050
  • 15
  • 30