Model Reference

MotoHawk™ supports Matlab's Model Reference feature. This feature will allow you to include a model as a subsystem in to another model. MotoHawk will compile these models to a c library that will then be referenced by the main model build.

Getting Started

Lets start by executing the following command at the Matlab prompt:


You should see output that looks like this:

     Creating project: ModelReferenceExample
         in directory: C:\Users\demo\Documents\MATLAB\ModelReferenceExample
           model file: C:\Users\demo\Documents\MATLAB\ModelReferenceExample\ModelReferenceExample.slx

The model "ModelReferenceExample.slx" will also be opened. Next, select your desired target. We now need to add a Tool Chain Definition block to our model. Then select the toolchain that you wish to use.

Now that the target and toolchain have been selected, we need to insure that the reference models have the same settings. Open the Model Configuration Parameters, (Either by pressing CTRL+E or from the Simulation menu). Expand the Code Generation from the menu and select "MotoHawk Target Definition." Now by clicking on the button labelled "Propagate Configuration to Model References" you will set up all referenced models to have the same configurations as the parent model.

You now have a MotoHawk model reference project set-up and ready to build. An optional step is to pre-build all of the referenced models. The is a handy button in the Configuration Parameters to make this easy for you. This may or may not be necessary depending on your data storage architecture.

Model Cross Checks

MotoHawk will perform cross checks of the reference models when the main model is updated. This requires that the reference models are pre built. If you do an update when the reference models have not been built, you will see the following output:

WARNING: Reference Model MODEL_NAME has not been built, skipping model cross checks.

This indicates that the model cross checks on the reference models where not completed. You may run into build errors when the cross checks are not performed. To avoid this scenario prebuild your reference models using the button in the model configuration parameters. This button can be found under Code Generation -> MotoHawk Target Definition, and can be seen in the image above.


Reference Models have multiple advantages, including faster build times, but MotoHawk imposes some limitations on their use. The model architecture must consider:

  1. Data Stores are in global context in a model reference, which differs from MotoHawk Components, where they are locally scoped.
    • A Model Reference must define the data store if it is to be read or written within the context of the model reference.
    • The top level application model can read or write the data stores defined within the Model Reference.
  2. Fixed Non Volatile Data Stores can not be defined in a model reference.
  3. While multi instance is supported, it is up to the model designer to handle the name conflicts.
  4. I/O blocks can’t be used inside a reference model.
  5. Virtual buses can't be passed through an interface. The signal interface must be well defined.
  6. Structures – single data store w/ multiple fields, etc are not supported.
  7. Non Standard Types (index_T, fault_T..) can only be passed through a boundary when the type is specified via Simulink.AliasType.
  8. All models are required to have the same toolchain, and reference models must be rebuilt if the toolchain for the main application model changes.
  9. The Model Reference must target the same processor that is utilized by the top level application's Target.
  10. The Model Reference cannot itself contain another Model Reference, nor a MotoHawk Component.

Protected Models

Currently MotoHawk supports Protected Model References where the "use generated code" was selected and the "Content Type" was configured for "Binaries."

A model reference which is to be converted to protected model reference will need to define Simulink.AliasType for each of these MotoHawk types (if used):

In addition, when the protected model reference using the above MotoHawk types is utilized in an application model, the application model will need to define the equivalent Simulink.AliasType for each type in use.

A model reference can be converted to a protected model reference by right-clicking a Model Reference Instance block and choosing "Subsystem & Model Reference" and then "Create Protected Model for Selected Model Block ..." Alternatively, this command is useful for accomplishing the protect operation from the MATLAB command line:

>> Simulink.ModelReference.protect('YOUR_MDLREF_NAME','Mode','CodeGeneration','OutputFormat','CompiledBinaries')

Where the 'YOUR_MDLREF_NAME' should be substituted for your Model Reference's Name without the file extension. Many steps of the build process involved in creating the protected model reference will be output to the command window. Be sure to take note that the process indicates that it has completed successfully.

Protected Model Simulation
At this time MotoHawk blocks do not support the simulation capability of protected model references. Signals which are sourced by MotoHawk blocks in a protected model reference will source the value zero, except for the MotoHawk Calibration block, which will source the Default Value provided in the block.

MotoHawk Components are also recommended if IP protection is required.

Supported Blocks

Calibration and Probing Blocks

Data Storage Blocks

* Data must be defined in same model

Lookup Tables

Trigger Blocks

OBD Fault Blocks

CAN Blocks