Configure Model to Generate C API Code
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:
Make sure the element is not configured to be optimized away, so it exists in the generated code.
Apply additional configuration settings that are required for generating C API code for the element type.
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:
| 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:
| 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:
| Configure Model to Generate C API Code for Model Parameters |
Block parameters | Values of block parameters |
| 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 a Gain block and an Outport block can be accessed as a model signal or as a root-level output port signal.