Main Content

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.

  1. Open a model that is configured for AUTOSAR code generation. This example uses a writable copy of the example model autosar_swc.

    Add an Initialize Function block to the model.

  2. 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.

  3. Add a Terminate Function block to the model.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. For both the initialize and terminate runnables, configure an AUTOSAR event that activates the runnable.

    This example defines a ModeSwitchEvent for each runnable. Using a ModeSwitchEvent requires 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.

  9. 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.

  10. 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.

See Also

| | | |

Related Examples

More About