How to use custom C data types in Simulink S-Functions

3 Ansichten (letzte 30 Tage)
Christopher Hack
Christopher Hack am 28 Mai 2015
Bearbeitet: Sam Fishwick am 14 Mär. 2019
Hi,
I am new to the whole MATLAB/Simulink programming environment and my boss is having us write firmware for our new product using this tool. I am essentially using the S-Functions as hardware drivers to call C code which I have written to carry out a specific hardware related task. I want to create libraries with these S-Functions in them so that it is easy for us to distribute among users. In some of the C functions that I'm calling using the S-Functions there are custom data types (for instance, one is called TIMER_TypeDef) that I not only need to be able to get Simulink to recognize, but also need to be able to assign as the input data type for an S-Function. I have read the support articles on the matter, chiefly this one:
In the article, it says that "the S-functions mdlInitializeSizes routine must..." and then gives an example of code that needs to be placed at the beginning of mdlInitializeSizes. My problem is being new to this programming environment I don't know where to define this routine. I don't even know if this is a MATLAB function or if it's something that's supposed to go in the C code that the model generates (which wouldn't make much sense, but the syntax in the example is very C code like, hence the confusion).
So, my question is where do I need to modify or define this S-function so that I can register my custom data type with Simulink?
Thank you in advance for your time.
-Chris Hack

Antworten (1)

Sam Fishwick
Sam Fishwick am 14 Mär. 2019
Bearbeitet: Sam Fishwick am 14 Mär. 2019
Mathworks provides templates for the S-functions.
I've seen mdlInitializeSizes within template sfuntmpl_doc.c
To find it either:
1:
Run this command by entering it in the MATLAB Command Window:
sfunddg_cb_edit('sfuntmpl_doc');
2:
Alternatively, sfuntmpl_doc.c can be found in your MATLAB installation path, most likely here:
MATLAB_ROOT\simulink\src

Kategorien

Mehr zu Simulink Coder finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by