Configure Model to Generate C API Code - MATLAB & Simulink (original) (raw)

Main Content

Configure your model to include C API elements in the generated code. The C API layer is an extension of the generated code, so you can configure the C API generation only for elements that exist in the generated code. To configure an element to generate C API code, you need to:

This table summarizes the required configuration for each type of model element:

Model Element Type Applies To Required Configuration Example Link
Root-level ports Output signals of root-level input port blocks and input signals of root-level output port blocks In the Configuration Parameters dialog box, enable C API code generation for root-level ports (see Generate C API for: root-level I/O). Configure Model to Generate C API Code for Root-Level Ports
Model signals Output signals of blocks that are not root-level input port blocks In the Configuration Parameters dialog box, enable C API code generation for signals (see Generate C API for: signals).To prevent the code generator from optimizing the signal away, do one of these: Add the signal to the model mappings and specify its storage class as a value other than Auto.Configure Signals as Test Points. Configure Model to Generate C API Code for Signals
Model states Model elements whose value in an execution step of the model depends on its value in the previous model execution step In the Configuration Parameters dialog box, enable C API code generation for states (see Generate C API for: states). Configure Model to Generate C API Code for States
Model parameters Any variables that are used by the model. The variables can be: MATLABĀ® variables or Simulink.Parameter variablesDefined in the base workspace or the model workspace In the Configuration Parameters dialog box, enable C API code generation for parameters (see Generate C API for: parameters).To prevent the code generator from optimizing the parameter away, do one of these: Specify the storage class of the parameter as a value other than Auto.In the Configuration Parameters dialog box, specify the default parameter behavior as tunable (see**Default parameter behavior**). Configure Model to Generate C API Code for Model Parameters
Block parameters Values of block parameters In the Configuration Parameters dialog box, enable C API code generation for parameters (see Generate C API for: parameters).To prevent the code generator from optimizing the parameter away, in the Configuration Parameters dialog box, specify the default parameter behavior as Tunable (see**Default parameter behavior**). Configure Model to Generate C API Code for Block Parameters

Some model elements belong to multiple types of C API elements and therefore you can access them in multiple ways. For example, a signal line that connects aGain block and an Outport block can be accessed as a model signal or as a root-level output port signal.

See Also

Topics