Main Content

Customize Default Naming Rule of Generated Entry-Point C Functions in Subcomponent Models

Entry-point functions are functions in the generated model code that interface with your external code. The example Customize Generated Entry-Point C Function Names explains and demonstrates how to customize the names of generated entry-point functions. This is a supplementary example, showing an additional option for customizing entry-point function names in code generated from models configured for subcomponent deployment type.

Open and Explore Model

Open the model EntryPoints.

epModel = "EntryPoints";
open_system(epModel)

Model EntryPoints. The two root-level inports are in a rectangle labeled Input arguments. The two root-level outports are in a rectangle labeled Output arguments. The three blocks between the inports and the outports are in a rectangle labeled Step Function body.

EntryPoints is a nonreusable, single-rate single-tasking model, configured to use the ERT system target file.

Customize Default Naming Rule for Generated Entry-Point C Functions in Subcomponent Models

The example Customize Generated Entry-Point C Function Names demonstrates how you can customize the names of generated entry-point functions directly or by using function customization templates. The names of functions you do not use any of these option with are created according to a default naming rule. When your model is configured for component deployment type, the default naming rule is constant, and you cannot customize it. In contrast, when the model is configured for subcomponent deployment type, the default naming rule is customizable, as shown in this example.

Configure the model for subcomponent deployment type:

  1. Open the Embedded Coder® app.

  2. In the Simulink Toolstrip, select the C Code tab.

  3. In the Prepare section, select Automatic > Subcomponent.

C Code tab is selected in the Simulink Toolstrip. The Deployment Type drop-down list is open, and the arrow cursor is on the Subcomponent entry in the list.

Alternatively, you can specify the deployment type programmatically:

  1. Get a handle to the code mappings object of the model and store it in the variable codeMapObj.

  2. Use the setDeploymentType function with the code mappings object to specify the deployment type as Subcomponent.

codeMapObj = coder.mapping.api.get(epModel);
setDeploymentType(codeMapObj,"Subcomponent")

Specify Default Naming Rule for Generated Entry-Point Function Names

When the model is configured for subcomponent deployment type, the default naming rule for generated entry-point function names is specified as the value of the configuration parameter Subsystem methods. You specify its value as a combination of valid C language characters and the macros $F, $H, $M, $N, $R, and $U. For the definition of each macro, see Subsystem methods.

  1. Open the Configure Parameters dialog box and navigate to Code Generation > Identifiers.

  2. On the right, locate the parameter Subsystem methods and update its value to subName_$F$R$M.

  3. Click Apply.

Configuration Parameter dialog box. On the left, Code Generation > Identifiers is selected. On the right, in the Identifier format control section, the System method parameter is highlighted with the value subName_$F$R$M.

Alternatively, you can use the function set_param to programmatically specify the value of this configure parameter:

set_param(epModel,CustomSymbolStrFcn="subName_$F$R$M")

This is how the macros are used in this naming rule:

  • The macro $F is replaced by the identifier of the function, such as initialize. The step function of a model configured for subcomponent deployment type has no identifier, so the code generator ignores the macro $F when it creates its name in these settings.

  • The macro $R is replaced by the name of the model.

  • The macro $M is replaced by an auto generated name-mangling text, required to avoid naming collisions. If there is no name collision, this macro is ignored.

In the Simulink Toolstrip, select the C Coder tab. Then, in the Generate Code section, click Generate Code to generate code from the model.

Simulink Toolstrip with the C Code tab selected. The arrow cursor is clicking the Generate Code button.

Alternatively, use the slbuild function to programmatically generate model code. Use the evalc function to suppress the output of slbuild.

evalc("slbuild(epModel)");

In the Code pane, navigate to the generated header file EntryPoints.h and examine the declaration of the model entry-point functions.

Code pane showing the declaration of the functions subName_EntryPoints and subName_initialize_EntryPoints in the header file EntryPoints.h.

The function names adhere to the naming rules you specified in the configuration parameter Subsystem methods.

See Also

| | | |

Topics