Main Content

Register New Hardware Devices

On the Hardware Implementation pane, you can specify parameters that describe target hardware and compiler properties for MATLAB® software, which enables you to:

  • Observe target hardware during model simulations.

  • Generate optimized code for production or test hardware.

  • Directly test or deploy generated code on target hardware.

The Hardware Implementation pane supports a range of target hardware. To extend the range, register new hardware devices by using the target.Processor and target.LanguageImplementation classes.

Specify Hardware Implementation for New Device

To register a new hardware device:

  1. Create a target.Processor object for the new hardware device.

    myProc = target.create('Processor', ...
                           'Name', 'MyProcessor', ...
                           'Manufacturer', 'MyManufacturer');

  2. Create a target.LanguageImplementation object for language implementation details.

    myLanguageImplementation = target.create('LanguageImplementation', ...
                                             'Name', 'MyProcessorImplementation');
    

  3. Specify language implementation details.

    myLanguageImplementation.Endianess = target.Endianess.Little;
     
    myLanguageImplementation.AtomicIntegerSize = 64;
    myLanguageImplementation.AtomicFloatSize = 64;
    myLanguageImplementation.WordSize = 64;
     
    myLanguageImplementation.DataTypes.Char.Size = 8;
    myLanguageImplementation.DataTypes.Short.Size = 16;
    myLanguageImplementation.DataTypes.Int.Size = 32;
    myLanguageImplementation.DataTypes.Long.Size = 64;
    myLanguageImplementation.DataTypes.LongLong.IsSupported = true;
    myLanguageImplementation.DataTypes.LongLong.Size = 64;
    myLanguageImplementation.DataTypes.Float.Size = 32;
    myLanguageImplementation.DataTypes.Double.Size = 64;
     
    myLanguageImplementation.DataTypes.Pointer.Size = 32;
      
    myLanguageImplementation.DataTypes.SizeT.Size = 64;
    myLanguageImplementation.DataTypes.PtrDiffT.Size = 64;

  4. Associate the language implementation with the hardware device.

    myProc.LanguageImplementations = myLanguageImplementation;
    

  5. Add the target.Processor object to an internal database.

    objectsAdded = target.add(myProc);

On the Hardware Implementation pane, you can now set Device vendor and Device type to MyManufacturer and MyProcessor respectively.

Specify Hardware Implementation That Persists Over MATLAB Sessions

By default, when you add the target object to the internal database, the target data is available only for the current MATLAB session. You can specify target data persistence over MATLAB sessions.

  1. Create a target.Processor object for a new hardware device.

    myProc = target.create('Processor', ...
                           'Name', 'MyProcessor', ...
                           'Manufacturer', 'MyManufacturer');
    
    existingImplementation = target.get('LanguageImplementation', ... 
                                        'ARM Compatible-ARM Cortex'); 
    myProc.LanguageImplementations = existingImplementation;

  2. Add the target.Processor object to an internal database and specify persistence of target data over MATLAB sessions.

    objectsAdded = target.add(myProc, 'UserInstall', true);
    If you subsequently modify the object in the MATLAB workspace and then want to update the object in the internal database, you can use the target.update function.

  3. You can remove the object from the internal database.

    target.remove(objectsAdded);
    To remove multiple persistent objects from the internal database, use the target.clear function.

Create Hardware Implementation by Modifying Existing Implementation

If an existing hardware implementation contains most of the values that you want in a new hardware implementation, you can quickly create the new implementation by creating and modifying a copy of the existing implementation.

  1. Create a target.Processor object for the new hardware device.

    myProc = target.create('Processor', ...
                           'Name', 'MyProcessor', ...
                           'Manufacturer', 'MyManufacturer');

  2. Create a target.LanguageImplementation object that copies an existing language implementation.

    myCopiedImplementation = target.create('LanguageImplementation', ...
                                           'Name', 'MyCopiedImplementation', ...
                                           'Copy', 'Atmel-AVR');
    

  3. Specify the required language implementation details. For example, byte ordering.

    myCopiedImplementation.Endianess = target.Endianess.Big;

  4. Associate the language implementation with the hardware device.

    myProc.LanguageImplementations = myCopiedImplementation;

  5. Add the target.Processor object to an internal database.

    objectsAdded = target.add(myProc);

Create Hardware Implementation by Reusing Existing Implementation

If your hardware device requires the same hardware implementation as an existing implementation, you can reuse the existing implementation.

  1. Create a target.Processor object for the new hardware device.

    myProc = target.create('Processor', ...
                           'Name', 'MyProcessor', ...
                           'Manufacturer', 'MyManufacturer');

  2. Retrieve the existing implementation by using the identifier for the device vendor and type, for example, 'ARM Compatible-ARM Cortex'.

    existingImplementation = target.get('LanguageImplementation', ...
                                        'ARM Compatible-ARM Cortex');

  3. Associate the language implementation with the hardware device.

    myProc.LanguageImplementations = existingImplementation;

  4. Add the target.Processor object to an internal database.

    objectsAdded = target.add(myProc);

Validate Hardware Device Data

To validate the data integrity of target objects, use the IsValid property or validate method of the target.Object base class.

Consider an example where you create a target.Processor object and associate an existing language implementation with the object.

myProcessor = target.create('Processor');
myProcessor.LanguageImplementations = target.get('LanguageImplementation', ...
                                                 'ARM Compatible-ARM Cortex');
To validate the created object, run myProcessor.IsValid or myProcessor.validate().
myProcessor.IsValid
ans =
  logical
  0
myProcessor.validate()
Error using target.Processor/validate
Target data validation failed.
* Undefined property "Name" in "Processor" object.
* Undefined identifier in "Processor" object.
The validation fails because these target.Processor properties are not specified:

  • Name — Processor name

  • Id — Object identifier

You can specify a processor name, which also specifies the object identifier.

myProcessor.Name = 'MyProcessor';
Check the validity of myProcessor.
myProcessor.IsValid
ans =
  logical
  1
The validity of the object is established.

Note

When you use the target.add function to register a target object, the software also checks the validity of the object.

Export Hardware Device Data

You can share previously created hardware device data across computers and users.

For this example, specify a hardware device and add it to an internal database.

myProc = target.create('Processor', ...
                    'Name', 'MyProcessor', ...
                    'Manufacturer', 'MyManufacturer');
existingImplementation = target.get('LanguageImplementation', ...
                                 'ARM Compatible-ARM Cortex');
myProc.LanguageImplementations = existingImplementation;

objectsAdded = target.add(myProc);
To create a function for sharing the hardware device data, run:
target.export(myProc, 'FileName', 'exportMyProcFunction')
The target.export function creates exportMyProcFunction.m in the current working folder.
function registeredObjects = exportMyProcFunction(varargin)
% This function was generated using target data export.

    % Create target.Processor "MyManufacturer-MyProcessor"
    processor = target.create("Processor");
    processor.LanguageImplementations(1) = ...
      target.get("LanguageImplementation", "ARM Compatible-ARM Cortex");
    processor.Manufacturer = "MyManufacturer";
    processor.Name = "MyProcessor";

    % Add the target objects to MATLAB memory
    registeredObjects = target.add(processor, varargin{:});
Now, you can use the generated function to share the hardware device data in your database across computers and users. For example, on another computer, run this command.
objectsAdded = exportMyProcFunction;
The generated function recreates the target.Processor object, MyManufacturer-MyProcessor, and adds it to an internal database.

Create Alternative Identifier for Target Object

To create alternative identifiers for target objects, use the target.Alias class.

For example, if a target.Processor object has a long class identifier, you can create a target.Alias object that provides a short identifier for the target.Processor object.

  1. Retrieve the target.Processor object.

    proccesorObj = target.get('Processor', ...
                              'Analog Devices-ADSP-CM40x (ARM Cortex-M)');

  2. Use the target.create function to create a target.Alias object.

    aliasProcessorObj = target.create('Alias');

  3. Use target.Alias object properties to specify the alternative identifier and original target object.

    aliasProcessorObj.Name = 'myShortName';
    aliasProcessorObj.For = proccesorObj;

  4. Add the target.Alias object to an internal database.

    target.add(aliasProcessorObj);
  5. To retrieve the original target.Processor object, run:

    target.get('Processor', 'myShortName');

Upgrade Data Definitions for Hardware Devices

To upgrade existing hardware device definitions that are specified through rtwTargetInfo.m or sl_customization.m files, use the target.upgrade function.

rtwTargetInfo.m File

Suppose you have the hardware device definition in an rtwTargetInfo.m file:

function rtwTargetInfo(tr)
  
    % Add registration function handle to the Target Registry
    tr.registerTargetInfo(@loc_register_hardware);
end
  
function hw = loc_register_hardware
    hw = RTW.HWDeviceRegistry;
    hw.Vendor = 'MyManufacturer';
    hw.Type = 'MyDevice';
    hw.Alias = {};
    hw.Platform = {'Prod', 'Target'};
    hw.setWordSizes([8 16 32 64 64 64 64 64 64 64 64]);
    hw.Endianess = 'Little';
    hw.IntDivRoundTo = 'Zero';
    hw.ShiftRightIntArith = true;
    hw.LargestAtomicInteger = 'Long';
    hw.LargestAtomicFloat = 'Double';
end

To upgrade the data definitions contained in the file, run:

target.upgrade('rtwTargetInfo', 'myPathTo/rtwTargetInfo.m');
In the current folder, the function creates this registerUpgradedTargets.m file:
function processor = registerUpgradedTargets(varargin)
% This function was generated using target data export.
  
    % Create target.LanguageImplementation 'MyManufacturer-MyDevice'
    languageimplementation = target.create('LanguageImplementation');
    languageimplementation.AtomicFloatSize = 64;
    languageimplementation.AtomicIntegerSize = 64;
    languageimplementation.DataTypes.Char.Size = 8;
    languageimplementation.DataTypes.Double.Size = 64;
    languageimplementation.DataTypes.Float.Size = 64;
    languageimplementation.DataTypes.Half.IsSupported = false;
    languageimplementation.DataTypes.Half.Size = 16;
    languageimplementation.DataTypes.Int.Size = 32;
    languageimplementation.DataTypes.Long.Size = 64;
    languageimplementation.DataTypes.LongLong.IsSupported = false;
    languageimplementation.DataTypes.LongLong.Size = 64;
    languageimplementation.DataTypes.Pointer.Size = 64;
    languageimplementation.DataTypes.PtrDiffT.Size = 64;
    languageimplementation.DataTypes.Short.Size = 16;
    languageimplementation.DataTypes.SizeT.Size = 64;
    languageimplementation.Name = 'MyManufacturer-MyDevice';
    languageimplementation.WordSize = 64;
  
    % Create target.Processor 'MyManufacturer-MyDevice'
    processor = target.create('Processor');
    processor.LanguageImplementations(1) = languageimplementation;
    processor.Manufacturer = 'MyManufacturer';
    processor.Name = 'MyDevice';
  
    % Add the target objects to MATLAB memory
    target.add(processor, varargin{:});
end

To register the hardware device with MATLAB, run:

registerUpgradedTargets()

If you want the registration to persist across MATLAB sessions, run:

registerUpgradedTargets('UserInstall', true)

sl_customization.m File

Suppose you have multiple hardware device definitions in an sl_customization.m file:

function sl_customization(cm)
  % sl_customization function to register a device
  % vendor and type with Simulink.
  % Copy or rename this file to sl_customization.m.
  cm.registerTargetInfo(@loc_register_device);
  cm.registerTargetInfo(@loc_register_device2);
  cm.registerTargetInfo(@loc_createConfig);
     
  cm.registerTargetInfo(@locRegisterTfl);
  cm.CodeCoverageTools.add('DummyCoverageToolForTesting',...
                           'HDummyCovTool',...
                           'A Coverage Tool Vendor');
end
 
function thisDev = loc_register_device
  thisDev = RTW.HWDeviceRegistry;
  thisDev.Vendor = 'MyDevVendor';
  thisDev.Type = 'MyDevType';
  thisDev.Alias = {};
  thisDev.Platform = {'Prod', 'Target'};
  thisDev.setWordSizes([8 16 32 32 32]);
  thisDev.LargestAtomicInteger = 'Char';
  thisDev.LargestAtomicFloat = 'None';
  thisDev.Endianess = 'Unspecified';
  thisDev.IntDivRoundTo = 'Undefined';
  thisDev.ShiftRightIntArith = true;
  thisDev.setEnabled({'IntDivRoundTo'});
end
 
function thisDev = loc_register_device2
  thisDev = RTW.HWDeviceRegistry;
  thisDev.Vendor = 'MyDevVendor';
  thisDev.Type = 'MyDevType2';
  thisDev.Alias = {};
  thisDev.Platform = {'Prod', 'Target'};
  thisDev.setWordSizes([8 16 32 32 32]);
  thisDev.LargestAtomicInteger = 'Char';
  thisDev.LargestAtomicFloat = 'None';
  thisDev.Endianess = 'Unspecified';
  thisDev.IntDivRoundTo = 'Undefined';
  thisDev.ShiftRightIntArith = true;
  thisDev.setEnabled({'IntDivRoundTo'});
end
 
% local function
function config = loc_createConfig
  config = rtw.connectivity.ConfigRegistry;
  config.ConfigName = 'Infineon->C16x, XC16x';
  config.ConfigClass = 'pil_slcust.HostDemoConfig1';
  config.SystemTargetFile = {'custom_target.tlc'};
  config.TemplateMakefile = {'custom_target.tmf'};
  config.TargetHWDeviceType = {'Infineon->C16x, XC16x'};
end
 
function thisTfl = locRegisterTfl
  thisTfl(1) = RTW.TflRegistry;
  thisTfl(1).Name = 'myTFL1';
  thisTfl(1).Description = 'Test';
  thisTfl(1).TableList = {'tfl_table_Sum',...
                          'tfl_table_Product',...
                         }; % Sum includes Add and Subtract
  thisTfl(1).BaseTfl = 'ANSI_C';
  thisTfl(1).TargetHWDeviceType = {'*'};
end

To upgrade the RTW.HWDeviceRegistry data definitions in the file, run:

target.upgrade('sl_customization', 'myPathTo/sl_customization.m')

In the current folder, the function creates this registerUpgradedTargets.m file:

function targetObjects = registerUpgradedTargets(varargin)
% This function was generated using target data export.
 
    % Create target.LanguageImplementation 'MyDevVendor-MyDevType'
    languageimplementation = target.create('LanguageImplementation');
    languageimplementation.AtomicIntegerSize = 8;
    languageimplementation.DataTypes.Char.Size = 8;
    languageimplementation.DataTypes.Double.Size = 64;
    languageimplementation.DataTypes.Float.Size = 32;
    languageimplementation.DataTypes.Half.IsSupported = false;
    languageimplementation.DataTypes.Half.Size = 16;
    languageimplementation.DataTypes.Int.Size = 32;
    languageimplementation.DataTypes.Long.Size = 32;
    languageimplementation.DataTypes.LongLong.IsSupported = false;
    languageimplementation.DataTypes.LongLong.Size = 64;
    languageimplementation.DataTypes.Pointer.Size = 32;
    languageimplementation.DataTypes.PtrDiffT.Size = 32;
    languageimplementation.DataTypes.Short.Size = 16;
    languageimplementation.DataTypes.SizeT.Size = 32;
    languageimplementation.Endianess = target.Endianess.Unspecified;
    languageimplementation.Name = 'MyDevVendor-MyDevType';
    languageimplementation.WordSize = 32;
 
    % Create target.Processor 'MyDevVendor-MyDevType'
    processor = target.create('Processor');
    processor.LanguageImplementations(1) = languageimplementation;
    processor.Manufacturer = 'MyDevVendor';
    processor.Name = 'MyDevType';
 
    % Create target.LanguageImplementation 'MyDevVendor-MyDevType2'
    languageimplementation2 = target.create('LanguageImplementation');
    languageimplementation2.AtomicIntegerSize = 8;
    languageimplementation2.DataTypes.Char.Size = 8;
    languageimplementation2.DataTypes.Double.Size = 64;
    languageimplementation2.DataTypes.Float.Size = 32;
    languageimplementation2.DataTypes.Half.IsSupported = false;
    languageimplementation2.DataTypes.Half.Size = 16;
    languageimplementation2.DataTypes.Int.Size = 32;
    languageimplementation2.DataTypes.Long.Size = 32;
    languageimplementation2.DataTypes.LongLong.IsSupported = false;
    languageimplementation2.DataTypes.LongLong.Size = 64;
    languageimplementation2.DataTypes.Pointer.Size = 32;
    languageimplementation2.DataTypes.PtrDiffT.Size = 32;
    languageimplementation2.DataTypes.Short.Size = 16;
    languageimplementation2.DataTypes.SizeT.Size = 32;
    languageimplementation2.Endianess = target.Endianess.Unspecified;
    languageimplementation2.Name = 'MyDevVendor-MyDevType2';
    languageimplementation2.WordSize = 32;
 
    % Create target.Processor 'MyDevVendor-MyDevType2'
    processor2 = target.create('Processor');
    processor2.LanguageImplementations(1) = languageimplementation2;
    processor2.Manufacturer = 'MyDevVendor';
    processor2.Name = 'MyDevType2';
 
    targetObjects = [processor, processor2];
 
    % Add the target objects to MATLAB memory
    target.add(targetObjects, varargin{:});
end

To register the hardware device definitions with MATLAB, run:

registerUpgradedTargets()

If you want the registration to persist across MATLAB sessions, run:

registerUpgradedTargets('UserInstall', true)

See Also

|

Related Topics