How can I call a function in simulink that is defined in one of the source file in the Custom Code of the Code generation pane ?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to include custom code into a simulink model and trying to call one of the function that is in the custom code in the model. However, I can not do this using the custom code section under Code generation. How can I call a function that is defined in the custom code of the code generation in the simulink model ? Do I need to define this function in the simulation target code generation pane ? if so what compiler does it use ? I am trying to generate code for F28335 C2000 family of the Texas instrument.
0 Kommentare
Antworten (1)
Jon Boerner
am 17 Okt. 2014
There are a couple options for calling a custom function from your model.
The first is to use a MATLAB function block. In a MATLAB Function block you can use a function called coder.ceval in order to call your custom code. The examples at the bottom of that page are for using the MATLAB Coder product, but the MATLAB code is specifies is exactly what you would put in the MATLAB Function block. As long as the files containg the function declaration and definition are in the custom code section of the configuration parameters, you should be all set.
The more popular way to incorporate custom code is to use something called S-functions. Lots of information on how to use S-functions can be found starting from this page:
My suggestion would be to look at the Legacy Code Tool, as I have found that to be the easiest to use and extend in the future. If you go that route, you do not even need to include the custom files in the custom code section. Whenever someone uses the block for your custom function, the source and header files will be included automatically in the code generation process (assuming you followed all the steps).
Please take a look at the above documentation pages and let me know in the comments if you have any questions.
3 Kommentare
Jon Boerner
am 17 Okt. 2014
Hi Claude,
My guess is that the CCSv6 compiler automatically includes some particular headers, or that there are other keywords allowed by that compiler not allowed by Windows SDK 7.0?
There is actually a support package for Simulink that lets you use the CCS family of compilers and will take care of a lot issues specific to compiling for that target. More information is here:
My suggestion would be to run through using that support package and see if it makes things any easier/straightforward.
Siehe auch
Kategorien
Mehr zu Simulink Coder finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!