|Target Language Compiler|
Loop Rolling Through a TLC File
%roll code is taken from the
Outputs function of
%% Function: Outputs ======================================= %% Abstract: %% Y = 2 * U %% %function Outputs(block, system) Output %assign fcnName = ParamSettings.FunctionName /* %<Type> Block: %<Name> (%<fcnName>) */ %assign rollVars = ["U", "Y"] %roll sigIdx=RollRegions, lcv=RollThreshold, block, ... "Roller", rollVars %assign u = LibBlockInputSignal(0, "", lcv, sigIdx) %assign y = LibBlockOutputSignal(0, "", lcv, sigIdx) %<y> = 2.0 * %<u>; %endroll %endfunction %% Outputs
Arguments for %roll
The lines between
%endroll may be either repeated or rolled. The key to understanding
%roll is in the arguments. Look at the
%roll line in detail.
%roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars
The first argument is
sigIdx. TLC uses
sigIdx to specify the appropriate index into a vector that is used in the generated code. Suppose you have a scalar signal, TLC looks at the
.rtw file and determines that only a single line of code is used and loop rolling is not needed. In this case, it will set
0 to be used to access only the first element of a vector.
Look at the second argument of
lcv, which is generally set in the
%roll line as
lcv = RollThreshold.
RollThreshold is a globally used threshold with the default value of
5. Therefore, where more than five contiguous and rollable variables exist, TLC will collapse the lines nested between
%endroll into a loop. If less than five contiguous rollable variables are found (for example, you build a block diagram where your block has only 4 inputs),
%roll will not create a loop and instead will produce individual lines of code.
The third argument should just be
block. This tells TLC that it is operating on block objects. Any TLC code for an S-function simply uses this argument as shown.
The fourth argument of
%roll is a string
Roller. Use this as is.
The fifth argument is
rollVars tells TLC which types of items should be rolled. Obvious choices include input signals, output signals, and parameters. It is not necessary to use all of them. In a previous line,
rollVars is defined using
%assign rollVars = ["U", "Y", "P"]
This list tells TLC that it is rolling on input signals, output signals, and parameters.
|Advanced External Mode Exercise||Input Signals, Output Signals, and Parameters|