C Data and Function Interfaces
To comply with code standards and guidelines, integrate generated code with external code, and address memory requirements, configure the representation of model data elements and entry-point functions for code generation. You configure model data elements and functions by mapping them to code definitions that are predefined by the product or created with the Embedded Coder Dictionary. For data elements, you also have the option of mapping them to code definitions created in packages with the Custom Storage Class Designer.
For an introduction, see C Data Code Interface Configuration for Model Interface Elements.
Tools
Code Mappings Editor – C | Associate model elements with code interface definitions |
Objects
coder.mapping.api.CodeMapping | Model data and function interface configuration for C code generation (Since R2020b) |
coder.mapping.api.CoderDictionary | Query and set the code settings of dictionary defaults in an Embedded Coder dictionary within a Simulink data dictionary (Since R2021a) |
Functions
Topics
Configuration Fundamentals
- C Data Code Interface Configuration for Model Interface Elements
Control the representation of model data elements and functions in generated C code by using a data code interface configuration. - Code Definition and Mapping Limitations and Considerations
Restrictions, constraints, and considerations that apply to code definitions and code mappings. - Configure Default C Code Generation for Categories of Data Elements and Functions
Apply default code generation configurations for categories of model data and functions across a model. - Manage Multiple Code Mappings for a Model
Design models that are platform-neutral and ready to deploy to different run-time environments. - Protect Global Data with const and volatile Type Qualifiers
Prevent data corruption and improve code safety by applying C type qualifiersconst
andvolatile
to global data in generated code. - How Generated Code Exchanges Data with an Environment
The generated code exchanges signal, state, and parameter data with the calling environment through a data interface. - Configure Generated Code According to Interface Control Document Specifications
Configure code generation settings for a model according to specifications from an interface control document. - Migration of Model Data Configurations to Code Mappings
How Simulink® migrates code definitions for models created before release R2020b to code mappings and related information to consider. - Migration of Memory Section and Shared Utility Settings from Configuration Parameters to Code Mappings
For models created before release R2018a, how Simulink migrates memory section and shared utility function configuration parameter settings to model code mappings for C code generation.
C Data Configuration
- Choose Data Configuration Approach
Make decisions about the design data used by your model based on your code generation requirements. - Configure Root-Level Inport Blocks for C Code Generation
Set the storage class and other relevant code generation properties for root-level Inport blocks. - Configure Root-Level Outport Blocks for C Code Generation
Set the storage class and other relevant code generation properties for root-level Outport blocks. - Configure Signal Data for C Code Generation
Set the storage class and other relevant code generation properties for signal data. - Configure Parameters for C Code Generation
Set the storage class and other relevant code generation properties for parameters. - Configure Block States for C Code Generation
Set the storage class and other relevant code generation properties for block states. - Configure Data Stores for C Code Generation
Set the storage class and other relevant code generation properties for data stores. - Choose Storage Class for Controlling Data Representation in Generated Code
Choose a storage class to apply to data elements in a model, such as signals, states, and block parameters. - Control Placement of Global Data Definitions and Declarations in Generated Files
Modularize the generated code and establish clear ownership of global data by controlling the file placement of each declaration and definition. - Design Data Interface by Configuring Inport and Outport Blocks
Customize the data interface of a model to enable integration of the generated code with your own code and to improve code traceability and readability.
C Function Configuration
- Configure Generated C Function Interface for Model Entry-Point Functions
Learn about generated C entry-point functions, configuration options, and how to interface with them. - Control Data and Function Interface in Generated Code
Control how generated code exchanges data with a calling environment. - Configure Entry-Point Function Interfaces for Simulink Function and Function Caller Blocks
Customize entry-point function names and step function arguments for Simulink Function and Function Caller blocks. - Generate Modular Function Code for Nonvirtual Subsystems
Generate modular function code for nonvirtual subsystems. - Rapid Prototyping Model Functions
Generate rapid prototyping code. - Control File Packaging of Generated Entry-Point Functions and Simulink Functions
This example shows how to specify custom filenames for entry-point functions and Simulink® functions using function customization templates.
Data Access and Initialization
- Create Tunable Calibration Parameter in the Generated Code
In the generated code, create tunable parameter data that you can access during rapid prototyping and calibration. - Reuse Parameter Data in Different Data Type Contexts
Reuse parameter data by creating aSimulink.Parameter
object or numeric MATLAB® variable that you can use in different data type contexts. - Limitations for Block Parameter Tunability in Generated Code
Limitations can prevent a block parameter from appearing in the generated code as tunable, which means you cannot interact with the parameter value after compiling the code. - Access Signal, State, and Parameter Data During Execution
As you iteratively develop a model, capture output signal and state data that model execution generates. Tune parameter values during execution to observe results on the outputs. - Switch Between Sets of Parameter Values During Simulation and Code Execution
Switch between independent sets of values for the same block parameters by storing the sets in an array of structures. - Preserve Variables in Generated Code
As you iteratively develop a model, you can tune block parameter values during simulation or execution of generated code to observe the results on signal and state values. - Configure Packaging of Parameter Arguments in Generated Code
Customize the implementation of parameter arguments in generated code. - Control Signal and State Initialization in the Generated Code
Generate code that enables you to store tunable initial conditions in memory, for example, for modeling a system that shuts down and restarts. - Initialization of Signal, State, and Parameter Data in the Generated Code
To match the numerics of a simulation in Simulink, the generated code assigns initial values to global data, especially for block states and parameters. - Compile Code Conditionally for All Values of Variant Parameters with Same and Different Dimensions
This example shows how to generate a C code that contains all the active and inactive values of variant parameters.