数据接口和函数接口
将模型数据元素和函数映射到代码定义
为了遵守代码标准和规范,并配置模型数据元素的表示和代码生成的入口函数,请将模型数据元素和函数映射到预定义的代码定义。
有关介绍,请参阅C Data Code Interface Configuration for Model Interface Elements。
工具
代码映射编辑器 | 将模型元素与代码接口定义相关联 (自 R2020b 起) |
对象
coder.mapping.api.CodeMapping | 用于 C 代码生成的模型数据和函数接口配置 (自 R2020b 起) |
函数
主题
配置基础
- 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. - Generate C++ Class Interface to Model or Subsystem Code
Generate a C++ class interface to code generated from a model or subsystem. - Code Definition and Mapping Limitations and Considerations
Restrictions, constraints, and considerations that apply to code definitions and code mappings. - Manage Multiple Code Mappings for a Model
Design models that are platform-neutral and ready to deploy to different run-time environments. - 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. - Exchange Data Between External Calling Code and Generated Code
When you export the generated code into your external code, exchange signal, state, and parameter data. - Generate Code That Matches Appearance of External Code
Configure how the code generator applies identifiers (symbols), comments, code styles, code format, and organization. - 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.
数据配置
- 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. - 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 入口函数、配置选项以及如何与它们对接。 - 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. - Code Generation of Parameter Objects With Expression Values
When you set the value of a parameter object (such asSimulink.Parameter
) to an expression, the generated code can preserve the expression.