Main Content

Generate Instantiable Code for Functions

For the MATLAB Function block, you can use the InstantiateFunctions parameter to generate a VHDL® entity, Verilog® or SystemVerilog module for each function. HDL Coder™ generates code for each entity or module in a separate file.

The InstantiateFunctions options for the MATLAB Function block are listed in the following table.

InstantiateFunctions SettingDescription
'off' (default)

Generate code for functions inline.

'on'

Generate a VHDL entity, Verilog or SystemVerilog module for each function, and save each module or entity in a separate file.

How To Generate Instantiable Code for Functions

To set the InstantiateFunctions parameter using the HDL Block Properties dialog box:

  1. Right-click the MATLAB Function block.

  2. Select HDL Code > HDL Block Properties.

  3. For InstantiateFunctions, select on.

To set the InstantiateFunctions parameter from the command line, use hdlset_param. For example, to generate instantiable code for functions in a MATLAB Function block, myMatlabFcn, in your DUT subsystem, myDUT, enter:

hdlset_param('my_DUT/my_MATLABFcnBlk', 'InstantiateFunctions', 'on')

Generate Code Inline for Specific Functions

If you want to generate instantiable code for some functions but not others, enable the option to generate instantiable code for functions, and use coder.inline. See coder.inline for details.

Limitations for Instantiable Code Generation for Functions

The software generates code inline when:

  • Function calls are within conditional code or for loops.

  • Any function is called with a nonconstant struct input.

  • The function has state, such as a persistent variable, and is called multiple times.

  • There is an enumeration anywhere in the design function.

See Also

Related Topics