Main Content

Integrate Generated Code with Custom Code

For the top-level subsystem that has internal state, the generated FUNCTION_BLOCK code has ssMethodType. ssMethodType is a special input argument that the coder adds to the input variables section of the FUNCTION_BLOCK section during code generation. ssMethodType enables you to execute code for Simulink® Subsystem block methods such as initialization and computation steps. The generated code executes the associated CASE statement based on the value passed in for this argument.

To use ssMethodType with a FUNCTION_BLOCK for your model, in the generated code, the top-level subsystem function block prototype has one of the following formats:

Has Internal StatessMethodType Contains...
Yes

The generated function block for the block has an extra first parameter ssMethodType of integer type. This extra parameter is in addition to the function block I/O parameters mapped from Simulink block I/O ports. To use the function block, first initialize the block by calling the function block with ssMethodType set to integer constant SS_INITIALIZE. If the IDE does not support symbolic constants, set ssMethodType to integer value 0. For each follow-up invocation, call the function block with ssMethodType set to constant SS_STEP. If the IDE does not support symbolic constants, set ssMethodType to integer value 1. These settings cause the function block to initialize or compute and return output for each time step. If you select Keep top level ssMethod name same as non-top level, the ssMethodType SS_STEP will be generated as SS_OUTPUT with integer value 3.

No

The function block interface only has parameters mapped from Simulink block I/O ports. There is no ssMethodType parameter. To use the function block in this case, call the function block with I/O arguments.

For non top-level subsystems, in the generated code, the subsystem function block prototype has one of the following formats:

Has Internal StatessMethodType Contains...
Yes

The function block interface has the ssMethodType parameter. The generated code might have SS_INITIALIZE, SS_OUTPUT, or other ssMethodType constants to implement Simulink semantics.

If non top-level subsystems have blocks with constant sample time the generated code could have SS_CONST_CODE constants to implement Simulink semantics.

No

The function block interface only has parameters mapped from Simulink block I/O ports. There is no ssMethodType parameter.