Main Content

Simulate and Deploy Software Architectures

This example shows how to build a multi-component software architecture model with a rate-based and export-function components, how to simulate your design at the architecture level, and how to generate code.

Open the Software Architecture Model

This software architecture model has two software components: Export_Function and Rate_Based.

open_system('RateBasedExportFunctionSoftwareArchitectureModel')

In the software architecture model, the Export_Function component is linked to a Simulink® export-function behavior model, export_model_software_architecture.

In this Simulink behavior, two functions are modeled using Function-Call Subsystem blocks. The inport blocks are connected to the function-call input ports and generate periodic function-call events with sample times 10ms and 100ms. To learn how to model this behavior, see Create an Export-Function Model.

If the inport blocks that are connected to the function-call input ports with sample time specified as -1, meaning the functions are aperiodic, use a Simulink test model with explicit scheduling blocks such as a Stateflow chart to simulate. For more information see Test Software Architecture.

The Rate_Based component is linked to rate_based_model_software_architecture as the Simulink behavior model. To learn how to create this rate-based model, see Create A Rate-Based Model.

Simulate the Model with Default Execution Order

Simulate the model. Observe that the Simulation Data Inspector displays the output from the Rate-Based component.

Visualize and Edit Component Functions Using Functions Editor

Use the Functions Editor to edit simulation execution order of the functions in your software architecture. You can also edit the sample time of the functions with inherited sample time (-1).

The Functions Editor is visible only when you model software architectures. To open the Functions Editor, in the toolstrip on the Modeling tab, select Functions Editor.

To edit the functions in your software architecture:

  1. Open the Functions Editor. When you open the Functions Editor, the model will automatically update, and the table will display the functions populated from your model.

  2. If there are changes in the software architecture model, the Update Model button becomes yellow to signal that an update is required to refresh your functions table.

  3. To arrange the execution order of the functions, use the up and down arrows or drag and drop functions to sort them.

  4. To edit sample times of the functions, specify their period in the table.

  5. To order functions based on their data dependencies, select the Order functions by dependency check box. To enable sorting of functions based on dependencies, you can set this parameter: set_param('RateBasedExportFunctionSoftwareArchitectureModel','OrderFunctionsByDependency','on'). The default value for the parameter is off.

Alternatively, you can use the systemcomposer.arch.Function object to get the functions programmatically.

Test Software Architecture

You can test a software architecture model and simulate different execution orders of functions by referencing it from a Model block in a Simulink test model with explicit scheduling blocks such as Stateflow® Chart (Stateflow).

In this example, a Model block that references a software architecture model has a function-call input port for each function in the architecture model.

To simulate the architecture model with a Stateflow chart periodic scheduler, connect the Stateflow chart function-call outputs to the Model block function-call inputs.

Deploy Software Architecture

You can generate code from the software architecture model for the functions of the export-function and rate-based components.

To generate code, from the Apps tab, select Embedded Coder. On the C Code tab, select Generate Code. The generated code contains an entry-point for each function of the component. For more information, see Generate Code for Export-Function Model.

For the export-function component, it generated the two functions that correspond to the function-call inport blocks inside the referenced export-function model.

Observe that, each rate-based component has separate entry point functions that correspond to each sample time in the referenced rate based model.

See Also

| | | |

Related Topics