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 and displays the associated package names in the Select package panel:

The Select package panel contains a menu of 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.

Selecting and Editing CSCs, Memory Sections, and References

The Custom Storage Class / Memory Section panel lets you select, view, and — if the CSC is writeable — edit CSC or memory section definitions and references. In the picture below, the Custom Storage Class tab is selected.

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:

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. These properties are shown in the next figure.

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[1] C standard (/*...*/). Use \n to specify a new line.

Properties in the Comments panel 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 selected. (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 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.

  4. In the Custom storage class 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. 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.

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.

Editing Memory Section Definitions

The Memory Section panel lets you view, edit, and verify memory section definitions. Memory section definitions add comments, qualifiers, and #pragma directives to generated symbol declarations. The next figure shows the Memory Section panel with the MemConstVolatile memory section selected:

The Memory section definitions list lets you select a memory section definition to view or edit. The predefined memory section definitions are as follows:

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. The relevant part of the designer window looks like this:

  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. 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.

  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.

You can use Custom Storage Class Designer capabilities to copy, reorder, validate, and otherwise manage 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.


[1] ANSI is a registered trademark of the American National Standards Institute, Inc.

  


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