Documentation

Generate Shared Utility Code

何时生成共享的实用代码

模型中的块可能需要共同的功能才能实现其算法。考虑将此功能模块化为独立支持或辅助功能。金宝app这种方法比在每个块实例的功能上添加代码更有效。要决定使用库或共享实用程序,请考虑:

  • 当静态定义功能时,可以将多个呼叫者带入库中的软件包函数。也就是说,在使用代码生成器为模型生成代码之前,函数源代码存在于文件中。

  • Package functions that can have multiple callers as shared utilities (produced during code generation) when the functions cannot be defined statically. For example, several model- and block-specific properties specify which functions are used and their behavior. Also, these properties determine type definitions (for example,Typedef) in shared utility header files. The number of possible combinations of properties that determine unique behavior make it impractical to define statically the possible function files before code generation.

Control Naming of Generated Functions

You can customize the names of the generated functions for shared utilities by defining the custom identifiers in theShared utilities范围。A macro for the conditional checksum$Cis required in the symbol format forShared utilities。You can control the location of the token$C。要自定义生成的校验和的长度,请使用Shared checksum length范围。Increase the length of the checksum to reduce the probability of clashes.

这个例子展示了自定义函数的names of generated code for shared utility functions.

  1. At the command prompt, typertwdemo_crlmath打开模型。

  2. Select模拟>模型配置参数

  3. In theCode Generation>Interface窗格,更改价值Shared code placementtoShared location

  4. In theCode Generation>符号pane, specify the format ofShared utilitiesasmymodel_$N$C。You can customize this format with any string. However, token$Cis required.

  5. 改变Shared checksum lengthto5

  6. PressCtrl+B

    代码生成过程完成后,出现代码生成报告。

  7. In the report, on the left navigation pane, you can view the generated files for shared utilities under theShared files文件夹。

Control Placement of Shared Utility Code

共享实用程序代码的控制放置与Shared code placementoption in theConfiguration Parameters>Code Generation>Interfacepane. The default option value isAuto。For this setting, the code generator places required code for fixed-point and other utilities in themodel。cfile, themodel.cppfile, or a separate file in the build folder (for example,vdp_grt_rtw)如果模型不包含现有的共享实用程序代码或以下块之一:

  • 模型blocks

  • Simulink Functionblocks

  • Function Callerblocks

  • 呼叫从状态流或金宝appMATLABFunctionblocks

  • Stateflow graphical functions when you select the导出图表级功能范围

If a model contains one or more of the preceding blocks, the code generator creates and uses a shared utilities folder withinslprj。共享实用程序文件夹的命名约定是slprj/目标/_ sharedutils目标issimfor simulations with模型blocks or the name of the system target file for code generation.

slprj/sim/_sharedutils%文件夹,与grt.tlc stf stf slprj/ert/_sharedutils%文件夹一起使用的仿真SLPRJ/grt/_sharedutils%文件夹,用eRT.tlc stf stf stf stf stf slprj/mytarget/mytarget/_sharedutils%folders in mytarget.trc starget.trc starget.trc St.

强迫模型构建以使用slprjfolder for shared utility generation, even when the current model does not contain existing shared utility code or one of the preceding blocks, set theShared code placement选项Shared location。The code generator places utilities under theslprj文件夹而不是在普通构建文件夹中。当您手动组合来自多个模型的代码时,此设置很有用,因为它可以防止模型之间的符号碰撞。

RTWTYPES.H共享实用程序代码的控制放置

生成的rtwtypes.hheader file provides fundamental type definitions,#define陈述和枚举。有关更多信息,请参阅rtwtypes.h

Control placement of rtwtypes.h file by selecting whether the build process uses the shared utilities folder. If the model build uses a shared utilities folder, the build process placesrtwtypes.hinslprj/目标/_ sharedutils。Otherwise, the software placesrtwtypes.hinmodel_目标_rtw

将模型添加到模型层次结构或更改层次结构中的现有模型可能会导致对共享的更新rtwtypes.hfile during code generation. If updates occur, recompile and, depending on your development process, reverify previously generated code. To minimize updates to thertwtypes.h文件,在“配置参数”对话框中进行以下更改:

  • On theInterface窗格,选择Support: complex numberseven if the model does not currently use complex data types. Selecting this option protects against a future requirement to add support for complex data types when integrating code.

  • Clear theConfiguration Parameters>Code Generation>Interface>高级参数>金宝app支持非插入的s功能option. If you use noninlined S-functions in the model, this option generates an error.

  • Clear theConfiguration Parameters>Code Generation>Interface>高级参数>Classic call interfaceoption. Disables use of the GRT interface.

Avoid Duplicate Header Files for Exported Data

导出的标头文件出现在共享实用程序文件夹中时:

  • You control the file placement of declarations for signals, parameters, and states by applying storage classes and custom storage classes.

  • The code generator places utility code in a shared location.

例如,您可以通过以下方式指定一个数据的标题文件:

  • TheCode Generationtab in a Signal Properties dialog box.

  • TheHeaderFile数据对象的属性。数据对象是类的对象Simulink.SignalandSimulink.Parameter

If you want the declaration to appear in the filemodel。h,这是未指定的标头文件名的最佳做法。默认情况下,代码生成器将数据声明放在model。h

If you specifymodel。has the header file name, and if the code generator places utility code in a shared location, you cannot generate code from the model. The code generator cannot create the filemodel。hin both the model build folder and the shared utility folder.

Reduce Shared Utility Code Generation with Incremental Builds

You can specify that the model build generates C source files in a shared utilities folder. SeeCustomize Build to Use Shared Utility Code(Simulink Coder). These files include C source files that contain function definitions and header files that contain macro definitions. For this discussion, the term functions means functions and macros.

同一模型中的块和不同模型中的块在使用模型参考时可以使用共享函数,或者从同一启动构建文件夹中构建多个独立模型时。代码生成器仅针对第一次触发代码生成的块生成一次给定函数的代码。由于产品确定了为后续块生成功能代码的要求,因此它执行文件存在检查。如果文件存在,则模型构建不会再生该函数。共享的实用代码机制要求给定功能和文件名表示相同的功能行为,无论哪个块或模型生成该功能。满足这一要求:

  • 模型properties that determine function behavior contribute to the shared utility checksum or determine the function and file name.

  • Block properties that determine the function behavior also determine the function and file name.

在编译期间,共享实用程序文件夹的MakeFile规则仅选择新C文件的汇编,然后将对象文件递增到共享实用程序库中,rtwshared.lib, orrtwshared.a。Incremental compilation also occurs.

管理共享的实用代码校验和

When a model configuration setsConfiguration Parameters>Code Generation>Interface>Shared code placementasShared locationor when the model contains模型块,代码生成器将共享代码放置在共享的实用程序文件夹中。构建过程为共享代码生成了代码生成配置的共享实用程序检查。

在随后的代码生成期间,如果校验和文件slprj/目标/_ sharedutils/checksummap.mat相对于当前文件夹,代码生成器读取该文件。代码生成器验证您正在构建的当前模型具有与共享实用程序模型属性校验和匹配的配置属性。如果在定义的属性之间发生不匹配checksummap.matand the current model properties, you see an error. Use the error message to manage the checksum (for example, diagnose and resolve the configuration issues with the current model).

有关更多信息,请参阅Reduce Shared Utility Code Generation with Incremental Builds(Simulink Coder).

查看共享实用程序检查表

查看有助于校验和的属性值很有帮助。此示例使用rtwdemo_lct_start_term.slx模型。To load thechecksum.matfile into MATLAB®and view the目标InfoStructthat defines the checksum-related properties:

  1. Open thertwdemo_lct_start_term.slx模型。在命令窗口中,键入:

    rtwdemo_lct_start_term
  2. Create and move to a new working folder.

    mkdir C:\Temp\demo cd C:\Temp\demo
  3. 将模型的副本保存在文件夹中。

  4. 通过使用金宝app>Code>C/C ++代码>Build Model命令。该模型已经设置为生产共享实用程序。

  5. Move to the_sharedutilsfolder created by the build process.

    cd C:\Temp\demo\slprj\grt\_sharedutils
  6. 加载checksummap.matfile into MATLAB.

    负载checksummap
  7. Display the contents ofhashTbl.targetInfoStruct并检查与校验和相关的属性值。

    hashTbl.targetInfoStruct

For this example, the Command Window displayshashTbl.targetInfoStructfor the shared utilities that you generated from the model:

ShiftRightIntArith: 'on' ProdShiftRightIntArith: 'on' Endianess: 'LittleEndian' ProdEndianess: 'LittleEndian' wordlengths: '8,16,32,32,64,32,64,64,64,64' Prodwordlengths: '8,16,32,32,64,32,64,64,64,64' TargetWordSize: '64' ProdWordSize: '64' TargetHWDeviceType: 'Custom Processor->MATLAB Host Computer' ProdHWDeviceType: 'Intel->x86-64 (Windows64)' TargetIntDivRoundTo: 'Zero' ProdIntDivRoundTo: 'Zero' tmfName: '' toolchainName: '' computer: 'PCWIN64' UseDivisionForNetSlopeComputation: 'off' PurelyIntegerCode: 'off' PortableWordSizes: 'off' SupportNonInlinedSFcns: '' RTWReplacementTypes: '' MaxIdInt8: 'MAX_int8_T' MinIdInt8: 'MIN_int8_T' MaxIdUint8: 'MAX_uint8_T' MaxIdInt16: 'MAX_int16_T' MinIdInt16: 'MIN_int16_T' MaxIdUint16: 'MAX_uint16_T' MaxIdInt32: 'MAX_int32_T' MinIdInt32: 'MIN_int32_T' MaxIdUint32: 'MAX_uint32_T' BooleanTrueId: 'true' BooleanFalseId: 'false' TypeLimitIdReplacementHeaderFile: '' SharedCodeRepository: '' TargetLang: 'C' PreserveExternInFcnDecls: 'on' EnableSignedRightShifts: 'on' EnableSignedLeftShifts: 'on' TflName: 'None' TflCheckSum: [1.6615e+09 521991164 2.2147e+09 1.7704e+09] UtilMemSecName: 'Default' CodeCoverageChecksum: [3.6498e+09 78774415 2.5508e+09 2.1183e+09] TargetLargestAtomicInteger: 'Char' TargetLargestAtomicFloat: 'None' ProdLargestAtomicInteger: 'Char' ProdLargestAtomicFloat: 'Float' LongLongMode: 'on' ProdLongLongMode: 'off' CollapseNonTrivialExpressions: 'false'

将共享实用程序校验和与配置参数相关联

检查目标InfoStructhash table from the shared utility model. Some key-value pairs relate directly to a model property. Other pairs relate to groups of properties.

The following table describes the key-value pairs.

Key Names 模型Properties
ShiftRightIntArith TargetShiftRightIntArith
ProdShiftRightIntArith ProdShiftRightIntArith
Endianess TargetEndianess
Prodendianess Prodendianess
wordlengths TargetBitpercharch,TargetBitPerShort,TargetBitPerInt,TargetBitPerLong,TargetBitPerLongLong,targetBitperfloat,TargetBitPerDouble,TargetBitPerPointer
Prodwordlengths ProdBitPerChar,Prodbitpershort,质地,ProdBitPerLong,ProdBitPerLongLong,ProdBitPerFloat,ProdBitPerDouble,ProdBitPerPointer
TargetWordSize TargetWordSize
prodswordsize prodswordsize
TargetHWDeviceType TargetHWDeviceType
prodhwdeviceType prodhwdeviceType
TargetIntDivRoundTo TargetIntDivRoundTo
ProdIntDivRoundTo ProdIntDivRoundTo
tmfName Templatemakefile
toolchainName 工具链
计算机 return value of the计算机命令
underivisionfornetslopecomponunt underivisionfornetslopecomponunt
PurelyIntegerCode PurelyIntegerCode
PortableWordSizes PortableWordSizes
SupportNonInlinedSFcns SupportNonInlinedSFcns
RTWReplacementTypes EnableUserReplacementTypes,替换类型
maxidint8 maxidint8
Minidint8 Minidint8
maxiduint8 maxiduint8
MaxIdInt16 MaxIdInt16
MinIdInt16 MinIdInt16
MaxIdUint16 MaxIdUint16
MaxIdInt32 MaxIdInt32
Minidint32 Minidint32
MaxIdUint32 MaxIdUint32
布鲁特里德 布鲁特里德
BooleanFalseId BooleanFalseId
TypeLimitIdReplacementHeaderFile TypeLimitIdReplacementHeaderFile
SharedCodeRepository 保留(仅内部用途)
TargetLang TargetLang
保存ExternInfcndecls 保存ExternInfcndecls
启用符号缩放 启用符号缩放
启用signedleftshifts 启用signedleftshifts
TflName CodeReplacementLibrary
tflchecksum 保留(仅内部用途)
UtilMemSecName MemSecFuncSharedUtil,memsecpackage
CodeCoveragageChecksum 保留(仅内部用途)
TargetLargestAtomicInteger TargetLargestAtomicInteger
靶标的float 靶标的float
ProdLargestAtomicInteger ProdLargestAtomicInteger
ProdLargestAtomicFloat ProdLargestAtomicFloat
LonglongMode TargetLongLongMode
prodlonglongmode prodlonglongmode
CollapseNonTrivialExpressions 保留(仅内部用途)

Related Topics

Was this topic helpful?