Stateflow    

Calling User-Written C Code Functions

To install your own C code functions for use in Stateflow action language, do the following:

  1. From the Tools menu, select the Open (RTW or Simulation) Target dialog.
  2. When the Open Target dialog appears, select Target Options.
  3. Enter the following:

See Specifying Custom Code Options.

To use your own C code functions in Stateflow action language, follow these guidelines:

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.


  Calling C Functions MATLAB Functions and Data