%% 
%% $Revision: 1.1.6.2 $
%% 
%%
%% Copyright 1994-2003 The MathWorks, Inc.
%%
%% Abstract: Trigger port block target file

%implements TriggerPort "C"

%% Function: BlockInstanceSetup ==============================================
%% Abstract:
%%   Set expression folding compliance
%%
%function BlockInstanceSetup(block, system) void
  %<LibBlockSetIsExpressionCompliant(block)>
%endfunction


%% Function: Outputs ==========================================================
%% Abstract:
%%      The trigger block only updates its outputs when it resides in
%%      function-call subsystem.  Otherwise, the outputs for a trigger
%%      block are updated by the subsystem block in which the trigger
%%      block resides.
%%
%%      Note: tControlPortIdx is passed into the function-call subsystem
%%      OutputUpdate routine to index into appropriate element of the
%%      trigger port.
%%
%function Outputs(block, system) Output
  %assign sysIdx = system.CallSites[0][2]
  %assign blkIdx = system.CallSites[0][3]
  %assign ssBlock = System[sysIdx].Block[blkIdx]
  %if EXISTS("ssBlock.MaskType")
    %if ssBlock.MaskType == "Stateflow" && ...
      LibBlockOutputSignalWidth(0) == 1
      %% This means that this trigger block is within a Stateflow block and
      %% its width is 1.  It has already been declared Reusable and will not
      %% be needed by any of the Stateflow code. Hence, we do not declare
      %% even this local variable.
      %return ""
    %endif
  %endif
  %if ISEQUAL(ParamSettings.TriggerType, "function-call")
    %% Setup correct output data type
    %if LibBlockOutputSignalAliasedThruDataTypeId(0) == tSS_INT8
      %assign activeFC    = 2
      %assign inactiveFCs = 0
    %elseif LibBlockOutputSignalAliasedThruDataTypeId(0) == tSS_DOUBLE
      %assign activeFC    = 2.0
      %assign inactiveFCs = 0.0
    %else
      %%START_ASSERT
      %assign dTypeName = LibBlockOutputSignalDataTypeName(0,"")
      %assign errTxt = "The data type '%<dTypeName>' on the output port " ...
	"is not supported."
      %<LibBlockReportError(block, errTxt)>
      %%END_ASSERT
    %endif
    %assign rollVars = ["Y"]
    %assign rollRegions = [0:%<LibBlockOutputSignalWidth(0) - 1>]
    %if LibBlockOutputSignalWidth(0) > 1
      %<LibNeedCPI(system)>\
      %roll sigIdx = rollRegions, lcv = RollThreshold, block, "Roller", rollVars
	%<LibBlockOutputSignal(0, "", lcv, sigIdx)> = %<inactiveFCs>;
      %endroll
    %endif
    %<LibBlockOutputSignal(0, tControlPortIdx, "", 0)> = %<activeFC>;

  %endif
%endfunction

%% [EOF] trigport.tlc
