Documentation

Finely Control Data Representation by Writing TLC Code for a Storage Class

If creating your own storage class by using the properties in an Embedded Coder Dictionary or the Custom Storage Class Designer does not meet your requirements for controlling data representation in the generated code, you can write TLC code that explicitly controls the effect that a storage class has on the code. For example, to create a storage class that yields arbitrarily nested structures, you must write TLC code. In the Custom Storage Class Designer, these advanced storage classes haveTypeset toOther. You cannot create such a storage class in an Embedded Coder Dictionary, so you cannot use the storage class as a default code generation setting in the Code Mapping Editor.

For an example, seeGenerate Code That Dereferences Data from a Literal Memory Address. For general information about TLC code, seeWhy Use the Target Language Compiler?(金宝app仿真软件编码器)。

Create Custom Attributes Class for Storage Class

As described inAllow Users of Storage Class to Specify Property Value, instance-specific properties enable users of a storage class to control the effect that the storage class has on each data item. For example, the built-in storage classExportToFilehas several instance-specific properties such asHeader fileandDefinition file.

When you create a storage class withTypeset toOther, to add your own instance-specific properties that are not built into the Custom Storage Class Designer, create acustom attributes classfor your package. A custom attributes class is a MATLAB®class that you create as a subclass ofSimulink.CustomStorageClassAttributes. Each property that you add to your custom attributes class appears to the user of the storage class as an instance-specific property.

To create your custom attributes class, seeDefine Data Classes(Simulink).

Write TLC Code for Storage Class

To control the effect of your storage class, write TLC code that specifies the code to generate for each data item.

  1. In your package folder (for example,+myPackage), create atlcfolder.

  2. Copy a TLC template such asTEMPLATE_v1.tlcfrom the foldermatlabroot/toolbox/rtw/targets/ecoder/csc_templates(open) into yourtlcfolder.

  3. Write your TLC code, following the comments in the template file. The comments describe how to specify, for example, how the generated code declares, defines, and accesses (by value or by reference) each data item.

Create Storage Class by Using Custom Storage Class Designer

To create your storage class in your package, you open the Custom Storage Class Designer in an advanced mode.

  1. At the command prompt, enter:

    cscdesigner-advanced
  2. Select your package and create a storage class.

  3. For the storage class, setTypetoOther. In theOther Attributespane, specify the name of your TLC file and the name of your custom attributes class.

  4. Set the properties on theOther Attributespane.

    • Is grouped: Select this option if you intend to combine multiple data items into a single entity in the generated code. For example, the built-in storage classesBitFieldandStructare grouped because they can aggregate multiple data items into a single structure variable.

    • TLC file name: Enter the name of your TLC file. The Custom Storage Class Designer assumes that the file exists in the packagetlcfolder, so specify only the name of the file, not the file path.

    • CSC attributes class name: (optional) If you created a custom attributes class, enter the full name of the class, including the package name. For example, specifymyPackage.myCustomAttsClass. For more information, seeCreate Custom Attributes Class for Storage Class.

  5. On theGeneralandCommentspanes, specify values for the remaining properties.

Related Topics