sf_custom (Simulink model) | Open this Model |
Custom C-Code Functions and Structures
Stateflow allows you to incorporate and to call your custom-written C-Code functions. One main advantage of this is the ability to create and access structures directly from the Stateflow chart.
In this particular demo, a C-code function defined in my_function.c and a structure that is defined in my_header.h are included in the chart. MY_FUNCTION simply multiplies its input by 2. The structure in my_header.h is defined as follows:
typedef struct {
real_T a;
int8_T b[10];
}MyStruct;
In the model, we access the structure member using the dot notation: MyStruct.a and also with the use of a pointer: gMyStructPointerVar ->b[1].
Notice that 'b' is defined as an 8-bit integer value and not a Real (double) value. This the reason why 'output_c' alternates between values '1' and '0' instead of taking the precise values of the input sine wave.