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 parameter Function interface as Allow 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 parameter Function interface set to Allow 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 specify Function interface as Allow arguments (Optimized) and Allow arguments (Match graphical interface).

Generate Function Interface That Has Optimized Arguments

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

2. Right-click the subsystem and select Block Parameters (Subsystem) from the context menu. Alternatively, click in the subsystem to open the Block Parameters dialog box in the Property Inspector pane.

These preset settings are required to generate expected code:

  • In the Main tab, the block parameter Treat as atomic unit is selected.

  • In the Code Generation tab, Function packaging is Nonreusable function and Function interface is Allow arguments (Optimized).

3. Open the Embedded Coder app. Click Build.

The generated code in ex_mux_allow_arguments.c file contains a subsystem function interface with arguments:

/* Output and update for atomic system: '<Root>/Subsystem' */
static void FPCSS_Mux(real_T rtu_In1, real_T rtu_In2, real_T rty_Out2[4])
{
  /* Constant: '<S1>/Constant1' */
  rtDW.Constant1 = 5.0;

  /* Gain: '<S1>/Gain4' */
  rtDW.Gain4 = 10.0 * rtu_In1;

  /* Gain: '<S1>/Gain1' incorporates:
   *  Constant: '<S1>/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;
}

The Allow 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 model ex_mux_allow_arguments, open the Subsystem Block Parameters dialog box.

2. On the Code Generation tab, specify Function interface as Allow arguments (Match graphical interface) and click Apply.

3. Generate code for the model.

The generated code in ex_mux_allow_arguments.c file contains a subsystem function interface with arguments that match the subsystem graphical block interface:

/* Output and update for atomic system: '<Root>/Subsystem' */
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: '<S1>/Out1' incorporates:
   *  Constant: '<S1>/Constant1'
   *  Gain: '<S1>/Gain4'
   */
  rty_Out1[0] = 5.0;
  rty_Out1[1] = 10.0 * rtu_In1;

  /* Gain: '<S1>/Gain1' incorporates:
   *  Constant: '<S1>/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];
}

The Allow 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 the Allow arguments (Match graphical interface) specification, the generated function contains arguments corresponding to each Enable, Trigger block, and Reset block present within that subsystem.

Limitations

  • The Function interface set as Allow arguments (Match graphical interface) specification is not applicable to context menu option C/C++ > Build this Subsystem.

  • You cannot control the argument names.

Related Topics