Registering Target Function Libraries

Overview of TFL Registration

After you define function and operator replacements in a target function library (TFL) table definition file, your table can be included in a TFL that you register either with Simulink software or with Embedded MATLAB Coder software. When a TFL is registered, it appears in the Target function library drop-down list on the Interface pane of either the Simulink Configuration Parameters dialog box or the Embedded MATLAB Coder Real-Time Workshop dialog box. You can select it from the Target function library drop-down list for use in code generation.

To register TFLs with Simulink software, use the Simulink customization file sl_customization.m. This file is a mechanism that allows you to use M-code to perform customizations of the standard Simulink user interface. The Simulink software reads the sl_customization.m file, if present on the MATLAB path, when it starts and the customizations specified in the file are applied to the Simulink session. For more information on the sl_customization.m customization file, see Customizing the Simulink User Interface in the Simulink documentation.

To register TFLs with Embedded MATLAB Coder software, use the Embedded MATLAB Coder customization file rtwTargetInfo.m. This file is a mechanism that allows you to use M-code to perform customizations of the standard Embedded MATLAB Coder Real-Time Workshop dialog box. The Embedded MATLAB Coder software reads the rtwTargetInfo.m file, if present on the MATLAB path, when it starts and the customizations specified in the file are applied to the Embedded MATLAB Coder session.

Using the sl_customization API to Register a TFL with Simulink Software

To register a TFL, you create an instance of sl_customization.m and include it on the MATLAB path of the Simulink installation that you want to customize. The sl_customization function accepts one argument: a handle to an object called the Simulink.CustomizationManager. The function is declared as follows:

function sl_customization(cm)

The body of the sl_customization function invokes the registerTargetInfo(tfl) method provided by Simulink.CustomizationManager to register one or more TFLs with the Simulink software. Typically, the registerTargetInfo function call references a local function that defines the TFLs to be registered. For example:

  % Register the TFL defined in local function locTflRegFcn
  cm.registerTargetInfo(@locTflRegFcn);

end % End of SL_CUSTOMIZATION

Below the sl_customization function, the referenced local function describes one or more TFLs to be registered. For example, you can declare the local function as follows:

% Local function to define a TFL
function thisTfl = locTflRegFcn

In the local function body, for each TFL to be registered, you instantiate a TFL registry entry using tfl = RTW.TflRegistry. For example,

  thisTfl = RTW.TflRegistry;

Then, you define the TFL properties shown in the following table within the registry entry.

TFL PropertyDescription
NameString specifying the name of the TFL, as it should be displayed in the Target function library drop-down list on the Interface pane of the Configuration Parameters dialog box.
Description String specifying a text description of the TFL, as it should be displayed in the tool tip for the TFL in the Configuration Parameters dialog box.
TableList Cell array of strings specifying the tables that make up the TFL, in descending priority order.
BaseTfl

String specifying the name of the TFL on which this TFL is based.

    Note   To ensure that functions, macros, and constants used by built-in blocks are available in your TFL, and to help ensure compatibility between releases, you must specify one of the default MathWorks libraries as the base TFL: 'C89/C90 (ANSI)', 'C99 (ISO)', 'GNU99 (GNU)', or an equivalent alias.

TargetHWDeviceTypeAlways specify {'*'}.

For example:

  thisTfl.Name = 'Sine Function Example'; 
  thisTfl.Description = 'Demonstration of sine function replacement';
  thisTfl.TableList = {'tfl_table_sinfcn'};
  thisTfl.BaseTfl = 'C89/C90 (ANSI)';
  thisTfl.TargetHWDeviceType = {'*'};

end % End of LOCTFLREGFCN

Combining the elements described in this section, the complete sl_customization function for the 'Sine Function Example' TFL would appear as follows:

function sl_customization(cm)
% sl_customization function to register a target function library (TFL) for use with Simulink

  % Register the TFL defined in local function locTflRegFcn
  cm.registerTargetInfo(@locTflRegFcn);

end % End of SL_CUSTOMIZATION


% Local function to define a TFL containing tfl_table_sinfcn
function thisTfl = locTflRegFcn

  % Instantiate a TFL registry entry
  thisTfl = RTW.TflRegistry;

  % Define the TFL properties
  thisTfl.Name = 'Sine Function Example'; 
  thisTfl.Description = 'Demonstration of sine function replacement';
  thisTfl.TableList = {'tfl_table_sinfcn'};
  thisTfl.BaseTfl = 'C89/C90 (ANSI)';
  thisTfl.TargetHWDeviceType = {'*'};

end % End of LOCTFLREGFCN

If you place the sl_customization.m file containing this function in the MATLAB search path or in the current working directory, the TFL is registered at each Simulink startup. The Simulink software will display the TFL in the Target function library drop-down list on the Interface pane of the Configuration Parameters dialog box. For example, the following figure shows the Configuration Parameters dialog box display, including tool tip, for the 'Sine Function Example' TFL.

Using the rtwTargetInfo API to Register a TFL with Embedded MATLAB Coder Software

To register a TFL for use with Embedded MATLAB Coder software, you create an instance of rtwTargetInfo.m and include it on the MATLAB path of the Embedded MATLAB Coder installation that you want to customize. The rtwTargetInfo function accepts one argument: a handle to a target registration object. The function is declared as follows:

function rtwTargetInfo(tr)

The body of the rtwTargetInfo function invokes the registerTargetInfo(tfl) method provided by the target registry object to register one or more TFLs with the Embedded MATLAB Coder software. Typically, the registerTargetInfo function call references a local function that defines the TFLs to be registered. For example:

  % Register the TFL defined in local function locTflRegFcn
  tr.registerTargetInfo(@locTflRegFcn);

end % End of RTWTARGETINFO

Below the rtwTargetInfo function, the referenced local function describes one or more TFLs to be registered. The format exactly matches the TFL description format previously described for Simulink use. For example, here is the Embedded MATLAB Coder equivalent of the complete TFL registration file displayed in Using the sl_customization API to Register a TFL with Simulink Software.

function rtwTargetInfo(tr)
% rtwTargetInfo function to register a target function library (TFL) for use with emlc

  % Register the TFL defined in local function locTflRegFcn
  tr.registerTargetInfo(@locTflRegFcn);

end % End of RTWTARGETINFO


% Local function to define a TFL containing tfl_table_sinfcn
function thisTfl = locTflRegFcn

  % Instantiate a TFL registry entry
  thisTfl = RTW.TflRegistry;

  % Define the TFL properties
  thisTfl.Name = 'Sine Function Example'; 
  thisTfl.Description = 'Demonstration of sine function replacement';
  thisTfl.TableList = {'tfl_table_sinfcn'};
  thisTfl.BaseTfl = 'C89/C90 (ANSI)';
  thisTfl.TargetHWDeviceType = {'*'};

end % End of LOCTFLREGFCN

If you place the rtwTargetInfo.m file containing this function in the MATLAB search path or in the current working directory, the TFL is registered at each Embedded MATLAB Coder startup. The Embedded MATLAB Coder software will display the TFL in the Target function library drop-down list on the Interface pane of the Real-Time Workshop dialog box.

Registering Multiple TFLs

For an example of a TFL registration file that registers multiple TFLs, see the sl_customization.m file used in the TFL demo, rtwdemo_tfl_script. The following excerpt illustrates the general approach, which applies equally to Simulink and Embedded MATLAB Coder TFL registration files.

function sl_customization(cm)

  cm.registerTargetInfo(@locTflRegFcn);

end % End of SL_CUSTOMIZATION

% Local function(s)
function thisTfl = locTflRegFcn
  % Register a Target Function Library for use with model: rtwdemo_tfladdsub.mdl
  thisTfl(1) = RTW.TflRegistry;
  thisTfl(1).Name = 'Addition & Subtraction Examples'; 
  thisTfl(1).Description = 'Demonstration of addition/subtraction operator replacement';
  thisTfl(1).TableList = {'tfl_table_addsub'};
  thisTfl(1).BaseTfl = 'C89/C90 (ANSI)';
  thisTfl(1).TargetHWDeviceType = {'*'};
  .
  .
  .
  % Register a Target Function Library for use with model: rtwdemo_tflmath.mdl
  thisTfl(4) = RTW.TflRegistry;
  thisTfl(4).Name = 'Math Function Examples'; 
  thisTfl(4).Description = 'Demonstration of math function replacement';
  thisTfl(4).TableList = {'tfl_table_math'};
  thisTfl(4).BaseTfl = 'C89/C90 (ANSI)';
  thisTfl(4).TargetHWDeviceType = {'*'};

end % End of LOCTFLREGFCN
  


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