Generate Predictable Function Interface to Match Graphical Block Interface

You can generate code for 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 predicatable 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's 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 nonreusable Subsystem with 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 with the Subsystem's 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.

3. Observe these preset settings that are needed 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).

4. 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's graphical block interface.

Generate Function Interface That Has Arguments that Match 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 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 with the graphical interface of the Subsystem block. There are arrays as part of the function arguments to account for the combination of input or output signals that th Mux block uses.

For the Enabled, Triggered, or Resettable Subsystem with Allow arguments (Match graphical interface) specification, the generated function contains arguments corresponding to each Enable, Trigger block, and/or 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