C 数据接口和函数接口
将模型数据元素和函数映射到独立于模型的代码定义
为了遵守代码标准和规范,将生成的代码与外部代码集成,并满足内存要求,需要针对代码生成配置模型数据元素和入口函数的表示。您可以将模型数据元素和函数映射到由产品预定义或使用 Embedded Coder 字典创建的代码定义。对于数据元素,您还可以选择将它们映射到使用自定义存储类设计器在包中创建的代码定义。
有关介绍,请参阅模型接口元素的 C 代码生成配置。
工具
代码映射编辑器 - C | Associate model elements with code interface definitions |
对象
coder.mapping.api.CodeMapping | Model data and function interface configuration for C code generation |
coder.mapping.api.CoderDictionary | Query and set the code settings of dictionary defaults in an Embedded Coder dictionary within a Simulink data dictionary |
函数
主题
配置基础
- 模型接口元素的 C 代码生成配置
控制生成的 C 代码中模型数据元素和函数的表示。 - 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.
C 数据配置
- 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. - 为 C 代码生成配置参数
为参数设置存储类和其他相关代码生成属性。 - 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 函数配置
- 为模型入口函数配置生成的 C 函数接口
了解生成的 C 入口函数、配置选项以及如何与它们对接。 - 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. - 为非虚拟子系统生成模块化函数代码
为非虚拟子系统生成模块化函数代码。 - Rapid Prototyping Model Functions
Generate rapid prototyping code.
数据访问和初始化
- 在生成的代码中创建可调标定参数
在生成的代码中创建可在快速原型和标定过程中访问的可调参数数据。 - 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. - 在仿真和代码执行期间在参数值集之间切换
通过将相同模块参数的独立值集存储在结构体数组中,在这些值集之间进行切换。 - 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.