Main Content

Model Reference support for C2000 Processors

A model reference is a reference to another model using a Model block. These references create model hierarchy. Each referenced model has a defined interface that specifies the properties of its inputs and outputs. The defined interface makes the behavior of the referenced model independent of its context in the model hierarchy. For simulation and code generation, a referenced model executes like a single block, or atomic unit, when the parent model executes. Model references are ideal for code reuse, unit testing, parallel builds, and large components. They can also reduce file contention and merge issues. For more information, see Model References.

In Embedded Coder® Support Package for Texas Instruments™ C2000™ Processors, you can now use all the driver blocks from C2000 library inside model reference expect for Software and Hardware interrupt, CLA task trigger, CLA subsystem, and Idle task.

Reference Existing Models

A model becomes a referenced model when a Model block in another model references it. Any model can function as a referenced model, and can continue to function as a separate model.

To reference an existing model in another model, follow these steps.

  1. If the folder containing the model you want to reference is not on the MATLAB® path, add the folder to the MATLAB path.

  2. In the referenced model, set Total number of instances allowed per top model to:

    • One - to use the model at most once in a model hierarchy.

    • Multiple - to use the model more than once in a model hierarchy. To reduce overhead, specify Multiple only when necessary.

    • Zero - to preclude referencing the model.

  3. Create an instance of the Model block in the parent model. The new block is initially unresolved because it does not specify a referenced model.

  4. To open the Block Parameters dialog box, double-click the unresolved Model block.

  5. Enter the name of the referenced model in the Model name field. This name must contain fewer than 60 characters, exclusive of the file extension.

  6. Click OK. If the referenced model contains root-level inputs or outputs, the Model block displays corresponding input and output ports. For more, see Reference Existing Models

Things to Consider during Reference Modeling

  • Scheduling is considered only from the top model.

  • All the configuration parameters referred by driver blocks must be same across all the models . If they are not same, then behavior is undefined as we do not have control on which configuration will be picked by the block.

  • When using model reference and when function block is present in top level of child model, then you will not be able to generate the code for the child model directly.

  • Total number of instances allowed per top model is One.

  • For referenced models, go to Configuration Parameters > Diagnostics and set Insufficient maximum identifier length to None, when maximum identifier length does not provide enough space to make global identifiers unique across models.

  • When naming the top model and reference model, if the first 31 characters of the top and reference model name matches, you will encounter an compilation error. since all 31 characters are used to name the variables in the generated code.

    So always try to have a unique names for top and reference model and try to keep the naming short.

Create Data Dictionary and Migrate the Model

  1. Configure your reference model with all the settings described in Reference Existing Models.

  2. Open Model Properties. In the Model Properties dialog box, click New to create a data dictionary.

  3. Name the data dictionary, save it, and click Apply.

  4. Link model to data dictionary dialog appears. Select the appropriate option.

  5. Click Migrate data.

  6. Click Migrate in response to the message about copying referenced variables.

  7. (Optional) Clear Enable model access to base workspace.

  8. Click OK.

  9. To open the dictionary, in the Simulink Editor, click the model data badge in the bottom left corner, then click the External Data link.

    To inspect the contents of the dictionary, in the Model Explorer Model Hierarchy pane under the External Data node, expand the dictionary node.

Convert Configuration Set to Configuration Reference

In the top model, you must convert the active configuration set to a configuration reference:

  1. Open the Model Explorer.

  2. In the Model Hierarchy pane, expand the top model. In the list, select the Configurations node, and right-click Configuration (Active) in the Contents pane. In the context menu, select Convert to Configuration Reference.

  3. In the Name field, use the default name, Configuration. This configuration set object is stored in the data dictionary SharedDataDictionary.sldd.

  4. Click OK.

    The original configuration set is now stored as a configuration set object, Configuration, in the Simulink data dictionary. The active configuration for the top model is now a configuration reference that points to the configuration set object in the data dictionary.

  5. In Model Explorer, go to Model Hierarchy > RefConfigModel > Configuration > Convert Active configuration to Reference.

  6. Name the configuration reference. The associated sldd is selected to create a reference configuration set.

    A configuration reference allows multiple models to use same externally stored configuration set.

  7. You can view the newly created reference configuration in Configuration Reference.

You can modify the reference configuration and share a Configuration with Multiple Models. For more information, see Share a Configuration with Multiple Models.

A predefined synchronous Referenced Model is available in Serial Communication Using SCI Blocks .

Configure Reference Model of Synchronous and Asynchronous

Configure a reference model for synchronous and asynchronous.

  1. Scheduling through base rate (periodic) and interrupt (asynchronous).

    Task priority matches the priority of ISR.

  2. Select the Output function call on the inport for asynchronous function trigger.

  3. You cannot generate code independently from child model.

See Also

Related Topics