Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Workshop Embedded Coder   

Designing Custom Storage Classes and Memory Sections

Using the Custom Storage Class Designer

The Custom Storage Class Designer (cscdesigner) is a tool for creating and managing custom storage classes and memory sections. You can use the Custom Storage Class Designer to:

To open the Custom Storage Class Designer, type the following command at the MATLAB prompt:

cscdesigner

When first opened, the Custom Storage Class Designer scans all data class packages on the MATLAB path to detect packages that have a CSC registration file. A message is displayed while scanning proceeds. When the scan is complete, the Custom Storage Class Designer window appears:

The Custom Storage Class Designer window is divided into several panels:

Selecting a Data Class Package

A CSC or memory section definition or reference is uniquely associated with a Simulink data class package. The link between the definition/reference and the package is formed when a CSC registration file (csc_registration.m) is located in the package directory.

You never need to search for or edit a CSC registration file directly: the Custom Storage Class Designer locates all available CSC registration files. The Select package menu contains names of all data class packages that have a CSC registration file on the MATLAB search path. At least one such package, the Simulink package, is always present.

When you select a package, the CSCs and memory section definitions belonging to the package are loaded into memory and their names are displayed in the scrolling list in the Custom storage class panel. The name and location of the CSC registration file for the package is displayed in the Filename panel.

If you select a user-defined package, by default you can use the Custom Storage Class Designer to edit its custom storage classes and memory sections. If you select a built-in package, by default you cannot edit its custom storage classes or memory sections. See Custom Storage Class Implementation for more information.

Selecting and Editing CSCs, Memory Sections, and References

The Custom Storage Class / Memory Section panel lets you select, view, and (if the CSC is writable) edit CSC and memory section definitions and references. In the next figure and the subsequent examples, the selected package is mypkg. Instructions for creating a user-defined package like mypkg appear in Creating Packages that Support CSC Definitions.

The list at the top of the panel displays the definitions/references for the currently selected package. To select a definition/reference for viewing and editing, click on the desired list entry. The properties of the selected definition/reference appear in the area below the list. The number and type of properties vary for different types of CSC and memory section definitions. See:

The buttons to the right of the list perform these functions, which are common to both custom storage classes and memory definitions:

For example, if you click New, a new custom storage class is created with a default name:

You can now rename the new class by typing the desired name into the Name field, and set other fields as needed. The changes take effect when you click Apply or OK. For example, you could set values for the new custom storage class as follows:

Saving Your Definitions

After you have created or edited a CSC or memory section definition or reference, you must save the changes to the CSC registration file. To do this, click Save in the Filename panel. When you click Save, the current CSC and memory section definitions that are in memory are validated, and the definitions are written out.

If errors occur, they are reported in the Validation result panel. The definitions are saved whether or not errors exist. However, you should correct any validation errors and resave your definitions. Trying to use definitions that were saved with validation errors can cause additional errors. Such problems can occur even it you do not try to use the specific parts of the definition that contain the validation errors, making the problems difficult to diagnose.

Restarting MATLAB After Changing Definitions

If you add, change, or delete custom storage class or memory section definitions for any user-defined class, and objects of that class already exist, you must restart MATLAB to put the changed definitions into effect and eliminate obsolete objects. A message warning you to restart MATLAB appears when you save the changed definitions. This warning message does not affect the success of the save operation itself.

Editing Custom Storage Class Properties

To view and edit the properties of a CSC, click the Custom Storage Class tab in the Custom Storage Class / Memory Section panel. Then, select a CSC name from the Custom storage class definitions list.

The CSC properties are divided into several categories, selected by tabs. Selecting a class, and setting property values for that class, can change the available tabs, properties, and values. As you change property values, the effect on the generated code is immediately displayed in the Pseudocode preview panel. In most cases, you can define your CSCs quickly and easily by selecting the Pseudocode preview panel and using the Validate button frequently.

The property categories and corresponding tabs are as follows:

General

Properties in the General category are common to all CSCs. In the next figure and the subsequent examples, the selected custom storage class is ByteField. Instructions for creating a user-defined custom storage class like ByteField appear in Selecting and Editing CSCs, Memory Sections, and References.

Properties in the General category, and the possible values for each property, are as follows:

Comments.   The Comments panel lets you specify comments to be generated with definitions and declarations.

Comments must conform to the ANSI C standard (/*...*/). Use \n to specify a new line.

Properties in the Comments tab are as follows:

Structure Attributes

The Structure Attributes panel gives you detailed control over code generation for structs (including bitfields). The Structure Attributes tab is displayed for CSCs whose Type parameter is set to FlatStructure. The following figure shows the Structure Attributes panel.

Structure Attributes Panel

The Structure Attributes properties are as follows:

The following listing is the pseudocode preview corresponding to the Structure Attributes properties displayed in Structure Attributes Panel.

Header file:

No header file is specified. By default, data is
exported with the generated model.h file.


Type definition:

/* CSC type comment generated by default */

typedef struct aToken myTag {
   :
} myType;


Declaration:

/* CSC declaration comment generated by default */

extern myType MyStruct;


Definition:

/* CSC definition comment generated by default */

myType MyStruct = {...};

Validating CSC Definitions

To validate a CSC definition, select the definition on the Custom Storage Class panel and click Validate. The Custom Storage Class Designer then checks the definition for consistency. The Validation result panel displays any errors encountered when the selected CSC definition is validated. The next figure shows the Validation result panel with a typical error message:

Validation is also performed whenever CSC definitions are saved. In this case, all CSC definitions are validated. (See Saving Your Definitions.)

Using Custom Storage Class References

Any package can access and use custom storage classes that are defined in any other package, including both user-defined packages and predefined packages such as Simulink and mpt. Only one copy of the storage class exists, in the package that first defined it. Other packages refer to it by pointing to it in its original location. Thus any changes to the class, including changes to a predefined class in later MathWorks™ product releases, are immediately available in every referencing package.

To configure a package to use a custom storage class that is defined in another package:

  1. Type cscdesigner to launch the Custom Storage Class Designer. The relevant part of the designer window initially looks like this:

  2. Select the Custom Storage Class tab.

  3. Use Select Package to select the package in which you want to reference a class or section defined in some other package. The selected package must be writable.

  4. In the Custom storage class definitions pane, select the existing definition below which you want to insert the reference. For example:

  5. Click New Reference.

    A new reference with a default name and properties appears below the previously selected definition. The new reference is selected, and a Reference tab appears that shows the reference's initial properties. A typical appearance is:

  6. Use the Name field to enter a name for the new reference. The name must be unique in the importing package, but can duplicate the name in the source package. The name cannot be any TLC keyword. Violating this rule causes an error.

  7. Set Refer to custom storage class in package to specify the package that contains the custom storage class you want to reference.

  8. Set Custom storage class to reference to specify the custom storage class to be referenced. Trying to create a circular reference generates an error and leaves the package unchanged.

  9. Click OK or Apply to save the changes to memory. See Saving Your Definitions for information about saving changes permanently.

For example, the next figure shows the custom storage class ConstVolatile imported from the Simulink package into mypkg, and given the same name that it has in the source package. Any other name could have been used without affecting the properties of the storage class.

You can use Custom Storage Class Designer capabilities to copy, reorder, validate, and otherwise manage classes that have been added to a class by reference. However, you cannot change the underlying definitions. You can change a custom storage class only in the package where it was originally defined.

Changing Existing CSC References

To change an existing CSC reference, select it in the Custom storage class definitions pane. The Reference tab appears, showing the current properties of the reference. Make any needed changes, then click OK or Apply to save the changes to memory. See Saving Your Definitions for information about saving changes permanently.

Creating and Editing Memory Section Definitions

Memory section definitions add comments, qualifiers, and #pragma directives to generated symbol declarations. The Memory Section tab lets you create, view, edit, and verify memory section definitions. The steps for creating a memory section definition are essentially the same as for creating a custom storage class definition:

  1. Select a writable package in the Select package field.

  2. Select the Memory Section tab. In a new package, only a Default memory section initially appears.

  3. Select the existing memory section below which you want to create a new memory section.

  4. Click New.

    A new memory section definition with a default name appears below the selected memory section.

  5. Set the name and other properties of the memory section as needed.

  6. Click OK or Apply.

The next figure shows mypkg with a memory section called MyMemSect:

The Memory section definitions list lets you select a memory section definition to view or edit. The available memory section definitions also appear in the Memory section name menu in the Custom Storage Class panel. The properties of a memory section definition are as follows:

Previewing Generated Code

If you click Validate on the Memory Section panel, the Pseudocode preview panel displays a preview of code that is generated from objects of the given class. The panel also displays messages (in blue) to highlight changes as they are made. The code preview changes dynamically as you edit the class properties. The next figure shows a code preview for the MemConstVolatile memory section.

Using Memory Section References

Any package can access and use memory sections that are defined in any other package, including both user-defined packages and predefined packages such as Simulink and mpt. Only one copy of the section exists, in the package that first defined it; other packages refer to it by pointing to it in its original location. Thus any changes to the section, including changes to a predefined section in later MathWorks product releases, are immediately available in every referencing package.

To configure a package to use a memory section that is defined in another package:

  1. Type cscdesigner to launch the Custom Storage Class Designer.

  2. Select the Memory Section tab.

  3. Use Select Package to select the package in which you want to reference a class or section defined in some other package.

  4. In the Memory section definitions pane, select the existing definition below which you want to insert the reference.

  5. Click New Reference.

    A new reference with a default name and properties appears below the previously selected definition. The new reference is selected, and a Reference tab appears that shows the reference's initial properties.

  6. Use the Name field to enter a name for the new reference. The name must be unique in the importing package, but can duplicate the name in the source package.

  7. Set Refer to memory section in package to specify the package that contains the memory section you want to reference.

  8. Set Memory section to reference to specify the memory section to be referenced. Trying to create a circular reference generates an error and leaves the package unchanged.

  9. Click OK or Apply to save the changes to memory. See Saving Your Definitions for information about saving changes permanently.

For example, the next figure shows the memory section MemConstVolatile imported from the Simulink package into mypkg, and given the same name that it has in the source package. Any other name could have been used without affecting the properties of the memory section.

You can use Custom Storage Class Designer capabilities to copy, reorder, validate, and otherwise manage memory sections that have been added to a class by reference. However, you cannot change the underlying definitions. You can change a memory section only in the package where it was originally defined.

Changing Existing Memory Section References

To change an existing memory section reference, select it in the Memory section definitions pane. The Reference tab appears, showing the current properties of the reference. Make any needed changes, then click OK or Apply to save the changes to memory. See Saving Your Definitions for information about saving changes permanently.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS