%% $RCSfile: sdspsreg2.tlc,v $ %% $Revision: 1.2 $ %% $Date: 2000/05/04 13:17:34 $ %% %% Copyright (c) 1995-1999 The MathWorks, Inc. All Rights Reserved. %% %% Abstract: Shift contents of a memory register and store %% input samples into start of register. %implements sdspsreg2 "C" %% Function: BlockInstanceSetup =============================================== %% %function BlockInstanceSetup(block, system) void %assign INPORT = 0 %assign OUTPORT = 0 %assign block = block + INPORT + OUTPORT %% %assign cplx_in = (LibBlockInputSignalIsComplex(INPORT) != 0) %assign sl_dtype_in = LibBlockInputSignalDataTypeName(INPORT,"%") %assign dtype_in = (cplx_in) ? "c" + sl_dtype_in : sl_dtype_in %assign inWidth = CAST("Number",LibDataInputPortWidth(INPORT)) %assign isFrame = LibBlockInputSignalIsFrameData(INPORT) %assign dims = LibBlockInputSignalDimensions(INPORT) %assign nChans = (isFrame) ? dims[1]: inWidth %assign spf = (isFrame) ? dims[0] : 1 %assign regsiz = CAST("Number", SFcnParamSettings.RegSiz) %assign reglen = nChans * regsiz %assign outDtypeId = LibBlockOutputSignalDataTypeId(OUTPORT) %assign bytesPerRealElmt = SLibGetDataTypeSizeFromId(outDtypeId) %assign bpe = (cplx_in ? 2 : 1) * bytesPerRealElmt %% %assign block = block + cplx_in + sl_dtype_in + dtype_in \ + inWidth + isFrame + nChans \ + regsiz + reglen + spf + bytesPerRealElmt + bpe %% %% %endfunction %% BlockInstanceSetup %% Function: InitializeConditions ============================================= %% %function InitializeConditions(block, system) Output /* DSP Blockset Shift Register (%) - % */ %% %assign numIC = SIZE(SFcnParamSettings.IC, 1) %assign cplx_ic = LibIsComplex(SFcnParamSettings.IC) { /* Preset output buffers to initial conditions: */ %% % *outBuf = (% *)(%); %if (numIC == 1) %% %% Scalar IC: %% %assign IC_re = (numIC == 0) ? 0.0 : % %if (cplx_in) %assign IC_im = ((numIC == 0) | (!cplx_ic)) ? 0.0 : % %endif %% /* Scalar IC */ %if reglen > 1 int_T i; for (i=0; i++ < %; ) { %endif %if !cplx_in *outBuf++ = %<(numIC == 0) ? 0.0 : "%">; %else outBuf->re = %; (outBuf++)->im = %; %endif %if reglen > 1 } %endif %% %else %% %% Vector and Matrix ICs %% %% Write out ICs in formatted, vector form %if (cplx_ic) %assign ic_str = "" %foreach Idx = numIC-1 %if ((Idx != 0) & ((Idx%10) == 0)) %assign ic_str = ic_str + "{%,%},\n" %else %assign ic_str = ic_str + "{%,%}," %endif %endforeach %assign ic_str = ic_str + "{%,%}" const % ic[%] = {%}; %% %elseif (cplx_in) %assign ic_str = "" %foreach Idx = numIC-1 %if ((Idx != 0) & ((Idx%10) == 0)) %assign ic_str = ic_str + "{%,0.0},\n" %else %assign ic_str = ic_str + "{%,0.0}," %endif %endforeach %assign ic_str = ic_str + "{%,0.0}" const % ic[%] = {%}; %% %else %assign ic_str = "" %foreach Idx = numIC-1 %if ((Idx != 0) & ((Idx%10) == 0)) %assign ic_str = ic_str + "%,\n" %else %assign ic_str = ic_str + "%," %endif %endforeach %assign ic_str = ic_str + "%" const % ic[%] = {%}; %% %endif %% %% Copy ICs to buffer: %% %if (numIC == regsiz) /* Vector IC */ %if nChans != 1 int_T i; for (i=0; i++ < %; ) { %endif memcpy(outBuf, ic, %*sizeof(%)); outBuf += %; %if nChans != 1 } %endif %else /* Matrix IC */ memcpy(outBuf, ic, %*sizeof(%)); %endif %endif } %endfunction %% InitializeConditions %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Shift Register(%) - % */ { /* Copy contents of buffer to the output */ char_T *outBuf = (char_T *)(%); char_T *y = (char_T *)(%); memcpy(y, outBuf, %); } %endfunction %% Outputs %% Function: Update =========================================================== %% %function Update(block, system) Output /* DSP Blockset Shift Register(%) - % */ { %assign regsizBytes = regsiz*bpe %assign spfBytes = spf*bpe char_T *outBuf = (char_T *)(%); char_T *u = (char_T *)(%); %if (spf < regsiz) int_T i; for (i=0; i < %; i++) { char_T *p0 = outBuf; char_T *p1 = p0 + %; int_T k; /* Shift all but the last sample in each buffer column up by one * For simplicity, we move ALL samples up by one */ for(k=0; k++ < %; ) { memcpy(p0, p1, %); p0 += %; p1 += %; } /* Place input in last element of register for each channel */ p0 = outBuf - %; for (k = 0; k < %; k++) { char_T *u_tmp = u + k * %; p0 += %; memcpy(p0, u_tmp, %); } u += %; } %elseif (spf > regsiz) int_T i; u += %; for (i = 0; i < %; i++) { memcpy(outBuf, u, %); outBuf += %; u += %; } %else /* Register size and samples per frame are the same */ memcpy(outBuf, u, %); %endif } %endfunction %% Update %% [EOF] sdspsreg2.tlc