Hauptinhalt

Simulate and Deploy Software Architectures

This example shows how to schedule and simulate the execution order of component functions and generate code.

In this example, a simple software architecture is modeled in System Composer™ containing two components. The export-function component is linked to a Simulink® behavior, export_model_software_architecture. The rate-based component is linked to a Simulink behavior, rate_based_software_architecture.

model = systemcomposer.openModel('RateBasedExportFunctionSoftwareArchitectureModel');

A software architecture model with two components. Each component is linked to a Simulink model indicated by a Simulink icon in the top right corner.

The linked behavior model of the export-function component contains two functions. Each function uses a Function-Call Subsystem block connected to an Inport block that generates periodic function-call events, with sample times of 10ms and 100ms. For details on creating export-function models, see Create Export-Function Model.

A Simulink export-function model with two Function-Call Subsystem blocks. Each subsystem connected to an Inport block.

If Inport blocks connected to the function-call input ports use a sample time of -1, the functions are aperiodic. To schedule and simulate aperiodic functions, create a test model that includes explicit scheduling blocks such as a Stateflow® Chart. For more information, see Test Software Architecture.

The linked behavior model of the rate-based component contains two subsystems, with sample times of 200ms and 400ms. For details on creating rate-based models, see Create Rate-Based Model.

A Simulink rate-based model with two subsystems. Each subsystem connected to an input and output.

Simulate Model with Default Execution Order

To simulate the model, use the sim function.

sim("RateBasedExportFunctionSoftwareArchitectureModel.slx");

To view the output signals of the rate-based component, open the Simulation Data Inspector. Go to the Simulation tab, in the Review Results section, select Data Inspector.

A line plot showing two signals from a rate-based behavior model over a time span of 0 to 10 seconds. The blue stepped line labeled “Rate_Based:1” increases gradually from 0 to 10, while the purple horizontal line labeled “Rate_Based:2” remains constant at a value of 4.

Schedule Component Functions Using Functions Editor

You can use the Functions Editor to change the execution order of component functions and edit the period of functions with an inherited sample time (-1).

To open the Functions Editor, in the toolstrip, on the Modeling tab, in the Design section, click Functions Editor.

Functions Editor showing execution order and scheduling details for four functions. The first two functions, Export_Function_function_call_10ms and Export_Function_function_call_100ms, belong to the Export_Function component with periods of 0.01 and 0.1 seconds. The next two functions, Rate_Based_D1 and Rate_Based_D2, belong to the Rate_Based component with periods of 0.2 and 0.4 seconds.

On the Functions tab of the Functions Editor, you can view the component functions and schedule the order of execution.

  1. When you open the Functions Editor, the model automatically updates, and the table displays the functions of components in your model.

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

  3. To change the order of component functions, use the up and down arrows or drag functions to sort them.

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

You can order functions automatically based on their data dependencies. To enable automatic sorting, select the Order functions by dependency check box. For more information, see Author Functions and Create Function Groups Using Functions Editor.

Alternatively, you can use the increaseExecutionOrder and decreaseExecutionOrder functions of the systemcomposer.arch.Function object to programmatically change function execution order. To order functions by dependency, you can enable the OrderFunctionsByDependency parameter of the architecture model using this command:

set_param('RateBasedExportFunctionSoftwareArchitectureModel','OrderFunctionsByDependency','on');

The OrderFunctionsByDependency parameter is disabled by default.

Test Software Architecture

You can test a software architecture model by referencing the architecture in a test model. The Simulink model contains a Stateflow Chart (Stateflow) block to model a more complex scheduling of functions. A Stateflow license is required for this functionality.

In this example, the Model block references the software architecture, RateBasedExportFunctionSoftwareArchitectureModel, and has a function-call input port for each function in the software architecture. To simulate with a Stateflow periodic scheduler, connect the function-call outputs of the chart to the function-call inputs of the Model block.

Simulink model showing a Sequence block on the left connected to a software architecture model named RateBasedExportFunctionSoftwareArchitectureModel. The sequence block sends signals labeled f1(), f2(), f3(), and f4() to four function-call input ports: Export_Function_function_call_100ms, Export_Function_function_call_10ms, Rate_Based_D1, and Rate_Based_D2. The model outputs through two buses, OutBus and OutBus1, to a sink block on the right.

Generate Code for Software Architecture

You can generate code from the software architecture model for the functions of the export-function and rate-based components. Code generation requires an Embedded Coder® license.

To generate code from the architecture model, on the Apps tab of the toolstrip, select Embedded Coder. Then, on the C Code tab of the toolstrip, select Generate Code.

The generated code contains an entry-point function for each function of the components in the software architecture. For more information on code generation for export-function models, see Generate Code for Export-Function Model.

For the export-function component, the generated code has two functions, one to correspond to each periodic function-call event of the linked behavior model.

Generated C code showing two export-function entry-point functions: Export_Function_function_call_10ms(void) and Export_Function_function_call_100ms(void).

For the rate-based component, the generated code has separate entry-point functions for each sample time in the linked behavior model.

Generated C code showing two rate-based entry-point functions: Rate_Based_D1(void) and Rate_Based_D2(void).

See Also

| | | |

Topics