Main Content

Manage Replacement of金宝appData Types in Generated Code

You can use theData type replacementconfiguration parameter to control the replacement of Simulink®data types in generated code:

  • If you set the parameter toUse C data types with fixed-width integers(default), the generated code uses data types from the C99 language standard, which includes definitions fromstdint.handstdbool.h。SeeC99中数据类型生成的代码

    The code generator does not create thertwtypes.hheader file. If you use custom code that requiresSimulink Coder™data type definitions, you can force the generation ofrtwtypes.hby selecting theCoder typedefs compatibilitycheck box.

  • If you set the parameter toUse coder typedefs, the code generator creates the header filertwtypes.hand generates data types that are based on the C89 language standard. Thertwtypes.hfile defines the data types throughtypedefstatements that build on C primitive types, for example,floatandshort。If you also select theSpecify custom data type namescheck box, you can specify replacement names for theSimulink Coderdata types. SeeControl Names of Simulink Coder Primitive Data Types

By default, the generated code aggregates signal, block parameter, and state data into structures (seeHow Generated Code Exchanges Data with an EnvironmentandHow Generated Code Stores Internal Signal, State, and Parameter Data). You can specify a naming rule for the structure types. You can also place data items into separate custom structures and specify names for the custom structure types. SeeControl Names of Structure Types

Use the naming control to:

You can also reuse data type definitions in generated code, for example,typedefstatements from external code. SeeGenerate Code That Reuses Data Types From External Code

C99中数据类型生成的代码

When theData type replacementconfiguration parameter is set toUse C data types with fixed-width integers, the code generator replaces Simulink data types with C99 data types as shown in this table.

Simulink Name Code Generation Name

double

double

single

float

int32

int32_t

int16

int16_t

int8

int8_t

uint32

uint32_t

uint16

uint16_t

uint8

uint8_t

boolean

bool

int

int

uint

unsigned int

char

char

uint64

uint64_t

int64

int64_t

You cannot specify replacements for the generated data type names.

Control Names of金宝appCoderPrimitive Data Types

To rename aSimulink Coderprimitive data type such asint8_T, create aSimulink.AliasTypeobject whose name matches the type name that you want the generated code to use. For example, to create a type namedmyType, at the command prompt, enter:

myType = Simulink.AliasType;

Set theBaseTypeproperty to the name of the Simulink data type that corresponds to the targetSimulink Coderdata type. For example, if the target type isint8_T, specifyint8。To identify the Simulink data type, use the information in the table.

Simulink CoderType Name Corresponding Simulink Type Name

real_T

double

real32_T

single

int32_T

int32

int16_T

int16

int8_T

int8

uint32_T

uint32

uint16_T

uint16

uint8_T

uint8

boolean_T

boolean

For configuring data type replacement throughout an entire model (Configuration Parameters>Code Generation>Data Type Replacement), you can alternatively use one of these types:

  • uint8

  • int8

  • intn*

int_T

intn*

uint_T

uintn*

char_T

intn*

uint64_T

uint64

int64_T

int64

*nmust be 8, 16, 32, or 64.

Note

Theboolean_TBaseTypemust promote to a signedint

For example, to replace the type nameuint8_TwithmyType, set theBaseTypeproperty of theSimulink.AliasTypeobject to'int8'

myType.BaseType ='int8';

Then, use one or both of these techniques to apply the type to data items in a model:

  • Configure data type replacements. Throughout the code that you generate from a model, you can replace aSimulink Coderdata type name with the name of theSimulink.AliasTypeobject. You configure data type replacements through model configuration parameters (Configuration Parameters>Code Generation>Data Type Replacement

    For an example that shows how to use data type replacement, seeReplace and Rename Simulink Coder Data Types to Conform to Coding Standards

  • Use the name of theSimulink.AliasTypeobject to specify the data type of an individual signal, that is, a block output, or block parameter. By default, due to data type propagation and inheritance (seeData Type Inheritance Rules), the signals, states, and parameters of other downstream blocks typically inherit the same data type. Optionally, you can configure data items in upstream blocks to inherit the type (通过回propagatio继承:继承n) or stop the propagation at an arbitrary block by specifying a noninherited data type setting.

    To specify a data type for an individual data item, use the Model Data Editor (on theModelingtab, clickModel Data Editor). You can use the name of the sameSimulink.AliasTypeobject to specify the data types of multiple data items.

    For an example that shows how to use aSimulink.AliasTypeobject directly in a model, seeCreate Data Type Alias in the Generated Code

Control Names of Primitive Types Technique
Change the name of a primitive type that the generated code uses to define variables by default (for example,int8_T).

Configure a data type replacement for an entire model.

To replace a defaultSimulink Coderdata type name with the corresponding Simulink type name, for example, to replaceint8_Twithint8, you do not need to create aSimulink.AliasTypeobject. SeeUse Simulink Data Type Names Instead of Simulink Coder Data Type Names

To share data type replacements throughout a model reference hierarchy, use referenced configuration sets (seeShare a Configuration Across Referenced Models).

Configure the generated code to define a particular data item, such as a variable, by using a specific, meaningful type name.

在模型中,找到相对应的数据项s to the variable. For example, trace from the code generation report to the model. Use the name of theSimulink.AliasTypeobject to set the data type of the item.

If necessary, to prevent other data items in upstream and downstream blocks from using the same type name, configure those items to use a data type setting that is not inherited. By default, most signals use the inherited typeInherit: Inherit via internal rule

Use the same type name for multiple signals and other data items in a data path, which is a series of connected blocks.

In the model, use the name of aSimulink.AliasTypeobject to set the data type of one of the signals in the path, for example, a root-levelInportblock or aConstantblock. For example, if the path begins with anInportblock at the root level of the model, you can specify the type in that block. By default, due to data type propagation, the data items in the other blocks typically inherit the same type.

通常情况下,无论你在数据路径规范ify the type, downstream data items inherit the type. You can configure upstream data items to inherit the type, too. Consider specifying the type in a block that you do not expect to remove or change frequently.

Configure the generated code to replace an implementation-dependent type, such aschar_Torboolean_T, and another type of equivalent bit length with a single type name that you specify. Use the name of theSimulink.AliasTypeobject to configure multiple data type replacements simultaneously. SeeReplace Implementation-Dependent Types with the Same Type Name

Use金宝appData Type Names Instead of金宝appCoderData Type Names

For consistency between the data type names that you see in a model and in the generated code, you can configure data type replacements so the code uses Simulink type names instead ofSimulink Codernames. For eachSimulink Codertype that you want to rename, use the Simulink data type name to specify the replacement name. You do not need to createSimulink.AliasTypeobjects.

To replaceboolean_T,int_T, oruint_T, use the information in the table.

Simulink CoderType Name Replacement Names to Use

boolean_T

One of these names:

  • boolean

  • uint8

  • int8

  • intn*

int_T

intn*

uint_T

uintn*

char_T

intn*

* Replacenwith the number of bits displayed inConfiguration Parameters>Hardware Implementationfor eitherNumber of bits: intorNumber of bits: char。Use the appropriate number of bits for the data type that you want to replace.

You cannot use this technique to replacereal_Twithdoubleorreal32_Twithsingle

Replace Implementation-Dependent Types with the Same Type Name

SomeSimulink Codertype names map to C primitives that are implementation-dependent. For example, theSimulink Codertypeint_Tmaps to the C typeint, whose bit length depends on the native integer size of your target hardware. Other implementation-dependent types includeboolean_T,char_T, anduint_T

For more readable, simpler code, you can use the same type name to replace multipleSimulink Codertypes of the same size. For example, if the native integer size of your hardware is 32 bits, you can replaceint_Tandint32_Twith the same type name, say,myInt

  1. Configure your target hardware settings inConfiguration Parameters>Hardware Implementation

  2. Create aSimulink.AliasTypeobject namedmyInt。In this case, becauseint_Tandint32_Trepresent a 32-bit signed integer, setBaseTypetoint32

    myInt = Simulink.AliasType('int32')

  3. Configure the same data type replacement forint32_Tandint_T

Note

Many-to-one data type replacement does not support thechar(char_T) built-in data type. Usecharonly in one-to-one data type replacements.

Many-to-one data type replacement is not supported forSimulink Coderdata types of different sizes.

Define Abstract Numeric Types and Rename Types

This model shows user-defined types, consisting of numeric and alias types. Numeric types allow you to define abstract numeric types, which is particularly useful for fixed-point types. Alias types allow you to rename types, which allows you create a relationship for types.

Explore Example Model

Open the example model and configure it to show the generated names of blocks.

load_system('UserDefinedDataTypes') set_param('UserDefinedDataTypes','HideAutomaticNames','off') open_system('UserDefinedDataTypes')

Key Features of User-Defined Types

  • Displayed and propagated on signal lines

  • Used to parameterize a model by type (e.g., In1 specifies itsOutput data typeasENG_SPEED)

  • Types with a common ancestor can be mixed, whereby the common ancestor is propagated (e.g., output of Sum1)

  • Intrinsically supported by the Simulink Model Explorer

  • Include an optional header file attribute that is ideal for importing legacy types (ignored for GRT targets)

  • Types used in the generated code (ignored for GRT targets)

Instructions

  1. Inspect the user-defined types in the Model Explorer by double-clicking the first yellow button below.

  2. Inspect the replacement data type mapping by double-clicking the second yellow button below.

  3. Compile the diagram to display the types in this model (Debug > Update Model > Update Model orCtrl+D).

  4. Generate code with the blue button below and inspect model files to see how user-defined types appear in the generated code.

  5. Modify the attributes ofENG_SPEEDandENG_SPEED_OFFSETand repeat steps 1-4.

Notes

  • User-defined types are a feature of Simulink that facilitate parameterization of the data types in a model. Embedded Coder preserves alias data type names (e.g.,ENG_SPEED) in the generated code, whereas Simulink Coder implements user-defined types as their base type (e.g.,real32_T).

  • Embedded Coder also enables you to replace the built-in data types with user-defined data types in the generated code.

Control Names of Structure Types

To control the names of the standard structures thatSimulink Codercreates by default to store data (model_Pfor parameter data, for example), useConfiguration Parameters>Code Generation>Identifiers>Global typesto specify a naming rule. For more information, seeIdentifier Format Control

When you use nonvirtual buses and parameter structures to aggregate signals and block parameters into a custom structure in the generated code, control the name of the structure type by creating aSimulink.Busobject. For more information, seeOrganize Data into Structures in Generated Code

Generate Code That Reuses Data Types From External Code

To generate code that reuses a data type definition from your external C code, specify the data scope of the corresponding data type object or enumeration in Simulink asImported。With this setting, the generated code includes (#include) the definition from your code. For more information about controlling the file placement of a custom data type, seeControl File Placement of Custom Data Types

Instead of creating individual data type objects and enumerated types, and then configuring them, consider creating the objects and types by using theSimulink.importExternalCTypesfunction. By default, the function configures the new objects and types so that the generated code imports (reuses) the type definitions from your code. You can then use the objects and types to set data types in a model and to configure data type replacements. For more information, seeSimulink.importExternalCTypesandExchange Structured and Enumerated Data Between Generated and External Code

Create Data Type Alias in the Generated Code

This example shows how to configure the generated code to use a data type name (typedef) that you specify.

Export Type Definition

When you integrate code generated from a model with code from other sources, your model code can create an exportedtypedefstatement. Therefore, all of the integrated code can use the type. This example shows how to export the definition of a data type to a generated header file.

Create aSimulink.AliasTypeobject namedmySingleAliasthat acts as an alias for the built-in data typesingle

mySingleAlias = Simulink.AliasType('single');

Configure the object to export its definition to a header file calledmyHdrFile.h

mySingleAlias.DataScope ='Exported'; mySingleAlias.HeaderFile ='myHdrFile.h';

Open the modelrtwdemo_configinterface

open_system('rtwdemo_configinterface')

Configure the model to show the generated names of blocks.

set_param('rtwdemo_configinterface','HideAutomaticNames','off')

On theModelingtab, clickModel Data Editor

In the model, select the Inport block labeledIn1

Use theData Typecolumn to set the data type tomySingleAlias

set_param('rtwdemo_configinterface/In1','OutDataTypeStr','mySingleAlias')

ConfigureIn1to use default storage.

In theC Codetab, selectCode Interface > Default Code Mappings

In the Code Mappings editor, underInports and Outports, select categoryInports。Set the default storage class toDefault

On theInportstab, setStorage ClasstoModel default

cm = coder.mapping.api.get('rtwdemo_configinterface'); setDataDefault(cm,'Inports','StorageClass','Default'); setInport(cm,'In1','StorageClass','Model default');

Generate code from the model.

slbuild('rtwdemo_configinterface')
### Starting build procedure for: rtwdemo_configinterface ### Successful completion of code generation for: rtwdemo_configinterface Build Summary Top model targets built: Model Action Rebuild Reason ============================================================================================ rtwdemo_configinterface Code generated. Code generation information file does not exist. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 16.704s

In the code generation report, view the filertwdemo_configinterface_types.h。The code creates a#includedirective for the generated filemyHdrFile.h

file = fullfile('rtwdemo_configinterface_ert_rtw','rtwdemo_configinterface_types.h'); rtwdemodbtype(file,'#include "myHdrFile.h"',。..'#include "myHdrFile.h"',1,1)
#include "myHdrFile.h"

View the filemyHdrFile.h。The code uses the identifiermySingleAliasas an alias for the data typereal32_T。By default, generated code represents the Simulink data typesingleby using the identifierreal32_T

The code also provides a macro guard of the formRTW_HEADER_filename_h_。When you export a data type definition to integrate generated code with code from other sources, you can use macro guards of this form to prevent unintentional identifier clashes.

file = fullfile('slprj','ert','_sharedutils','myHdrFile.h'); rtwdemodbtype(file,“#如果未定义RTW_HEADER_myHdrFile_h_',。..' * File trailer for generated code.',1,0)
#ifndef RTW_HEADER_myHdrFile_h_ #define RTW_HEADER_myHdrFile_h_ #include "rtwtypes.h" typedef real32_T mySingleAlias; typedef creal32_T cmySingleAlias; #endif /* RTW_HEADER_myHdrFile_h_ */ /*

View the filertwdemo_configinterface.h。The code uses the data type aliasmySingleAliasto define the structure fieldinput1, which corresponds to the Inport block labeledIn1

file = fullfile('rtwdemo_configinterface_ert_rtw','rtwdemo_configinterface.h'); rtwdemodbtype(file,。..'/* External inputs (root inport signals with default storage) */',。..'} ExtU_rtwdemo_configinterface_T;',1,1)
/* External inputs (root inport signals with default storage) */ typedef struct { mySingleAlias input1; /* '/In1' */ MYTYPE input2; /* '/In2' */ MYTYPE input3; /* '/In3' */ MYTYPE input4; /* '/In4' */ } ExtU_rtwdemo_configinterface_T;

Import Type Definition

When you integrate code generated from a model with code from other sources, to avoid redundanttypedefstatements, you can import a data type definition from the external code. This example shows how to import your own definition of a data type from a header file that you create.

Use a text editor to create a header file to import. Name the fileex_myImportedHdrFile.h。把它放在你的工作文件夹。复制下ing code into the file.

#ifndef HEADER_myImportedHdrFile_h_ #define HEADER_myImportedHdrFile_h_ typedef float myTypeAlias; #endif

The code uses the identifiermyTypeAliasto create an alias for the data typefloat。The code also uses a macro guard of the formHEADER_filename_h。When you import a data type definition to integrate generated code with code from other sources, you can use macro guards of this form to prevent unintentional identifier clashes.

At the command prompt, create aSimulink.AliasTypeobject namedmyTypeAliasthat creates an alias for the built-in typesingle。The Simulink data typesinglecorresponds to the C data typefloat

myTypeAlias = Simulink.AliasType('single')
myTypeAlias = AliasType with properties: Description: '' DataScope: 'Auto' HeaderFile: '' BaseType: 'single'

Configure the object so that generated code imports the type definition from the header fileex_myImportedHdrFile.h

myTypeAlias.DataScope ='Imported'; myTypeAlias.HeaderFile ='ex_myImportedHdrFile.h';

Open the modelrtwdemo_configinterface

open_system('rtwdemo_configinterface')

On theModelingtab, clickModel Data Editor

In the model, select the Inport block labeledIn1

Use theData Typecolumn to set the data type tomyTypeAlias

set_param('rtwdemo_configinterface/In1','OutDataTypeStr','myTypeAlias')

Generate code from the model.

slbuild('rtwdemo_configinterface')
### Starting build procedure for: rtwdemo_configinterface ### Successful completion of code generation for: rtwdemo_configinterface Build Summary Top model targets built: Model Action Rebuild Reason =========================================================================== rtwdemo_configinterface Code generated. Generated code was out of date. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 12.401s

In the code generation report, view the filertwdemo_configinterface_types.h。The code creates a#includedirective for your header fileex_myImportedHdrFile.h

file = fullfile('rtwdemo_configinterface_ert_rtw','rtwdemo_configinterface_types.h'); rtwdemodbtype(file,'#include "ex_myImportedHdrFile.h',。..'/* Forward declaration for rtModel */',1,0)
# include # include“ex_myImportedHdrFile.h MYTYPE。h" #ifndef DEFINED_TYPEDEF_FOR_Table1_Type_ #define DEFINED_TYPEDEF_FOR_Table1_Type_ typedef struct { MYTYPE BP[11]; MYTYPE Table[11]; } Table1_Type; #endif #ifndef DEFINED_TYPEDEF_FOR_Table2_Type_ #define DEFINED_TYPEDEF_FOR_Table2_Type_ typedef struct { MYTYPE BP1[3]; MYTYPE BP2[3]; MYTYPE Table[9]; } Table2_Type; #endif #endif /* RTW_HEADER_rtwdemo_configinterface_types_h_ */ /* * File trailer for generated code. * * [EOF] */

View the filertwdemo_configinterface.h。The code uses the data type aliasmyTypeAliasto define the structure fieldinput1, which corresponds to the Inport block labeledIn1

file = fullfile('rtwdemo_configinterface_ert_rtw','rtwdemo_configinterface.h'); rtwdemodbtype(file,。..'/* External inputs (root inport signals with default storage) */',。..'} ExtU_rtwdemo_configinterface_T;',1,1)
/* External inputs (root inport signals with default storage) */ typedef struct { myTypeAlias input1; /* '/In1' */ MYTYPE input2; /* '/In2' */ MYTYPE input3; /* '/In3' */ MYTYPE input4; /* '/In4' */ } ExtU_rtwdemo_configinterface_T;

Display Base Data Types and Aliases on Model Diagram

When you display signal data types on the model diagram, you can choose to display aliases (such asmyTypeAlias) and base data types (such asint16). To display aliases, on theDebugtab, selectInformation Overlays>Alias Data Types。To display the base types, selectInformation Overlays>Base Data Types。For more information, seePort Data Types

Create a Named Fixed-Point Data Type in the Generated Code

This example shows how to create and name a fixed-point data type in generated code. You can use the name of the type to specify parameter and signal data types throughout a model and in generated code.

The example modelrtwdemo_fixpt1uses fixed-point data types. So that you can more easily see the fixed-point data type in the generated code, in this example, you create aSimulink.Parameterobject that appears in the code as a global variable.

Create aSimulink.AliasTypeobject that defines a fixed-point data type. Name the objectmyFixType。The generated code uses the name of the object as a data type.

myFixType = Simulink.AliasType('fixdt(1,16,4)');

Open the modelrtwdemo_fixpt1

open_system('rtwdemo_fixpt1')

Configure the model to show the generated names of the blocks.

set_param('rtwdemo_fixpt1','HideAutomaticNames','off')

On theModelingtab, clickModel Data Editor

In the Model Data Editor, select theParameterstab.

In the model, select the Gain block.

In the Model Data Editor, for the row that represents theGainparameter of the Gain block, in theValuecolumn, specifymyParam

Click the action button (with three vertical dots) next to the parameter value. SelectCreate

In theCreate New Datadialog box, setValuetoSimulink.Parameter(8)。In this example, for more easily readable code, you set the parameter value to 8 instead of -3.2. ClickCreate。ASimulink.Parameterobject namedmyParamappears in the base workspace. The object stores the real-world value8, which the Gain block uses for the value of theGainparameter.

In theSimulink.Parameterproperty dialog box, setStorage classtoExportedGlobal。ClickOK。With this setting,myParamappears in the generated code as a separate global variable.

In the Model Data Editor, use theData Typecolumn to set the data type of theGainparameter of the Gain block tomyFixType

On theSignalstab, use theData Typecolumn to set the data type of the Gain block output tomyFixType

Use theData Typecolumn to set the data type of theConversionblock output tomyFixType

Alternatively, you can use these commands at the command prompt to configure the blocks and create the object:

set_param('rtwdemo_fixpt1/Gain','Gain','myParam','OutDataTypeStr','myFixType',。..'ParamDataTypeStr','myFixType') myParam = Simulink.Parameter(8); myParam.StorageClass ='ExportedGlobal'; set_param('rtwdemo_fixpt1/Conversion','OutDataTypeStr','myFixType')

In the model, setConfiguration Parameters > Code Generation > System target filetoert.tlc。With this setting, the code generator honors data type aliases such asmyFixType

set_param('rtwdemo_fixpt1','SystemTargetFile','ert.tlc')

Select the configuration parameterGenerate code only

set_param('rtwdemo_fixpt1','GenCodeOnly','on')

Generate code from the model.

slbuild('rtwdemo_fixpt1')
### Starting build procedure for: rtwdemo_fixpt1 ### Successful completion of code generation for: rtwdemo_fixpt1 Build Summary Top model targets built: Model Action Rebuild Reason =================================================================================== rtwdemo_fixpt1 Code generated. Code generation information file does not exist. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 20.049s

In the code generation report, view the filertwdemo_fixpt1_types.h。The code defines the typemyFixTypebased on an integer type of the specified word length (16).

file = fullfile('rtwdemo_fixpt1_ert_rtw','rtwdemo_fixpt1_types.h'); rtwdemodbtype(file,“#如果未定义DEFINED_TYPEDEF_FOR_myFixType_',。..'/* Forward declaration for rtModel */',1,0)
#ifndef DEFINED_TYPEDEF_FOR_myFixType_ #define DEFINED_TYPEDEF_FOR_myFixType_ typedef int16_T myFixType; typedef cint16_T cmyFixType; #endif

View the filertwdemo_fixpt1.c。The code uses the typemyFixType, which is an alias of the integer typeint16, to define the variablemyParam

file = fullfile('rtwdemo_fixpt1_ert_rtw','rtwdemo_fixpt1.c'); rtwdemodbtype(file,'myFixType myParam = 128;','myFixType myParam = 128;',1,1)
myFixType myParam = 128; /* Variable: myParam

The stored integer value128ofmyParamis not the same as the real-world value8because of the scaling that the fixed-point data typemyFixTypespecifies. For more information, seeScaling(Fixed-Point Designer)in the Fixed-Point Designer documentation.

The line of code that represents the Gain block applies a right bit shift corresponding to the fraction length specified bymyFixType

rtwdemodbtype(file,。..'rtwdemo_fixpt1_Y.Out1 = (myFixType)((myParam * rtb_Conversion) >> 4);',。..'rtwdemo_fixpt1_Y.Out1 = (myFixType)((myParam * rtb_Conversion) >> 4);',1,1)
rtwdemo_fixpt1_Y.Out1 = (myFixType)((myParam * rtb_Conversion) >> 4);

Rename Data Type Object

To rename a data type object such asSimulink.AliasTypeorSimulink.Busafter you create it (for example, to rename an alias when coding standards change or when you encounter a naming conflict), you can allow Simulink to rename the object and correct all of the references to the object that appear in a model or models. In the Model Explorer, right-click the variable and selectRename All。For more information, seeRename Variables

Display Signal Data Types on Block Diagram

For readability, you can display signal data types directly on a block diagram. When you use custom names for primitive data types, you can choose to display the custom name (the alias), the underlying primitive, or both. SeePort Data Types

Data Type Replacement Limitations

  • You cannot configure the generated code to use these custom C data types:

    • Array types

    • Pointer types

    • constorvolatiletypes

  • You cannot configure the generated code to use generic C primitive types such asintandshort

When you setData type replacementtoUse C data types with fixed-width integers, these limitations apply:

  • TheSpecify custom data type namesconfiguration parameter is not supported.

  • Word size values for production integer data types must include the values 8, 16, and 32 bits and each value can only be 8, 16, 32, or 64 bits. IfProdEqTargetis set to'off', the same requirement applies to test hardware integer data types.

  • You cannot generate AUTOSAR code.

  • You cannot run external mode simulations that use TCP/IP or serial communication. Run external mode simulations that use XCP communication.

  • You cannot generate code for third-party hardware workflows that use Embedded Coder®support packages.

  • In generated C++ code, statements that include the header filesstdint.handstdbool.hviolate MISRA™ C++:2008 rule 18-0-1.

  • If the model includes Simscape™ blocks, some of the generated source files might contain#include "rtwtypes.h"。Generated code from Simscape blocks is not intended for production deployment. The build process can compile the generated code because the code generator creates artwtypes.hfile for continuous-time models.

When you setData type replacementtoUse coder typedefsand select theSpecify custom data type namesconfiguration parameter, these limitations apply:

  • Data type replacement does not support multiple levels of mapping. Each replacement data type name maps directly to one or more built-in data types.

  • Data type replacement is not supported for simulation target code generation for referenced models.

  • If you select theClassic call interfaceconfiguration parameter for your model, data type replacement is not supported.

  • Code generation performs data type replacements while generating。c,。cpp, and。hfiles. Code generation places these files in build folders (including top and referenced model build folders) and in the_sharedutilsfolder.Exceptionsare as follows:

    rtwtypes.h
    multiword_types.h
    model_reference_types.h
    builtin_typeid_types.h
    model_sf.cor。cpp(ERT S-function wrapper)
    model_dt.h(C header file supporting external mode)
    model_capi.cor。cpp
    model_capi.h
  • Data type replacement is not supported for complex data types.

  • Many-to-one data type replacement is not supported for thechardata type. Attempting to usecharas part of a many-to-one mapping to a custom data type represents a violation of the MISRA C™ specification. For example, if you mapchar(char_T) and eitherint8(int8_T) oruint8(uint8_T) to the same replacement type, the result is a MISRA C violation. If you try to generate C++ code, the code generator makes invalid implicit type casts, resulting in compile-time errors. Usecharonly in one-to-one data type replacements.

    Many-to-one data type replacement is not supported forSimulink Coderdata types of different sizes. For more information, seeReplace Implementation-Dependent Types with the Same Type Name

  • For ERT S-functions, replace thebooleandata type with only an 8-bit integer,int8, oruint8

  • Set theDataScope财产的Simulink.AliasTypeobject toAuto(default) orImported

Related Topics