Documentation

Integrate External C Code Into Generated Code Using Custom Code Blocks and Model Configuration Parameters

The model shows how to integrate external code into generated code by using Simulink® Coder™ custom code blocks and model configuration parameters.

Open Example Model

Open the example model rtwdemo_slcustcode.

open_system('rtwdemo_slcustcode')

Several techniques exist for integrating external code into code that Simulink® Coder™ generates for a model. This model shows how to integrate external C code by using Simulink® Coder™ custom code blocks and model configuration parameters.

In the model:

  • Custom code block Model Source declares integer GLOBAL_INT1. The declaration appears in the generated file model.c.

  • Triggered subsystem Amplifier includes the custom code block System Outputs, which uses GLOBAL_INT1. The System Outputs block declares code for the nearest parent atomic subsystem. In this case, the code appears in the output for the triggered subsystem.

  • Model configuration parameters Source file and Initialize function, on the Code Generation > Custom Code pane, declare and set the variable GLOBAL_INT2.

Some overlap exists between custom code blocks and the custom code model configuration parameters. Custom code blocks provide finer granularity of code placement and are graphical.

To view the custom code blocks, double click View Custom Code Library. To view the custom code configuration parameters, double click View Custom Code Configuration.

Was this topic helpful?