IsolarAB exports arxml to Matlab/Simulink to generate the model and configure the memory partition

This article uses a simple example to illustrate how to import the SWC arxml designed by Isolar into simulink to generate a model, and specify that the code generated by simulink has memory partition information. The SWC created in this article is called ECAS_Sensor_SWC. Its main function is to process sensor signals and pass them to the subsequent SWC for use.

1. solarAB modifies the PlatformBase_Types.arxml file

Add the NativeDeclaration attribute as shown in the figure to the basic data type under IsolarAB AUTOSAR_Platform/BaseTypes (defined in PlatformBase_Types.arxml).


After the addition is completed, browse the PlatformBase_Types.arxml file under the Isolar project and you can see that there is an additional NativeDeclaration attribute under the data type definition, which is a necessary attribute for importing into Simulink.

2. Create necessary ImplementationDataTypes

Please use the prefix IDT_ when creating ImplementationDataTypes, and create a new DataTypes.arxml, and then put all DataTypes and ComputeMethods into this file.


Set the ImplementationDataTypes type to VALUE, and select the corresponding BaseType (there are 3 here, make sure the selected definition is located in Platform_BaseType.arxml).

3. Create necessary Interfaces

Please use the prefix SRI/CSI when creating an Interface, and create a new Intefaces.arxml, and then put all Interfaces into this file (at least those required by ASW).

4. Add necessary data elements to SR Interfaces

5. Model Component

Here we take ECAS_Sensor_SWC as an example. The description file (arxml) of each SWC remains independent and the name remains default.

Create a Port, where the RequestPort is prefixed with RP_, and the ProviderPort is prefixed with PP_.

Create two Runables as shown in the figure.

Create an Event corresponding to Runable.

Specify the DataAcess of Runable.

6. Import Arxml into Matlab and automatically create Simulink models

First create a new working folder and set the workspace to that folder.

Create a new subfolder Arxml under this folder.

Change PlatformBase_Types.arxml, Platform_Types.arxml, DataType under the Isolar project
s.arxml, Intefaces.arxml, and XX_SWC.arxml into this folder.
Among them, XX_SWC.arxml describes the SWC name, Port, Runable, Runable trigger event, the Inteface referenced by the Port, and the read and write DataElement and other information.
Intefaces.arxml is a specific description of Intefaces, that is, its data elements. At the same time, the variable type description of the data elements is located in the PlatformBase_Types.arxml file. Platform_Types.arxml here is not used for the time being.

Create a .m function in the project root folder to facilitate automatic model generation, and add code in it:

function CreateModefromArxml(modeName)
arxmlDir = './Arxml/';
platformTypeArxmlPath = strcat(arxmlDir,'Platform_Types.arxml');
platformBaseTypeArxmlPath = strcat(arxmlDir,'PlatformBase_Types.arxml');
interfaceArxmlPath = strcat(arxmlDir,'Interfaces.arxml');
dataTypeArxmlPath = strcat(arxmlDir,'DataTypes.arxml');
modeArxmlPath = strcat(arxmlDir,'SwComponentTypes_',modeName,'.arxml');
ar = arxml.importer({<!-- -->platformTypeArxmlPath, platformBaseTypeArxmlPath, interfaceArxmlPath, dataTypeArxmlPath, modeArxmlPath});
names=getComponentNames(ar);
createComponentAsModel(ar,names{<!-- -->1,1},'ModelPeriodicRunnablesAs','FunctionCallSubsystem');
end

Change the AUTOSAR_00047 in the header of each arxml to AUTOSAR_00042, because the highest recognized AUTOSAR version in 2019b is 4.2.

When using it, enter CreateModefromArxml(ECAS_Sensor_SWC’) directly in the dialog box;

The generated model.slx is shown in the figure. Various Autosar definitions and Mappings have been automatically generated.



If there are interface modifications, Compnent redefinition, data type redefinition, etc., you only need to replace the corresponding arxml file and update the model through the customized Function UpdateAutosarMode. The .m code is as follows:

function UpdateAutosarMode(modeName)
arxmlDir = './Arxml/';
platformTypeArxmlPath = strcat(arxmlDir,'Platform_Types.arxml');
platformBaseTypeArxmlPath = strcat(arxmlDir,'PlatformBase_Types.arxml');
interfaceArxmlPath = strcat(arxmlDir,'Interfaces.arxml');
dataTypeArxmlPath = strcat(arxmlDir,'DataTypes.arxml');
modeArxmlPath = strcat(arxmlDir,'SwComponentTypes_',modeName,'.arxml');
ar = arxml.importer({<!-- -->platformTypeArxmlPath, platformBaseTypeArxmlPath, interfaceArxmlPath, dataTypeArxmlPath, modeArxmlPath});
open_system(modeName);
updateModel(ar,modeName);
end

Save the DataTypes generated in the workspace to DataTypes.mat, so that when you reopen Matlab, you only need to click on this file to automatically load the data type definition (generated through arxml). Otherwise, you will lose definitions such as IDT_Temperature when you reopen Matlab next time. You can only use Regenerate using CreateModefromArxml.

7. Create a custom Storage class for the Simulink model

Command line input:
demoPath = \toolbox\simulink\simdemos\dataclasses’;
cd([matlabroot,demoPath]);

Copy the entire folder to your own project directory. Rename the folder in the project directory.

Modify the following sections in Signal.m and Parameter.m:


Replace with MyAutosarPackage
Command line input:
cscdesigner(MyAutosarPackage’); Open the following interface.

Delete the default Custom Storage Class and Memory Section. Add several Memory Sections as shown in the figure.

Among them, CONST_UNSPECIFIED is used to store all rodata segments not specified by SwAddrMethod, CODE is used to store all code segments not specified by SwAddrMethod, VAR_CLEARED_UNSPECIFIED is used to store all bss segments not specified by SwAddrMethod, and VAR_INIT_UNSPECIFIED is used to store all data not specified by SwAddrMethod. part.
The segments not specified by SwAddrMethod here refer to the segments that cannot be allocated by SwAddrMethod when generating code, such as Chart’s internal status record/delay related variables, SWC internal functions not included in Runbable, etc.
For example, let’s create a new Memory module in the model.

The variables associated with this module are generated in default storage and cannot be Memmap.

Expand Code Generation and click the Refresh package list option on the right side of Package.

Select the MyAutosarPackage we created.

Make the settings and generate the code again.

This variable has already allocated a memory partition, and the segment address can be specified through ECAS_Sensor_SWC_MemMap.h during actual compilation.

It also encapsulates a function used internally by SWC.

Before the above settings are made, the generated CODE does not specify a memory partition.

After configuration, the function generated again has been allocated in the corresponding CODE area, and the segment address during actual compilation can be specified through ECAS_Sensor_SWC_MemMap.h.

Here are some other settings for the model:




Unexplained settings can follow the default configuration when generating the model.

8. Specify SwAddrMethod for Simulink model

Runable Body, etc., if SwAddrMethod is not specified, will not be generated in the Default memory segment specified through Code Generation->Memory Section.

Open AUTOSAR Dictionary and create a new SwAddrMethods->CODE as shown in the figure.

Select a Runable in the Code Mapping at the bottom, and change the SwAddrMethod option in the Property Inspector on the right to CODE. Similarly, modify other Runables.

You can see that the newly generated Runable has been assigned to the corresponding CODE segment.

In the AUTOSAR Dictionary, create a new SwAddrMethods->CALIB_UNSPECIFIED as shown in the figure to specify the calibration variable.

Create a new Simulink.Parameter, Param_0 in Mode Workspace and use it in the model.

Select the Param in the Code Mapping at the bottom, change it to ConstantMemory, and set the Property on the right
Change the SwAddrMethod option in the Inspector to CALIB_UNSPECIFIED, check Const == TRUE, Volatile == TRUE, and similarly modify other calibration variables. The generated code is shown below.


In the AUTOSAR Dictionary, create a new SwAddrMethods->MEASURABLE_CLEARED_UNSPECIFIED as shown in the figure to specify the measurement variable.

Create a new Simulink.Signal, Moni_0 in Mode Workspace and use it in the model.


Select the Signals in the Code Mapping at the bottom, change it to StaticMemory, and change the SwAddrMethod option in the Property Inspector on the right to MEASURABLE_CLEARED_UNSPECIFIED, Volatile == TRUE, and modify other measurement variables similarly. The generated code is shown below.

9. Summary

When importing arxml to generate a Simulink model, you need to import the necessary DataType, Interface, and SWC information.
Specifying memory partitions for generated code is mainly divided into two categories. One type needs to be specified through SwAddrMethod (Runable, calibrated measurement variables), and the other type keeps the default Default settings, but needs to be designed.
MemoryPackage (Storage class) to change the default storage location, and ultimately require all variables in the generated code, the code is included in the macro:

#define %<AUTOSAR_COMPONENT>_START_SEC_%<MemorySectionName>
#include "%<AUTOSAR_COMPONENT>_MemMap.h"

#define %<AUTOSAR_COMPONENT>_STOP_SEC_%<MemorySectionName>
#include "%<AUTOSAR_COMPONENT>_MemMap.h"

middle.
In this way, the %_MemMap.h generated by the Cobara script can be used to specify the specific memory segment in the hex file and the download address during compilation and linking. The advantage of this is that it facilitates segmented updates (Bootloader) and OS level configuration. memory protection.