Configure AUTOSAR Initialize, Reset, or Terminate Runnables
AUTOSAR applications sometimes require complex logic to execute during system initialization, reset, and termination sequences. To model startup, reset, and shutdown processing in an AUTOSAR software component, use the Simulink® blocks Initialize Function and Terminate Function.
The Initialize Function and Terminate Function blocks can control execution of a component in response to initialize, reset, or terminate events. For more information, see Using Initialize, Reset, and Terminate Functions, Generate Code That Responds to Initialize, Reset, and Terminate Events (Simulink Coder), and AUTOSAR topic Startup, Reset, and Shutdown.
In an AUTOSAR model, you map each Simulink initialize,
reset, or terminate entry-point function to an AUTOSAR runnable. For
each runnable, configure the AUTOSAR event that activates the runnable.
In general, you can select any AUTOSAR
event type except
TimingEvent. The runnables work
with any AUTOSAR component modeling style.
(However, software-in-the-loop simulation of AUTOSAR initialize, reset,
or terminate runnables works only with exported function modeling.)
This example shows how to configure an AUTOSAR software component for simple startup and termination processing, using the Initialize Function and Terminate Function blocks.
Open a model that is configured for AUTOSAR code generation. This example uses a writable copy of the example model
Add an Initialize Function block to the model.
In the Initialize Function block, develop the logic that is required to execute during component initialization, using the techniques described in Using Initialize, Reset, and Terminate Functions.
Add a Terminate Function block to the model.
In the Terminate Function block, develop the logic that is required to execute during component termination, using the techniques described in Using Initialize, Reset, and Terminate Functions.
In this example, the Terminator block is a placeholder for saving the state value.
Add a terminate entry-point function to the model. In the Configuration Parameters dialog box, in the Code Generation > Interface pane, under Advanced parameters, select the option Terminate function required. Click Apply.
Open the Code Mappings editor. To update the Simulink to AUTOSAR mapping of the model, click the Update button . The mapping now reflects the addition of the Initialize Function and Terminate Function blocks and enabling of a terminate entry-point function.
Open the AUTOSAR Dictionary. Expand AtomicComponents, expand the component, and select the Runnables view.
The runnables list already contains an initialization runnable, created as part of the initial Simulink representation of the AUTOSAR software component. Use the Add button to add a terminate runnable to the component. Select each runnable and configure its name and properties.
The runnable symbol value shown in the runnables view becomes the runnable function name. The runnable Name value is used in the names of RTE access methods generated for the runnable.
For both the initialize and terminate runnables, configure an AUTOSAR event that activates the runnable.
This example defines a
ModeSwitchEventfor each runnable. Using a
ModeSwitchEventrequires creating a model declaration group, a mode-switch (M-S) interface, and a mode receiver port for the model. For more information, see Configure AUTOSAR Mode-Switch Communication.
In the runnables view, click the initialize runnable name to display and modify its associated event properties. Add and configure an event.
In the runnables view, click the terminate runnable name to display and modify its associated event properties. Add and configure an event.
Open the Code Mappings editor and select the Functions tab. Select the Simulink initialize and terminate functions and map them to the AUTOSAR initialize and terminate runnables that you configured.
Build the model and examine the generated code.
The exported ARXML code contains an AUTOSAR runnable for each initialize, reset, or terminate subsystem in the model, with the specified AUTOSAR runnable name and symbol. The runnable description includes each AUTOSAR data access point and server call point associated with the runnable.
The generated C code contains RTE access methods for parameters, states, function callers, and external I/O associated with the runnable.
- Using Initialize, Reset, and Terminate Functions
- Generate Code That Responds to Initialize, Reset, and Terminate Events (Embedded Coder)
- Create Test Harness to Generate Function Calls
- Configure AUTOSAR Mode-Switch Communication