Documentation

Function Reuse in Generated Code

This model shows how to configure a subsystem for reuse of generated code. By selecting the Subsystem Parameters option Treat as atomic unit, you can specify that the code for that subsystem executes as an atomic unit. Once a system is marked atomic, you can specify how the subsystem is represented in code via the Subsystem Parameters option Code Generation Function Packaging.

  • Inline: An inlined function

  • Nonreusable Function: Function with I/O passed as global data

  • Reusable Function: Function with I/O passed as function arguments

  • Auto: Let Simulink Coder optimize based on context

The last two options permit Simulink to reuse the subsystem in the generated code. The function name is controlled with the "Code Generation Function name" option. The last two options permit Simulink to reuse the subsystem in the generated code. The function name is controlled with the "Code Generation Function name" option. Here, SS2 is simply a copy of SS1, which is configured as a "Reusable Function" with function name "myfun". Notice that the system is a parameterized masked subsystem. Parameters of a mask become arguments to the function. This example uses parameters: T1Break, T1Data, T2Break, and T2Data.

Instructions To see the subsystem parameters, right-click the subsystem block and select "SubSystem Parameters." To see the content of the masked subsystem, right-click the subsystem block and select "Look Under Mask."

Example Model

model = 'rtwdemo_ssreuse';
open_system(model);

Was this topic helpful?