| Real-Time Workshop® Embedded Coder™ | ![]() |
After you create a target function library (TFL) table containing your function replacement entries, but before you deploy production TFLs containing your table for general use in building models, you can use various techniques to examine and validate the TFL table entries. These include:
Invoking the table definition M-file
Using the TFL Viewer at various stages of TFL development to examine TFLs, tables, and entries
Tracing code generated from models for which your TFL is selected
Examining TFL cache hits and misses logged during code generation
Immediately after creating or modifying a table definition M-file (as described in Creating Function Replacement Tables), you should invoke it at the MATLAB command line. This invocation serves as a check of the validity of your table entries. For example,
>> tbl = tfl_table_sinfcn
tbl =
RTW.TflTable
Version: '1.0'
AllEntries: [2x1 RTW.TflCFunctionEntry]
ReservedSymbols: []
>> Any errors found during the invocation are displayed. In the following example, a typo in a data type name is detected and displayed.
>> tbl = tfl_table_sinfcn ??? RTW_CORE:tfl:TflTable: Unsupported data type, 'dooble'. Error in ==> tfl_table_sinfcn at 7 hTable.registerCFunctionEntry(100, 1, 'sin', 'dooble', 'sin_dbl', ... >>
After creating or modifying a table definition M-file, as a further check of your table entries, you should use the TFL Viewer to display and examine your table. Invoke the TFL Viewer using the following form of the MATLAB command RTW.viewTfl:
RTW.viewTfl(table-name)
For example,
>> RTW.viewTfl(tfl_table_sinfcn)

Select entries in your table and verify that the graphical display of the contents of your table meets your expectations. Common problems that can be detected at this stage include:
Incorrect argument order
Conceptual argument naming that does not match the naming convention used by the code generation process
Incorrect relative priority of entries within the table (highest priority is 0, and lowest priority is 100).
For more information about the TFL Viewer, see Using the Target Function Library Viewer in the Real-Time Workshop documentation.
After you register a TFL that includes your function replacement table (as described in Registering Target Function Libraries), you should use the TFL Viewer to verify that your TFL was properly registered and to examine the TFL and the tables it contains. Invoke the TFL Viewer using the MATLAB command RTW.viewTfl with no arguments. This command displays all TFLs registered in the current Simulink session. For example:
>> RTW.viewTfl

If your TFL is not displayed, there may be an error in your TFL registration file, or you may need to issue the MATLAB command sl_refresh_customizations.
If your TFL is displayed, select the TFL and examine and compare its tables, including their relative order. Common problems that can be detected at this stage include
Incorrect relative order of tables in the library (tables are displayed in search order)
Table entry problems as listed in the previous section
For more information about the TFL Viewer, see Using the Target Function Library Viewer in the Real-Time Workshop documentation.
After you register a TFL that includes your function replacement tables, you should use the TFL to generate code and verify that you are obtaining the function or operator replacement that you expect. For example, the following approach uses model-to-code highlighting to trace a specific expected replacement.
Open a ERT-based model for which you anticipate that a function or operator replacement should occur.
Select your TFL in the Target function library drop-down list on the Interface pane of the Configuration Parameters dialog box.
Go to the Real-Time Workshop > Report pane of the Configuration Parameters dialog box and select the options Create code generation report and Model-to-code.
Go to the Real-Time Workshop pane, select the Generate code only option, and generate code for the model.
Go to the model window and use model-to-code highlighting to trace the code generated using your TFL. For example, right-click a block that you expect to have generated a function or operator replacement and select Real-Time Workshop > Navigate to Code. This selection highlights the applicable generated function code within the HTML report, as shown in the following example.

Inspect the generated code and see if the function or operator replacement occurred as you expected.
Note If a function or operator was not replaced as you expected, it means that a call site request was not matched as you intended by your table entry attributes. Either a higher-priority (lower priority value) match was used or no match was found. You can analyze the TFL table entry matching behavior by using the following resources together:
|
Target function library (TFL) replacement may behave differently than you expect in some cases. To verify that you are obtaining the function or operator replacement that you expect, you first inspect the generated code, as described in Tracing Code Generated Using Your Target Function Library.
To analyze replacement behavior, in addition to referencing the generated code and examining your TFL tables in the TFL Viewer, you can view the TFL cache hits and misses logged during the most recent code generation session. This approach provides information on what data types and attributes should be registered in order to achieve the desired replacement.
To display the TFL cache hits and misses logged during the most recent code generation session, you specify the model parameter TargetFcnLibHandle in a get_param call, as follows:
tfl=get_param('model', 'TargetFcnLibHandle')The resulting display includes the following fields:
| Field | Description |
|---|---|
| HitCache | Table containing function entries that were successfully matched during a code generation session. These entries represent function implementations that should appear in the generated code. |
| MissCache | Table containing function entries that failed to match during a code generation session. These entries are created by the code generation process for the purpose of querying the TFL to locate a registered implementation. If there is a registered implementation that you feel should have been used in the generated code and was not, examining the MissCache for entries that are similar but did not match can help you locate discrepancies in a conceptual argument list or in table entry attributes. |
In the following example, the most recent code generation session logged one cache hit and zero cache misses. You can examine the logged HitCache entry using its table index.
>> a=get_param('sinefcn','TargetFcnLibHandle')
a =
RTW.TflControl
Version: '1.0'
HitCache: [1x1 RTW.TflCFunctionEntry]
MissCache: [0x1 handle]
TLCCallList: [0x1 handle]
TflTables: [2x1 RTW.TflTable]
>> a.HitCache(1)
ans =
RTW.TflCFunctionEntry
Key: 'sin'
Priority: 100
ConceptualArgs: [2x1 RTW.TflArgNumeric]
Implementation: [1x1 RTW.CImplementation]
RTWmakecfgLibName: ''
GenCallback: ''
GenFileName: ''
SaturationMode: 'RTW_SATURATE_UNSPECIFIED'
RoundingMode: 'RTW_ROUND_UNSPECIFIED'
AcceptExprInput: 1
SideEffects: 0
UsageCount: 2
SharedUsageCount: 0
Description: ''
ImplType: 'FCN_IMPL_FUNCT'
AdditionalHeaderFiles: {0x1 cell}
AdditionalIncludePaths: {0x1 cell}
AdditionalSourceFiles: {0x1 cell}
AdditionalSourcePaths: {0x1 cell}
AdditionalLinkObjs: {0x1 cell}
AdditionalLinkObjsPaths: {0x1 cell}
>>
![]() | Creating Function Replacement Tables | Registering Target Function Libraries | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |