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.
For information about initialize functions, see Schedule Component Initialization in Software Architectures.
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
Component1
as the parent. Use the same steps to add a function forComponent2
.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
myFunction
.You can edit sample times of these functions by specifying their period in the table. Change the period of the first function to
1
.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
OrderFunctionsByDependency
on the architecture model.set_param('MySoftwareArchitecture','OrderFunctionsByDependency','on')
The default value for the parameter is
off
.
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.
Use the addFunction
function to add a set of functions to the software
architecture component, architecture
with specified names
functionNames
.
addFunction(architecture,functionNames)
For more information, see addFunction
.
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
rate-based
orexport-function
.Alternatively, you can right-click a component and select Create Simulink Behavior.
You can also use the
createSimulinkBehavior
function 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.createSimulinkBehavior(component,"mySoftwareModel",BehaviorType="RateBased")
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
FunctionValue
property of the stereotype calledFunctionStereotype
using the Property Inspector.
Import and Export Functions of Software Architectures
You can import and export functions of your software architectures.
Use the
systemcomposer.exportModel
function to output afunctions
field 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
mySoftwareArchitecture
. TheexportedSet
output has thefunctions
field 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"
Use the
systemcomposer.importModel
function to import a model with functions where theimportStruct
argument can have afunctions
field that contains function information.
See Also
Tools
Objects
Functions
addFunction
|decreaseExecutionOrder
|increaseExecutionOrder
|systemcomposer.importModel
|systemcomposer.exportModel