%%
%%
%%
%%Copyright2007TheMathWorks,Inc.
%%
%%Abstract:
%%ExampleofS-Functionthatgeneratesafunction-call
%%ntimesatthedesignatedrate(sampletime)
 
%implements sldemo_sfun_fcncallgen "C"
 
%%Function:Enable==============================================
%%Abstract:
%%Issueenableevents
%%
%function Enable(block,system) Output
  %openfile tmpBuffer
  %foreach fcnCallIdx = NumSFcnSysOutputCalls
    %% call the downstream system
    %with SFcnSystemOutputCall[fcnCallIdx]
      %% skip unconnected function call outputs
      %if LibIsEqual(BlockToCall, "unconnected")
    %continue
      %endif
      %assign sysIdx = BlockToCall[0]
      %assign blkIdx = BlockToCall[1]
      %assign ssBlock = System[sysIdx].Block[blkIdx]
      %assign tidVal = ParamSettings.SampleTimesToSet[0][1]
      %openfile tmp2Buffer
      %<LibExecuteFcnEnable(ssBlock, FcnPortElement, 0)>/
      %closefile tmp2Buffer
      %if (!WHITE_SPACE(tmp2Buffer))
    %<tmp2Buffer>/
      %endif
    %endwith
  %endforeach
  %closefile tmpBuffer
  %% output buffer
  %if !WHITE_SPACE(tmpBuffer)
    %assign type = ParamSettings.FunctionName
    %if !ISFIELD(system,"PreventComments") || system.PreventComments != "yes"
      /* Function-call Generator Block: '%<Name>' */
    %endif
    %<tmpBuffer>/
  %endif
%endfunction
 
%%Function:Disable==============================================
%%Abstract:
%%Issuedisableevents
%%
%function Disable(block,system) Output
  %openfile tmpBuffer
  %foreach fcnCallIdx = NumSFcnSysOutputCalls
    %% call the downstream system
    %with SFcnSystemOutputCall[fcnCallIdx]
      %% skip unconnected function call outputs
      %if LibIsEqual(BlockToCall, "unconnected")
    %continue
      %endif
      %assign sysIdx = BlockToCall[0]
      %assign blkIdx = BlockToCall[1]
      %assign ssBlock = System[sysIdx].Block[blkIdx]
      %assign tidVal = ParamSettings.SampleTimesToSet[0][1]
      %openfile tmp2Buffer
      %<LibExecuteFcnDisable(ssBlock, FcnPortElement, 0)>/
      %closefile tmp2Buffer
      %if (!WHITE_SPACE(tmp2Buffer))
    %<tmp2Buffer>/
      %endif
    %endwith
  %endforeach
  %closefile tmpBuffer
  %% output buffer
  %if !WHITE_SPACE(tmpBuffer)
    %assign type = ParamSettings.FunctionName
    %if !ISFIELD(system,"PreventComments") || system.PreventComments != "yes"
      /* Function-call Generator Block: '%<Name>' */
    %endif
    %<tmpBuffer>/
  %endif
%endfunction
 
%function Outputs(block, system) Output
  %openfile tmpBuffer
  %foreach fcnCallIdx = NumSFcnSysOutputCalls
    %% call the downstream system
    %with SFcnSystemOutputCall[fcnCallIdx]
      %% skip unconnected function call outputs
      %if LibIsEqual(BlockToCall, "unconnected")
    %continue
      %endif
      %assign sysIdx = BlockToCall[0]
      %assign blkIdx = BlockToCall[1]
      %assign ssBlock = System[sysIdx].Block[blkIdx]
      %assign num = SIZE(SFcnParamSettings.Counter, 1)
      %assign idx = (num > 1) ? fcnCallIdx : 0
      %assign count = CAST("Number",SFcnParamSettings.Counter[idx])
      %assign tidVal = ParamSettings.SampleTimesToSet[0][1]
      %openfile tmp2Buffer
      %<LibExecuteFcnCall(ssBlock, FcnPortElement, tidVal)>/
      %closefile tmp2Buffer
      %if (!WHITE_SPACE(tmp2Buffer))
    %if count > 1
      {
        int_T i = 0;
        for(i = 0; i < %<count> ; ++i){
    %endif
    %<tmp2Buffer>/
    %if count > 1
        }
      }
    %endif
      %endif
    %endwith
  %endforeach
  %closefile tmpBuffer
  %% output buffer
  %if !WHITE_SPACE(tmpBuffer)
    %assign type = ParamSettings.FunctionName
    %if !ISFIELD(system,"PreventComments") || system.PreventComments != "yes"
      /* Function-call Generator Block: '%<Name>' */
    %endif
    %<tmpBuffer>/
  %endif
%endfunction
 
%%[EOF]fcncallgen.tlc