Author and Extend Functions for Software Architectures
A function is an entry point that can be defined in a software
component. For inline components, you can author functions in the architecture level
using the Functions
Editor or by using the
addFunction function. You can then implement Simulink® behaviors for your authored functions.
For reference components, the functions are automatically created from the referenced behavior Simulink models. For information, see Simulate and Deploy Software Architectures.
In this topic, we explain the workflow to create functions in the architecture level and describe how to:
Author and visualize functions.
Implement behaviors for the functions.
Import and export functions.
Add custom properties to functions using stereotypes.
Author and Visualize Functions Using Functions Editor
You can apply stereotypes to functions in software architectures, edit sample times, and specify the function period using the Functions Editor.
The Functions Editor is visible only when you model software architectures. To open the Functions Editor, in the toolstrip, navigate to Modeling > Functions Editor. The model automatically updates, and the table displays the functions of components in your model.
This example shows a software architecture with two components and the Functions Editor with an empty table.
To author functions and sort them based on the order of execution:
Add a function. Select
Component1as the parent. Use the same steps to add a function for
Arrange the execution order of the functions by using the up and down arrows or clicking and dragging functions to sort them.
You can change the name of these functions by modifying the name in the table. Change the name of the first function to
You can edit sample times of these functions by specifying their period in the table. Change the period of the first function to
You can order functions automatically based on their data dependencies. This functionality is available for functions from behavior models. To enable automatic sorting, select the Order functions by dependency check box or enable
OrderFunctionsByDependencyon the architecture model.
The default value for the parameter is
The Functions Editor visualizes the functions created at the architecture level and the functions implemented in a Simulink model that is referenced by a component.
In this example, a third function is created in a Simulink behavior model, and the model is referenced by a third component,
Component3. The Software Component
column of the table shows the difference between functions created at the
architecture level and functions created in a Simulink behavior and referenced by a component.
Author Functions Programmatically
You can also author functions for your components using the
addFunction function to add a set of functions to the software
architecture with specified names
For more information, see
Implement Behaviors for Functions in the Architecture Level
You can create functions in the architecture level, and then implement behaviors for your functions.
To implement functions using the toolstrip:
Under the Modeling tab, select Component, and select Create Simulink Behavior.
Select the Type of the Simulink behavior as
Alternatively, you can right-click a component and select Create Simulink Behavior.
You can also use the
createSimulinkBehaviorfunction to implement functions programmatically. The function creates a new rate-based or export-function behavior and links the software component to the new model. You can create rate-based or export-function behaviors only for software architectures.
Apply Stereotypes to Functions of Software Architectures
You can extend software architecture functions by adding stereotypes containing custom properties. These steps describe how to add stereotypes to your functions and are very similar to the steps to add stereotypes to other architectural elements. For more information, see Apply Stereotypes to Extend Model Elements.
Define your function stereotypes using the Profile Editor.
Use the Functions Editor to select functions in your software component, apply stereotypes, view the stereotypes applied to your functions, and edit the stereotype property values.
In this example, you can specify the value for the
FunctionValueproperty of the stereotype called
FunctionStereotypeusing the Property Inspector.
Import and Export Functions of Software Architectures
You can import and export functions of your software architectures.
systemcomposer.exportModelfunction to output a
functionsfield that contains a table with information such as the name, execution order, parent component ID, period, and stereotypes of a function.
This example shows how to export a software architecture model
exportedSetoutput has the
functionsfield that contains the table with function information.
exportedSet = systemcomposer.exportModel('MySoftwareArchitecture') exportedSet = struct with fields: components: [4×5 table] ports: [6×4 table] connections: [3×5 table] portInterfaces: [0×9 table] requirementLinks: [0×15 table] domain: 'Software' functions: [3×4 table] >> exportedSet.functions ans = 3×4 table Name ExecutionOrder CompID Period _____________________ ______________ ______ ______ "myFunction" "1" "1" "1" "Component2_Function" "2" "2" "-1" "Component3_D1" "3" "3" "0.2"
systemcomposer.importModelfunction to import a model with functions where the
importStructargument can have a
functionsfield that contains function information.