Main Content

Register Code Replacement Library

Create a code replacement library by defining in a registration file the library name, code replacement tables, and other information. After you define and register your library it becomes available to the code generator for code replacement.

Interactively Develop and Load a Registration file

  1. In the crtool, select File > Generate registration file.

  2. In the Generate registration file dialog box, specify registration information. Then click OK.

    ParameterDescription
    Registry name (Required)Code replacement library name.
    Table list (Required) Comma-separated list of one or more code replacement tables that you want in the library. Specify tables by using either their names (if located on the MATLAB search path), absolute paths, or relative paths. Library registration does not support tables in namespace directories.
    Base CRLEnables you to specify library hierarchies. Provide the name of a registered library to serve as a base for the library that you are currently registering. For example, a TI device library can be a base for a TI C28x library.
    Target HW deviceComma-separated list of one or more hardware devices that this library supports. Indicate support of all devices with an asterisk (*).
    DescriptionDescription of the purpose and content of the library.
    Generate data alignment specification Flag that enables data alignment.
  3. To use your registered code replacement library, refresh your current MATLAB session with the command:

    sl_refresh_customizations

Programmatically Develop and Load a Registration File

  1. Open a MATLAB function file. From the MATLAB menu, select New > Function.

  2. Save the function file with the name rtwTargetInfo.m.

  3. Copy and paste the following code into your file to use as a template.

    function rtwTargetInfo(cm)
     
    cm.registerTargetInfo(@loc_register_crl);
    end
     
    function this = loc_register_crl 
     
    this(1) = RTW.TflRegistry; %instantiates a registration entry
    this(1).Name = 'Example Code Replacement Library';
    this(1).TableList = {'example_code_replacement_table.m'};
    this(1).TargetHWDeviceType = {'*'};
    this(1).Description = 'This registers an example library';
    
    end
    
  4. In the template, specify the following registration information:

    ParameterDescription
    Registry name (Required)Code replacement library name.
    Table list (Required) Comma-separated list of one or more code replacement tables that you want in the library. Specify tables by using either their names (if located on the MATLAB search path), absolute paths, or relative paths. Library registration does not support tables in package directories.
    Base CRLEnables you to specify library hierarchies. Provide the name of a registered library to serve as a base for the library that you are currently registering. For example, a TI device library can be a base for a TI C28x library.
    Target HW deviceComma-separated list of one or more hardware devices that this library supports. Indicate support of all devices with an asterisk (*).
    DescriptionDescription of the purpose and content of the library.
    Generate data alignment specification Flag that enables data alignment.
  5. Save the file on your MATLAB path.

  6. To use your registered code replacement library, refresh your current MATLAB session with the command:

    >> sl_refresh_customizations

Examples

Register one code replacement library

function rtwTargetInfo(cm)
 
cm.registerTargetInfo(@loc_register_crl);
end
 
function this = loc_register_crl 
 
this(1) = RTW.TflRegistry; %instantiates a registration entry
this(1).Name = 'Example Code Replacement Library';
this(1).TableList = {'example_code_replacement_table.m'};
this(1).TargetHWDeviceType = {'*'};
this(1).Description = 'This registers an example library';

end

Register multiple code replacement libraries.  The models in this section belong to the example Optimize Generated Code by Developing and Using Code Replacement Libraries - Simulink

function rtwTargetInfo(cm)
cm.registerTargetInfo(@loc_register_crl);
end

function thisCRL = loc_register_crl
  % Register a code replacement library for use with model: CRLAdditionSubtraction
  thisCrl(1) = RTW.TflRegistry;
  thisCrl(1).Name = 'Addition & Subtraction Examples';
  thisCrl(1).Description = 'Example of addition/subtraction op replacement';
  thisCrl(1).TableList = {'crl_table_addsub'};
  thisCrl(1).TargetHWDeviceType = {'*'};

  % Register a code replacement library for use with model: CRLMultiplicationDivision
  thisCrl(2) = RTW.TflRegistry;
  thisCrl(2).Name = 'Multiplication & Division Examples';
  thisCrl(2).Description = 'Example of mult/div op repl for built-in integers';
  thisCrl(2).TableList = {'c:/work_crl/crl_table_muldiv'};
  thisCrl(2).TargetHWDeviceType = {'*'};

  % Register a code replacement library for use with model: CRLFixedPointOperators
  thisCrl(3) = RTW.TflRegistry;
  thisCrl(3).Name = 'Fixed-Point Examples';
  thisCrl(3).Description = 'Example of fixed-point operator replacement';
  thisCrl(3).TableList = {fullfile('crl_demo','crl_table_fixpt')};
  thisCrl(3).TargetHWDeviceType = {'*'};

end

Register a code replacement hierarchy

function rtwTargetInfo(cm)
 
cm.registerTargetInfo(@loc_register_crl);
end
 
function thisCRL = loc_register_crl 
  % Register a code replacement library that includes common entries
  thisCrl(1) = RTW.TflRegistry;
  thisCrl(1).Name = 'Common Replacements';
  thisCrl(1).Description = 'Common code replacement entries shared by other libraries';
  thisCrl(1).TableList = {'crl_table_general'};
  thisCrl(1).TargetHWDeviceType = {'*'};
 
  % Register a code replacement library for TI devices
  thisCrl(2) = RTW.TflRegistry;
  thisCrl(2).Name = 'TI Device Replacements';
  thisCrl(2).Description = 'Code replacement entries shared across TI devices';
  thisCrl(2).TableList = {'crl_table_TI_devices'};
  thisCrl(2).TargetHWDeviceType = {'TI C28x', 'TI C55x', 'TI C62x', 'TI C64x', 'TI 67x'};
  thisCrl(1).BaseTfl = 'Common Replacements'
 
  % Register a code replacement library for TI c6xx devices
  thisCrl(3) = RTW.TflRegistry;
  thisCrl(3).Name = 'TI c6xx Device Replacements';
  thisCrl(3).Description = 'Code replacement entries shared across TI C6xx devices';
  thisCrl(3).TableList = {'crl_table_TIC6xx_devices'};
  thisCrl(3).TargetHWDeviceType = {'TI C62x', 'TI C64x', 'TI 67x'};
 
  % Register a code replacement library for the TI c67x device
  thisCrl(4) = RTW.TflRegistry;
  thisCrl(4).Name = 'TI c67x Device Replacements';
  thisCrl(4).Description = 'Code replacement entries for the TI C67x device';
  thisCrl(4).TableList = {'crl_table_TIC67x_device'};
  thisCrl(4).TargetHWDeviceType = {'TI 67x'};

 
end

Related Topics