Main Content

Generate Predictable Function Interface to Match Graphical Block Interface

You can generate code for a nonreusable subsystem that has a predictable function interface. A predictable interface can be useful for debugging and testing your code and integrating it with external applications. The generated code with a predictable function interface is more readable.

When you specify block parameterFunction interfaceasAllow arguments (Match graphical interface), the generated function interface matches the subsystem graphical block interface. For example, if a subsystem has two Inports and one Outport, the function interface generates two arguments for the Inports and one function argument for the Outport. The order of the arguments is determined by the port index. The function interface is predictable and does not change.

When you generate code for a nonreusable subsystem by using the block parameterFunction interfaceset toAllow arguments (Optimized), the code generator generates a subsystem function interface that passes data through arguments. The function arguments might not match the subsystem graphical block interface.

This example shows how the generated code is different when you specifyFunction interfaceasAllow arguments (Optimized)andAllow arguments (Match graphical interface).

Generate Function Interface That Has Optimized Arguments

1. Open the example modelex_mux_allow_arguments. The subsystem in the model contains three inputs and two outputs.

2. Right-click the subsystem and selectBlock Parameters (Subsystem)from the context menu. Alternatively, click in the subsystem to open the Block Parameters dialog box in theProperty Inspectorpane.

These preset settings are required to generate expected code:

  • In theMaintab, the block parameter对待原子unit被选中。

  • In theCode Generationtab,Function packagingisNonreusable functionandFunction interfaceisAllow arguments (Optimized).

3. Open theEmbedded Coderapp. ClickBuild.

The generated code inex_mux_allow_arguments.cfile contains a subsystem function interface with arguments:

/ *输出和更新原子系统:< Root > /苏bsystem' */ static void FPCSS_Mux(real_T rtu_In1, real_T rtu_In2, real_T rty_Out2[4]) { /* Constant: '/Constant1' */ rtDW.Constant1 = 5.0; /* Gain: '/Gain4' */ rtDW.Gain4 = 10.0 * rtu_In1; /* Gain: '/Gain1' incorporates: * Constant: '/Constant' */ rty_Out2[0] = 150.0; rty_Out2[1] = 15.0 * rtu_In2; rty_Out2[2] = 15.0 * rtu_In1; rty_Out2[3] = 15.0 * rtu_In2; }

TheAllow arguments (Optimized)specification leads to optimized generated code by reducing global RAM. The function interface has some inputs and outputs as function arguments. The generated function interface does not match the subsystem graphical block interface.

Generate Function Interface That Has Arguments Matching Graphical Interface

1. In the example modelex_mux_allow_arguments, open the Subsystem Block Parameters dialog box.

2. On theCode Generationtab, specifyFunction interfaceasAllow arguments (Match graphical interface)and clickApply.

3. Generate code for the model.

The generated code inex_mux_allow_arguments.cfile contains a subsystem function interface with arguments that match the subsystem graphical block interface:

/ *输出和更新原子系统:< Root > /苏bsystem' */ static void FPCSS_Mux(real_T rtu_In1, const real_T rtu_In2[2], real_T rtu_In3, real_T rty_Out1[2], real_T rty_Out2[4]) { /* SignalConversion generated from: '/Out1' incorporates: * Constant: '/Constant1' * Gain: '/Gain4' */ rty_Out1[0] = 5.0; rty_Out1[1] = 10.0 * rtu_In1; /* Gain: '/Gain1' incorporates: * Constant: '/Constant' */ rty_Out2[0] = 150.0; rty_Out2[1] = 15.0 * rtu_In3; rty_Out2[2] = 15.0 * rtu_In2[0]; rty_Out2[3] = 15.0 * rtu_In2[1]; }

TheAllow arguments (Match graphical interface)specification generates a predictable interface and maps the function arguments to the graphical interface of the Subsystem block. Arrays as part of the function arguments account for the combination of input or output signals that the Mux block uses.

For the Enabled, Triggered, or Resettable Subsystem with theAllow arguments (Match graphical interface)specification, the generated function contains arguments corresponding to each Enable, Trigger block, and Reset block present within that subsystem.

Limitations

  • TheFunction interfaceset asAllow arguments (Match graphical interface)specification is not applicable to context menu optionC/C++>构建这个子系统.

  • You cannot control the argument names.

Related Topics