| Real-Time Workshop® | ![]() |
| On this page… |
|---|
About Custom C Code Integration with Embedded MATLAB™ Coder |
You integrate custom C code with generated C code by specifying the locations of your external source files, header files, and libraries to Embedded MATLAB™ Coder. You can specify custom C files on the command line or with configuration objects.
When you compile an M-function with Embedded MATLAB Coder, you can specify custom C files — such as source, header, and library files — on the command line along with your M-file. For example, suppose you want to generate an embeddable C code executable that integrates a custom C function myCfcn with an M-function myMfcn. The custom source and header files for myCfcn reside in the directory C:\custom. You can use the following command to generate the code:
emlc -T rtw:exe C:\custom\myCfcn.c C:\custom\myCfcn.h myMfcn
You can specify custom C files by setting custom code properties on Real-Time Workshop® configuration objects (as described in Real-Time Workshop Dialog Box Overview in the Real-Time Workshop Reference documentation). Follow these steps:
Define a Real-Time Workshop configuration object, as described in Creating Configuration Objects.
For example:
cc = emlcoder.RTWConfig;
Set one or more of the custom code properties as needed:
| Custom Code Property | Description |
|---|---|
CustomInclude | Specifies a list of directories that contain custom header, source, object, or library files. |
CustomSource | Specifies additional custom C files to be compiled with the M-file. |
CustomLibrary | Specifies the names of object or library files to be linked with the generated code. |
CustomSourceCode | Specifies code to insert at the top of each generated C source file. |
CustomHeaderCode | Specifies custom code to insert at the top of each generated C header file. |
For example:
cc.CustomInclude = 'C:\custom\src C:\custom\lib'; cc.CustomSource = 'cfunction.c'; cc.CustomLibrary = 'chelper.obj clibrary.lib'; cc.CustomSourceCode = '#include "cgfunction.h"';
Compile the M-code with the Real-Time Workshop configuration object.
For example:
emlc -T rtw:lib -s cc myFunc
Call custom C functions as follows:
| From: | Call: |
|---|---|
| C source code | Custom C functions directly |
| M-code, compiled on the Embedded MATLAB path | Custom C functions using eml.ceval, as described in Calling C Functions from the Embedded MATLAB™ Subset in the Embedded MATLAB documentation. |
For example (from M-code):
...
y = 2.5;
y = eml.ceval('myFunc',y);
...For more information, see Configuring Your Environment for Code Generation.
![]() | Calling Generated C Functions | Blocks That Depend on Absolute Time | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |