
Everywhere at this page, the terms Matlab, Simulink, S-Function, and Mex refer to products and programs developed and owned by MathWorks. For more information, please visit http://matworks.com/ .
The CIF 3 code generator can generate Matlab Simulink S-Function C code from a CIF specification. It is assumed the reader of this page is familiar with the general information of the CIF 3 code generator tool. This page describes specific information applicable only to Simulink code generation.
The aim of the the conversion from CIF to Simulink is to provide a smooth path from a CIF specification to a controlled real-time system.
At this page, all the details about the Simulink code generation are discussed. For an example of how to use this code generation in practice, read Simulink code generation and simulation example.
The CIF 3 code generator supports a subset of CIF specifications. See the Supported specifications section of the CIF 3 code generator page for more information. Generation of Simulink S-Function C code adds a restriction to the type of CIF input variables caused by limitations in Simulink input ports.
Simulink input ports can only handle real and complex signals. The latter cannot be expressed in CIF, while the former creates the need for CIF input variables with data types that can be relatively easily converted to real number values. For this reason, CIF input variables must have a boolean, enumeration, integer, or real elementary type. Arrays (fixed length CIF lists) of these elementary types are also supported, they are converted to a vector of real numbers at a Simulink input port. Finally, arrays of arrays of the elementary types are converted to a matrix of real numbers at a Simulink input port.
Data types of all other CIF variables have no additional constraints. However, Simulink poses similar restrictions to its other data vectors, in particular the output ports. The CIF to Simulink code generator toool only makes variables available for output that are compatible with real number, vectors of real numbers, or matrices of real numbers. That means that use of the CIF string type, the tuple type, or arrays with a deeper nesting than two levels will not be available at the output.
When converting a real number to text, for example when printing a real value, the generated Simulink code does not preserve trailing zeroes of real number fractions while using %g. For example fmt("%.3g", 1.0) will output 1 rather than 1.000.
This may cause real number values to be printed with less digits precision than indicated in the CIF program.
Strings have an upper limit in length that is set during compilation. Longer strings are silently truncated to this length.
The CIF print statement is supported, but only for the :stdout: file. It is translated to the ssPrintf C function. This is also the only way to get a string to appear outside the Simulink S-Function block. Note that Simulink may drop the output function for platforms that have no output possibilities.
The CIF to Simulink code generator uses the common options that apply to all target languages/platforms of the CIF 3 code generator. It also has the additional Simulink Output option to state which CIF variables should be output of the generated S-Function block.
The code prefix that can be configured using a common option is used as name for the generated S-Function.
Running the Simulink code generator produces four output files:
Generated file Contents <prefix>.c The generated Simulink S-Function C code. <prefix>_library.c Common library code, gets included in <prefix>.c <prefix>_library.h Common library declarations, gets included in <prefix>.c <prefix>_report.txt Report file that links CIF variables to Simulink entries.
where <prefix> is replaced by the value of the Code prefix option during code generation.
The <prefix>.c file contains the source code of the actual S-Function. Both library files contain support code for CIF program execution. The library code is always the same. The <prefix>.c file can be compiled using the Matlab Mex C compiler. The resulting mex file can be used in Simulink (Open the Simulink Library, select User-defined functions, and then the S-Function block, drag it in the Simulink canvas, open the block , and type the <prefix> name into the Name field.)
The report file lists how CIF variables got mapped onto the input, mode, contstate, and output Simulink vectors. You can use this information