Data Representation and Access
Signals, states, and block parameters that you create in a model appear in the generated code as variables. Control the way that the code declares and defines these variables.
Generate efficient code by reducing memory usage and specifying numeric data types. Control the naming, definition, and usage of data types.
Ease the integration of the generated code with your own code by specifying identifiers and file placement of declarations and definitions.
Manage access to signal data and specify parameter tunability.
Package signal and parameter data into structures.
Improve code readability and traceability.
Functions
coder.mapping.create |
Create C code mapping environment for model |
coder.mapping.defaults.allowedProperties |
Return properties for model default mapping category |
coder.mapping.defaults.allowedValues |
Return value of property for model default mapping category |
coder.mapping.defaults.dataCategories |
Return default mapping categories for model data |
coder.mapping.defaults.get |
Return value of property for model default mapping category |
coder.mapping.defaults.set |
Set value for property of model default mapping category |
Topics
Storage in the Generated Code
How Generated Code Stores Internal Signal, State, and Parameter Data
To calculate output data from input data, the generated code must store some internal data in memory, such as block state data and nonscalar parameter data.
Standard Data Structures in the Generated Code
The generated code stores data, such as signals and states, in global structures. Use the structures to access and integrate with the data.
The real-time model data structure describes the generated model code and enables your code to interact with the generated code.
Parameter Data Types in the Generated Code
Optimize the generated code and generate code for specific processors by controlling the data types that store parameter data in computer memory.
Share Data Between Code Generated from Simulink, Stateflow, and MATLAB
Stateflow and MATLAB Coder can fully define their data definitions, or they can inherit them from Simulink.
Access for Tuning and Testing
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 the 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 the effect 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.
Configure Data Accessibility for Rapid Prototyping
As you iteratively develop a model, you can tune block parameter values during simulation or execution of the generated code to observe the effect on signal and state values.
Specify Instance-Specific Parameter Values for Reusable Referenced Model
When you create a reusable component as a referenced model, configure block parameters to use either the same value for all instances of the component or a different value for each instance.
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.
Custom Storage
Apply Storage Classes to Individual Signal, State, and Parameter Data Elements
Control data representation in the generated code by applying storage classes directly, which overrides the default storage classes that you specify in the Code Mapping Editor.
Apply Custom Storage Classes to Individual Signal, State, and Parameter Data Elements
Customize data representation in the generated code by applying custom storage classes to individual data items.
Choose a Storage Class for Controlling Data Representation in the 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.
Protect Global Data with const and volatile Keywords
Applyconst
andvolatile
to global data in the generated code. The keywords can help prevent data corruption and improve safety for your application.
Create Custom Storage Classes by Using the Custom Storage Class Designer
For additional control of data representation in the generated code, create custom storage classes.
Finely Control Data Representation by Writing TLC Code for a Custom Storage Class
For advanced control of data representation in the generated code, create custom storage classes by writing TLC code.
Use a data store to explicitly model a piece of shared global data in the generated code.
Access Data Through Functions with Custom Storage Class GetSet
Use the custom storage classGetSet
to integrate the generated code with legacy code that uses specialized functions to read from and write to data.
Generate Local Variables with Localizable Custom Storage Class
For signals, if possible, generate variables that are local to functions rather than in global storage.
Named and Custom Data Types
Control Data Type Names in Generated Code
Control the names of primitive, structure, and enumerated data types in the generated code.
Organize Data into Structures in Generated Code
Create structures of signal, state, and parameter data in the generated code.
Use Enumerated Data in Generated Code
Enumerated data is data that is restricted to a finite set of values. Create enumerations in the generated code.
Control File Placement of Custom Data Types
Integrate the generated code with your own code by placingtypedef
statements in generated and imported files.
Specify Boolean and Data Type Limit Identifiers
Integrate the generated code with your code by specifying the identifiers that correspond to Booleanfalse
andtrue
。同时,指定对应的标识符data type limits, which the generated code uses to determine overflows.