How do I include custom code files specific for the TI C2000 target in Simulink?

24 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 29 Jan 2024
To integrate custom code files with the Simulink-generated code files, follow the steps below: 
1) Configure Custom Code settings for Simulation Target: 
In the Configuration Parameters > Simulation Target pane, specify the names of the custom code files under respective fields as below: 
  • Include headers — Specify the custom header file name enclosed in double quotes.  
For example, if you need to include ePWM_custom.h file you need to specify it as "#include "ePWM_custom.h"" as shown below: 
  • Source files - Enter a list of source files to compile and link into the target.  
For example, if you need to add an ePWM_custom.c file you need to specify it as "epwm_custom.c" as shown below: 
If you need to add multiple source files, you can separate the source files with a comma, space, or new line. 
2) Configure Custom Code Settings for Code Generation: 
Enable the parameter ‘Use the same custom code settings as Simulation Target’ under configuration parameters > Code Generation > Custom Code pane to use the same settings as configured for Simulation Target. 
3) Apply changes to custom source files (*.c): 
All the header file inclusions and function definitions specific to the TI C2000 target in the custom source file (.c) must be enclosed in a ‘#ifndef MATLAB_MEX_FILE’ statement as shown below: 
Adding the ‘#ifndef MATLAB_MEX_FILE’ statement to the custom code files does not compile the code for Simulation Target and includes the custom code only for code generation. If this conditional inclusion statement is not added, it may result in a build error.
4) Adding the custom code functions to the Simulink model:
The functions in the custom code files can be used in the Simulink model using ‘C Caller’ blocks by following the below steps:
a. Add a ‘C Caller’ block to the model.
b. Double-click on the block to open the block parameters and click on the drop-down next to the parameter ’Function name’ to select the required function as shown below:
Note: The C Caller block in your model imports all functions in your external source code and shows the function names next to the Function name on the block dialog. To select and use a function in your block, confirm that the function name appears in the Available Functions table. If you are missing one of the functions, reload the source code by clicking the 'Refresh' icon on the block dialog.
c. Update the sample time as required and also provide the values to the input ports of the 'C Caller’ block if the selected function has function arguments.
d. Click "Build, Deploy & Start" under Hardware > Deploy tab to build the model and deploy the executable (.out file) in the target board.

More Answers (0)

Tags

No tags entered yet.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!