Call C Functions Using C Caller Block
This example shows how to use the C Caller block to call your handwritten C functions.
In this example, five custom C functions are defined in my_func.h
and implemented in my_func.c
.
The header file and the source file are specified in the Simulation Target pane of the Model Configuration Parameters. Then C functions can be called via C Caller blocks. For example, the block add
adds a signal and a constant together and the block timesK
multiplies the signal by a parameter K
. The C Caller block supports C structure and enumeration types. Use command Simulink.importExternalCTypes
to import these types into Simulink as matching Simulink.Bus
objects or Simulink.IntEnumType
classes.
Set up custom C code in model configuration
Add '#include "my_func.h"' to ''Configuration Parameters > Simulation Target > Include headers'' field.
Add 'include' to ''Configuration Parameters > Simulation Target > Include directories'' field.
Add 'src/my_func.c' to ''Configuration Parameters > Simulation Target > Source files'' field.