Simulate and Optionally Generate AUTOSAR Software Component Code (Requires Embedded Coder)
After you configure the AUTOSAR software component model for use in the Simulink® environment, simulate model my_autosar_swc
, which you
configured in Configure Elements of AUTOSAR Software Component for Simulink Modeling Environment.
If not already open, open your configured version of model
my_autosar_swc
.In the Simulink Editor, click the Simulate button .
If you have access to Simulink Coder™ and Embedded Coder® software, next, generate code for the AUTOSAR model.
If not already open, open your configured version of model
my_autosar_swc
.Initiate code generation by pressing Ctrl+B. The code generator produces C code and ARXML files. The generated code complies with the AUTOSAR standard so that you can schedule the code with the AUTOSAR run-time environment.
The code generator also produces and displays a code generation report.
In the code generation report, review the generated code. In your current MATLAB® folder, the
my_autosar_swc_autosar_rtw
folder contains the primary files listed in this table.Generated Code Files
Files Description my_autosar_swc.c
Contains entry points for the code that implements the model algorithm. This file includes rate scheduling code. my_autosar_swc.h
Declares model data structures and a public interface to the model entry points and data structures. my_autosar_swc_component.arxml
my_autosar_swc_datatype.arxml
my_autosar_swc_implementation.arxml
my_autosar_swc_interface.arxml
Contain elements and objects that represent AUTOSAR software components, ports, interfaces, data types, and packages. You integrate ARXML files into an AUTOSAR run-time environment. You can import ARXML files into the Simulink environment by using the AUTOSAR ARXML importer tool. By default, AUTOSAR Blockset code generation uses AUTOSAR platform types in the generated code and defines platform types in
Platform_Types.h
. If needed for support of legacy implementations, you can use the Data Type Replacement configuration parameter to specify that the code generator create the Simulink data type header filertwtypes.h
and use it in the generated code to describe AUTOSAR platform types in terms of coder type definitions. (since R2023b)Before R2023b: AUTOSAR Blockset code generation created and required the support file
rtwtypes.h
.Open and review the Code Interface Report. This information is captured in the ARXML files. The run-time environment generator uses the ARXML descriptions to interface the code into an AUTOSAR run-time environment.
Entry-point functions:
Initialization entry-point function —
void my_autosar_swc_Init(void)
. At startup, call this function once.Output and update entry-point function —
void my_autosar_swc_Step(void)
. Call this function periodically at the fastest rate in the model. For this model, call the function every second. To achieve real-time execution, attach this function to a timer.Output and update entry-point function —
void my_autosar_swc_Step1(void)
. Call this function periodically at the second fastest rate in the model. For this model, call the function every 2 seconds. To achieve real-time execution, attach this function to a timer.
The entry-point functions are also accessible in the Code Mappings editor, on the Functions tab. You call these generated functions from external code or from a version of a generated main function that you modify. If required, you can change the name of a function. For the base-rate step function of a rate-based model and for step functions for export function models, you can customize the function name and arguments.
Input ports:
Block In1_1s — Require port, interface: sender-receiver of type real-T of 1 dimension
Block In2_2s — Require port, interface: sender-receiver of type real-T of 1 dimension
Output ports:
Block Out1 — Provide port, interface: sender-receiver of type real-T of 1 dimension
Block Out2 — Provide port, interface: sender-receiver of type real-T of 1 dimension
Check whether the configuration changes that you made appear in the generated code by using the Code panel in the Code perspective. To open the Code panel, on the AUTOSAR tab, click View Code. The Code panel opens to the right of the model. In the search field, type
In1_1s_SS1
, the new name for AUTOSAR software component portIn1_1s
. Then, click the arrow button to advance to instances of the name in the ARXML filemy_autosar_swc_component.arxml
. Verify that the settings of communication attributes that you modified for the AUTOSAR software component port appear correctly.Use the Code perspective Code panel to explore other aspects of the generated code. For example, if you select file
my_autosar_swc.c
, and then click in the search field, a list of links to code elements, including the entry-point functions, appears. Use the links to quickly navigate to key areas of the generated C code.