Memory Mapping Allocation Keywords

Micael Coutinho,autosarbswmemmap

There are multiple keywords to map all variables on the ECU according to your application needs. Learn about them here

Within the bounds of an ECU, a resource-constrained hardware with hard real-time and special safety and security needs, it's necessary to use take advantage of the underlying memory layout, by allocating the data into special sections and reap the performance, security and safety benefits which will arise from it. Not to mention, an efficient and optimized Software always leads to a cheaper product, keeping your boss happy.

In order to take advantage of the memory layout of your ECU, Autosar contains the MemMap (Memory Mapping) module, which abstracts you from the preprocessor directives/pragmas and underlying linker-specific sections, which are arguably two of the hardest areas to master in microcontroller architecture. We already explained how the MemMap magic happens, but if you need a better refresher, you can read our article Memory Mapping (opens in a new tab). There, we explain the basics of this mechanism, along with its advantages.

Today, we'll build on this article, by discussing the most common keywords and their use. To start, let's take a look at the syntax, and after we'll look at all the options available for each section and their use. So, a section is usually defined as follows:

    <MODULE>_<START/STOP>_SEC_<TYPE>[_<INIT_POLICY>][_<ALIGNMENT>]  

Keep in mind, the aforementioned structure can have some slight variations. For example, in some types you can specify an ASIL (safety) level or the core scope. But, let's start small, as these are sporadic and you are most likely not to use them. At least, you will expect them if they show up on your source code. Now, if we divide the former example into smaller chunks:

TYPEDescription
VARMost common allocation type. Used for global or static variables
CONSTAlso very common. Used for constant allocation
CALIBUsed for calibrations, which are constants that you will want to calibrate in runtime. You can learn more about calibration in the article Calibration Overview (opens in a new tab)
CODEUsed to map code into the specific areas defined in your architecture
VAR_FASTVariables that need bitwise access or are frequently used in the source code
VAR_SLOWVaribles that are used rarely
INTERNAL_VARUsed for variabes that are accessed by a calibration tool
VAR_SAVED_ZONEUsed for RAM buffers of variables that are saved in non-volatile memory. If you are unfamiliar with non-volatile storage in Autosar, you can check our article NvM Overview (opens in a new tab)
CONST_SAVED_RECOVERY_ZONEUsed for ROM buffers of variables stored in non-volatile memory
CARTOUsed for cartography constants
CONFIG_DATAUsed for constants that should reside in a segment for module configuration
CALLOUT_CODEUsed to map code into the callouts for BSW modules
CODE_FASTUsed for code that is accessed very often
CODE_SLOWUsed for code that is rarely accessed
CODE_LIBUsed for code belonging to libraries of BSW modules or Software Components
INIT_POLICYDescription
NO_INITVariables are never initialized or cleared
CLEAREDVariables are initialized to zero after every reset
INITVariables initialized with its init value after every reset
POWER_ON_CLEAREDVariables initialized to zero only after power-on resets
POWER_ON_INITVariables initialized with its init value only after power-on resets
ALIGNMENTDescription
BOOLEANUsed for bits
8BITUsed when to align your section's contents to 8 bits
16BITUsed when to align your section's contents to 16 bits
32BITUsed when to align your section's contents to 32 bits
UNSPECIFIEDUsed when the provided aligments do not apply to your section

Now that you are a pro when it comes to memory mapping, I hope your applications start running smoother. And with the knowledge you just acquired, you can optimize your applications to perform safer, faster and ensure an efficient resource usage. Happy coding!

Author: Micael Coutinho (opens in a new tab)

References:

© AutosarToday —@LinkedIn