%% $Revision: 1.10 $ %% $RCSfile: sdsptsfw.tlc,v $ %% $Date: 2000/06/15 20:37:51 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Target file for the S-Function sdsptsfw.c %% used for the Triggered Signal From Workspace block %implements "sdsptsfw" "C" %% Function: BlockInstanceSetup =============================================== %% %function BlockInstanceSetup(block, system) void % % % % % % %endfunction %% BlockInstanceSetup %% Start ====================================================================== %% Abstract: %% Initialize PWork pointer %% %function Start(block, system) Output /* DSP Blockset Triggered Signal From Workspace (%) - % */ %assign OUTPORT = 0 %assign cplx = LibBlockOutputSignalIsComplex(OUTPORT) %assign ic_cplx = (TYPE(InitCond.Value[0]) == "Complex") %assign outwidth = LibDataOutputPortWidth(OUTPORT) %assign ic_numelem = SIZE(InitCond.Value,0) * SIZE(InitCond.Value,1) %% %% Initial ouputs { real_T *y = (real_T *)%; int_T N = %; %% Scalar or empty initial condition %if (ic_numelem <= 1) %assign ic = LibBlockParameterValue(InitCond,"%0") %if LibIsEmpty(ic) %assign icre = 0.0 %assign icim = 0.0 %else %assign icre = LibBlockParameterValue(InitCond,"%0") %assign icim = !ic_cplx ? 0.0 : LibBlockParameterValue(InitCond,"%0") %endif %% while(N-- > 0) { *y++ = %; %if (cplx) *y++ = %; %endif } %else %% Vector for Matrix initial condition real_T *ic = (real_T *)%; while(N-- > 0) { *y++ = *ic++; %if (cplx) *y++ = *ic++; %endif } %endif } %% Put the workspace data into a static %%variable and store the address into a PWork. %assign WksPtrIdx = 0 %assign asgnStr = "" %assign initStr = "" %assign rows = CAST("Number",SIZE(WorkspaceVar.Value,0)) %assign cols = CAST("Number",SIZE(WorkspaceVar.Value,1)) %assign nterms = rows * cols %assign BufferName = "SignalData" %assign block = block + BufferName %% %if TYPE(WorkspaceVar.Value) != "Matrix" %% VECTOR or SCALAR Variable %foreach i = nterms %assign tui = CAST("Real",REAL(WorkspaceVar.Value[i])) %if !LibIsFinite(tui) %assign asgnStr = asgnStr + "%[%] = %;\n" %assign tui = 0.0 %endif %assign suffix = (!cplx && i==nterms-1) ? "" : "," %assign initStr = initStr + "%%\n" %if cplx %assign tui = CAST("Real",IMAG(WorkspaceVar.Value[i])) %if !LibIsFinite(tui) %assign asgnStr = asgnStr + "%[%] = %;\n" %assign tui = 0.0 %endif %assign suffix = (i == nterms-1) ? "" : "," %assign initStr = initStr + "%%\n" %endif %endforeach %else %% MATRIX Variable %foreach j =cols %foreach i = rows %assign tui = CAST("Real",REAL(WorkspaceVar.Value[i][j])) %if !LibIsFinite(tui) %assign asgnStr = asgnStr + "%[%] = %;\n" %assign tui = 0.0 %endif %assign suffix = (!cplx && i==nterms-1) ? "" : "," %assign initStr = initStr + "%%\n" %if cplx %assign tui = CAST("Real",IMAG(WorkspaceVar.Value[i][j])) %if !LibIsFinite(tui) %assign asgnStr = asgnStr + "%[%] = %;\n" %assign tui = 0.0 %endif %assign suffix = (i == nterms-1) ? "" : "," %assign initStr = initStr + "%%\n" %endif %endforeach %endforeach %endif %% %% Data can be declared constant if there are no non-finite values %% %if WHITE_SPACE(asgnStr) %assign prefix = "const" %else %assign prefix = "" %endif %if cplx %assign nterms = 2 * nterms %endif { static % real_T %[%] = { % }; %% %% Cache non-finite assignments %% %if asgnStr != "" /* (re)initialize non-finites */ % %endif % = (void *) &%[0]; } %% Initialize state: % = UNINITIALIZED_ZCSIG; % = 0; %endfunction %% Output ===================================================================== %% Abstract: %% Output data from matrix in Workspace %% %function Outputs(block, system) Output /* DSP Blockset Triggered Signal From Workspace (%) - % */ %assign OUTPORT = 0 %assign INPORT = 0 %assign WksPtrIdx = 0 %assign cplx = LibBlockOutputSignalIsComplex(OUTPORT) %assign cyclic = LibBlockParameterValue(Cyclic, 0) != 0 %assign trigtype = LibBlockParameterValue(TrigType, 0) %assign N = LibDataOutputPortWidth(OUTPORT) %% %assign RISING = 1 %assign FALLING = 2 %assign EITHER = 3 %% %if trigtype==RISING %assign zc_dir = "RISING_ZERO_CROSSING" %elseif trigtype==FALLING %assign zc_dir = "FALLING_ZERO_CROSSING" %else %assign zc_dir = "ANY_ZERO_CROSSING" %endif if(rt_ZCFcn(%, (ZCSigState *)(&%), %) != NO_ZCEVENT) { real_T *y = (real_T *)%; int_T outIdx = %; %assign Mwks = !cplx ? SIZE(WorkspaceVar.Value,0) : 2*SIZE(WorkspaceVar.Value,0) if(outIdx < %) { /* Output next matrix row. */ real_T *pwks = (real_T *)%; int_T i; %% for (i = 0; i < %; i++) { *y++ = *(pwks + outIdx + i*%); %if cplx *y++ = *(pwks + outIdx+1 + i*%); /* Complex part. */ %endif } %% %if cyclic } %else } else { %% /* Zero extend output: */ int_T i; for (i = 0; i < %; i++) { *y++ = 0.0; } } %endif %% /* Update row index for next read: */ %++; %if cplx %++; %endif %% %if cyclic /* Cyclic */ if(% == %) { % = 0; } %endif } %endfunction %% [EOF] sdsptsfwks.tlc