This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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, four 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 ''Model Configuration Parameters > Simulation Target''. 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. C Caller block supports C structure and enumeration types. Use command ''Simulink.importExternalCTypes'' to import these types into Simulink as matching Simulink.Bus object or Simulink.IntEnumType.

Set up custom C code in model configuration

Add '#include "my_func.h"' to ''Configuration Parameters > Simulation Target > Header File'' field.

Add 'include' to ''Configuration Parameters > Simulation Target > Include directories'' field.

Add 'src/my_func.c' to ''Configuration Parameters > Simulation Target > Source Files'' field.