Main Content

Control File Packaging of Generated Entry-Point Functions and Simulink Functions

This example shows how to specify custom filenames for entry-point functions and Simulink® functions using function customization templates. Use custom filenames to group related functions together in generated code.

Inspect Model

Open the SimulinkFunctions model.

model = 'SimulinkFunctions';

The model contains five functions: the model_initialize and model_reset entry-point functions, two exported functions called f1 and f2, and a Simulink function called f3.

Create Function Customization Templates

Open the Embedded Coder Dictionary by selecting Code Interface > Embedded Coder Dictionary (Model) on the C Code tab. In the Data Interface pane, select Function Customization Template.

Click Create to create a new function customization template. The right pane populates with the properties of a new function customization template, FunctionTemplate1.

In the Name field, rename the function customization template to MyFunctionTemplate.

Populate the Header File field with the value MyHeader_$N.h and populate the Definition File field with the value MyDefinition_$N.c. The $N token expands to the name of the function. The code generator generates the functions that you map to this function customization template in these files instead of the default locations, SimulinkFunctions.c and SimulinkFunctions.h.

Click Save to save the Embedded Coder Dictionary.

Edit Code Mappings

Open the Code Mappings Editor by selecting Code Interface > Individual Element Code Mappings on the C Code tab. In the Code Mappings Editor, select the Functions tab.

By default, each function maps to Model default. In the Function Customization Template column for the functions Initialize and Simulink Function:f3, select MyFunctionTemplate.

Modify Configuration Parameters

Open the Configuration Parameters dialog box by selecting Model Settings on the Modeling tab.

In the left pane, select Code Placement. Set the File packaging format parameter to Modular. You cannot control function file packaging for a model that uses Compact or Compact (with separate data file) file packaging.

Generate Code

Generate code for the model. On the C Code tab, select Generate Code.

Inspect MyDefinition_f3.c, MyDefinition_initialize.c, MyHeader_f3.h, and MyHeader_initialize.h. Because the model maps the initialize and f3 functions to the MyTemplate function customization template, these files contain the definitions and prototypes of those functions. Because the function naming rule contains the $N token, each filename contains the name of the function that the file contains.

Inspect SimulinkFunctions.c and SimulinkFunctions.h. Because the model maps the model_reset entry-point function and the f1 and f2 exported functions to Model default, these files contain the definitions and prototypes of those Simulink functions.

Close the model.


See Also


Related Topics