Target Language Compiler | ![]() ![]() |
Exercise
The files for this exercise are in the tlctutorial
/dualportram
directory of the TLC examples directory.
You are given the C code S-function dp_read.c
. Write your own TLC file to inline this S-function. The dp.mdl
model file contains the dual port read model. The mask for the dp_read
S-function allows you to enter parameters for:
Parameter |
Description |
offset |
|
gain |
Gain |
varType |
Data type for the value read from dual port RAM |
hwAddress |
Memory address that your (fictitious) custom hardware needs to access |
The S-function dp_read.c
is written with error handling to ensure dialog box entries are consistent with the types of data that are to be included in the generated code. This error handling functionality is only needed in the S-function, and is not needed in the generated code.
To simplify your assignment, the file dp_read_assign.tlc
is included. You must:
dp_read.tlc
.This is the file you will need, dp_read_assign.tlc
. Copy it to dp_read.tlc
.
%% File : dp_read.tlc %% Abstract: %% Dual-Port Read block target file for S-function dp_read. %% %% Copyright (c) 1994-1999 by The MathWorks, Inc. All Rights Reserved. %% %implements "dp_read" "C" %% Function: Outputs ========================================================== %% Abstract: %% Dual port read for the dp_read.mex S-function, (e.g. dp_read.dll). %% Read the value from the specified address entered in the S-function %% parameters and write to the output location: %% Y = *dpAddress %% %% In the dp_read, the Parameters are defined to be: %% offset,gain,variableType,hardwareAddress %% %function Outputs(block, system) Output /* %<Type> Block: %<Identifier> */ { %% ONLY MAKE CHANGES TO THE CODE BELOW HERE! %% #1 and #2 %assign offset = CAST("Real",P1.Value[0]) %assign gain = %% COMPLETE THIS LINE - Look at mask for the %% dp_read block and also look at the .rtw file after %% generating it by using >> rtwgen dp %% %% #3 %assign varType = %% COMPLETE THIS LINE - using LibBlockParameterString %% see page 26 of TLC Quick Ref %% #4 %assign hwAddress = %% COMPLETE THIS LINE - similar to varType, except P4 %% #5 %assign y = %% COMPLETE THIS LINE - using LibBlockOutputSignal %% where portIdx=0, ucv="", lcv="", sigIdx=0 %% However, this model uses the "y" variable for the simple %% case of only a scalar output. See the LibBlockOutputSignal function %% on page 20 of the Target Language Quick Reference. %% The generated code for this block should appear as follows: %% %% volatile float *dpAddress = (float *) 0x40; %% rtB.s1_dual_port_read = ((real_T) *dpAddress) * 1.0 + 0.0; volatile %<varType> *dpAddress = %% COMPLETE THIS LINE %<y> = %% COMPLETE THIS LINE } %endfunction %% Outputs
![]() | Inlined S-Function for Dual Port RAM | Further Hints | ![]() |