Stateflow | ![]() ![]() |
User-Written Functions
You can specify calls to user-written functions in the action language. These guidelines apply to user-written function calls:
func(`string')
.double
in the case of MATLAB functions and of any type in the case of C user-written functions).Example: Function Call Transition Action
These are example formats of function calls using transition action notation.
If S1
is active, event e
occurs, c
is true, and the transition destination is determined, then a function call is made to function_name
with arg1
, arg2
, and arg3
. The transition action in the transition from S2
to S3
shows a function call nested within another function call.
Example: Function Call State Action
These are example formats of function calls using state action notation.
When the default transition into S1
occurs, S1
is marked active and then its entry
action, a function call to function_name1
with the specified arguments, is executed and completed. If S2
is active and an event occurs, the during
action, a function call to function_name3
with the specified arguments, executes and completes.
Passing Arguments by Reference
A Stateflow action can pass arguments to a user-written function by reference rather than by value. In particular, an action can pass a pointer to a value rather than the value itself. For example, an action could contain the following call.
f(&x);
where f
is a custom-code C-function that expects a pointer to x
as an argument.
If x
is the name of a data item defined in the SF data dictionary, the following rules apply.
If you need to pass an input item by reference, for example, an array, assign the item to a local data item and pass the local item by reference.
x
is a Simulink output data item having a data type other than double
, the chart property Use strong data typing with Simulink IO must be on (see Specifying Chart Properties).x
is boolean
, the coder option Use bitsets to store state-configuration must be turned off (see Use bitsets for storing state configuration).x
is an array with its first index property set to zero (see Array), then the function must be called as follows.f(&(x[0]));
This will pass a pointer to the first element of x
to the function.
x
is an array with its first index property set to a non-zero number (for example, 1), the function must be called in the following way.f(&(x[1]))
;
This will pass a pointer to the first element of x
to the function.
![]() | Assignment Operations | ml() Functions | ![]() |