Stateflow    

Calling C Functions

This section describes the C functions that you can call directly in Stateflow action language. See the following topics:

Calling C Library Functions

You can call the following small subset of the C Math Library functions:

abs
acos
asin
atan
atan2
ceil
cos
cosh
exp
fabs
floor
fmod
labs
ldexp
log
log10
pow
rand
sin
sinh
sqrt
tan
tanh

You can call the above C Math Library functions without doing anything special as long as you are careful to call them with the right data types.

If you call other C library functions not specified above, be sure to include the appropriate #include... directive in the Custom code included at the top of generated code field of the Target Options dialog. See the section Specifying Custom Code Options.

Calling min and max Functions

Although min and max are not C library functions, Stateflow enables them by emitting the following macros automatically at the top of generated code.

To allow compatibility with user graphical functions named min() or max(), Stateflow generates code for them with a mangled name of the following form: <prefix>_min. However, if you export min() or max() graphical functions to other Stateflow charts in the Stateflow machine, the name of these functions can no longer be emitted with mangled names in generated code and conflict occurs. To avoid this conflict, rename the min() and max() graphical functions.


  Fixed-Point "Bang-Bang Control" Example Calling User-Written C Code Functions