Main Content

Function Call

This example shows how to generate a function call by adding a subsystem, which implements the operations that you want.

C Construct

void add_function(void)
   y1 = u1 + u2;


1. Open example model ex_function_call.

The subsystem has two inputs and returns one output.

Selecting the Treat as atomic unit parameter enables parameters on the Code Generation tab. The Code Generation tab provides these customizations:

  • Function packaging set to Nonreusable function

  • Function name options set to User specified

  • Function name specified as add_function

  • File name options set to Use function name

2. To build the model and generate code, press Ctrl+B.


In ex_function_call.c, the function is called from ex_function_call_step:

/* Model step function */
void ex_function_call_step(void)
  /* Outputs for Atomic SubSystem: '<Root>/Add_Subsystem' */

  /* End of Outputs for SubSystem: '<Root>/Add_Subsystem' */

The function prototype is externally declared through the subsystem file, add_function.h:

extern void add_function(void);

#endif                                 /* add_function_h_ */

 * File trailer for generated code.
 * [EOF]

The function definition is in the subsystem file add_function.c:

void add_function(void)
  /* Outport: '<Root>/y1' incorporates:
   *  Inport: '<Root>/u1'
   *  Inport: '<Root>/u2'
   *  Sum: '<S1>/Sum'
  rtY.y1 = u1 + u2;

See Also

Related Topics