Stateflow | ![]() ![]() |
Calling User-Written C Code Functions
To install your own C code functions for use in Stateflow action language, do the following:
file name
containing your C code functions in the Custom source files field.
See Specifying Custom Code Options.
To use your own C code functions in Stateflow action language, follow these guidelines:
func(`string')
.
double
in the case of MATLAB functions and of any type in the case of C user-written functions).
Function Call Transition Action Example
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.
Function Call State Action Example
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
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 Stateflow data dictionary, the following rules apply.
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 -- Use bitsets for storing state configuration variables. This can significantly reduce the amount of memory required to store the variables. However, it can increase the amount of memory required to store target code if the target processor does not include instructions for manipulating bitsets.).
x
is an array with its first index property set to 0 (see Array), then the function must be called as follows.
x
is an array with its first index property set to a nonzero number (for example, 1), the function must be called in the following way:
![]() | Calling C Functions | MATLAB Functions and Data | ![]() |