S-Function builder
Afficher commentaires plus anciens
Hi to all,
Im using Matlab in linux system. Im building a simulink model and have a S-Function Builder on it that needs the texas instruments fiel "DSP28x_Project.h". In the library pane I have to include a file, reading the matlab help about S-Function Builder, I try to add the SRC_PATH to this file that in my case is in this route /home/gaston/ti/c2000/C2000Ware_3_01_00_00/device_support/f2802x, then bellow this line I put the DSP28x_Project.h (Not seen in the picture bellow) and tried to build the model. The build throws error "can't find directory or file".
How is the correct way to include the path to this file?
Thanks for your help

Réponses (1)
Nivedita
il y a environ 7 heures
Hi Gaston,
The errors that you are observing are probably because target-specific C2000 code is being compiled during the simulation/MEX build. During normal Simulink simulation, the S-Function Builder creates a MEX file for the host machine. On Linux, that usually means the code is compiled using the host compiler, for example GCC. That compiler does not understand TI C2000-specific keywords and declarations such as "cregister", "interrupt", "IFR", and "IER". Those are intended to be compiled only by the TI C2000 compiler during code generation/build for the target.
You can avoid this by separating simulation code from target code. A few possible approaches are:
- Variant approach: You can use separate simulation and code-generation paths. Refer to the example: Field-Oriented Control of PMSM with Hall Sensor Using C2000 Processors - MATLAB & Simulink. Within this example, the relevant model is "mcb_pmsm_foc_hall_f28035.slx". Under the model, refer to the 'Sensor Driver Blocks', found under 'mcb_pmsm_foc_hall_f28035' -> 'Embedded Processor' -> 'Sensor Driver Blocks'. The subsystem is handled separately for Simulation vs Code Generation.
- MATLAB Function block: You can also use a MATLAB Function block and call external C functions using coder.ceval. In that case, use a code-generation check such as isequal(coder.target,'rtw') to differentiate between simulation and codegen. this will let you avoid compiling target-specific Ccode during simulation. For a related workflow, refer to this example: Buffer Logic for Data Transmission - MATLAB & Simulink.
- Custom Code approach: If the code is only needed for target code generation, include the TI libraries and source files through model configuration settings rather than forcing them into the simulation MEX build. Check the ‘Custom Code’ approach for including TI libraries under the model. The setting is found under 'Configuration Parameters' -> 'Code Generation' -> 'Custom Code' -> 'Libraries'. The TI C2000 headers/ libraries should be used in the target build configuration, not unconditioanlly during host simulation. For more information on the same, refer to the following doc page: Model Configuration Set Customization - MATLAB & Simulink
- Preprocessor guard for MEX vs target build: Since MATLAB defines `MATLAB_MEX_FILE` when compiling code for a MEX file, you can use this macro to exclude C2000-specific headers and code from the simulation build:
#ifndef MATLAB_MEX_FILE
#include "DSP28x_Project.h"
#endif
This prevents the host compiler from seeing DSP28x_Project.h, while still allowing the TI compiler to compile that code during target code generation.
Thanks,
Nivedita.
Catégories
En savoir plus sur Control Peripherals dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!