%% $Revision: 1.6 $ %% $RCSfile: sndelay.tlc,v $ %% $Date: 1999/03/24 14:58:12 $ %% %% Murali Yeddanapudi, 28-May-1997 %% Copyright (c) 1995-1999 The MathWorks, Inc. All Rights Reserved. %% %% Abstract: Target file for the S-Function sndelay.c %% %implements "sndelay" "C" %% Function: BlockInstanceSetup =============================================== %% %% Abstract: %% Rename the S-Function parameter for easy reference. %% %function BlockInstanceSetup(block, system) void %% % % %% %if RWork[0] > 0 % %endif % %% %endfunction %% BlockInstanceSetup %% Function: InitializeConditions ============================================= %% %% Abstract: %% Initialize the RWork vector (Buffer) to the initial values specified. %% Note that the IWork is memset to zero in the registration function, %% however we need to initialize it to zero again here, because this block %% might be used inside an enabled subsystem that resets on disable. %% %function InitializeConditions(block, system) Output /* % Block: % (%) */ { %assign delayLen = SIZE(Delay.Value, 1) %assign icLen = SIZE(IC.Value, 1) %assign noutputs = LibDataOutputPortWidth(0) %% %% check if all delays are zero %if RWork[0] > 0 %if icLen == 1 int_T i; %assign ic = CAST("Real", LibBlockParameterValue(IC, 0)) for (i=0; i<%; i++) { % = %; } %else int_T i; %assign offset = 0 %foreach idx = noutputs %assign delay = CAST("Number", LibBlockParameterValue(Delay, idx)) %assign ic = CAST("Real", LibBlockParameterValue(IC, idx)) for (i=%; i<%; i++) { % = %; } %assign offset = offset + delay %endforeach %endif memset(&%, 0, %*sizeof(int_T)); %endif } %endfunction %% InitializeConditions %% Function: Outputs ========================================================== %% %% Abstract: %% %function Outputs(block, system) Output /* % Block: % (%) */ { %assign outputLen = LibDataOutputPortWidth(0) %% %if outputLen < RollThreshold %% %assign offset = 0 %foreach idx = outputLen %% %assign head = LibBlockIWork(Head,"","",idx) %assign indxStr = (offset == 0) ? "%" : "%+%" %assign delay = CAST("Number", LibBlockParameterValue(Delay, idx)) %assign offset = offset + delay %% %if delay != 0 %assign rhs = LibBlockRWork(Buffer, indxStr, "", 0) %else %assign rhs = LibBlockInputSignal(0, "", "", idx) %endif % = %; %% %endforeach %else %% If all delays are 0, no need to define buffer: %if RWork[0]>0 real_T *buffer = &%; real_T *y = %; %endif %% %assign delayLen = SIZE(Delay.Value, 1) %if delayLen == 1 %assign delay = CAST("Number", LibBlockParameterValue(Delay, 0)) %% %if delay != 0 int_T i, head = %; for (i=0; i<%; i++) { y[i] = buffer[head]; buffer += %; } %else %assign rollVars = ["U", "Y"] %roll idx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars % = %; %endroll %endif %else %assign noZeroDelays = 1 %foreach idx = delayLen %if noZeroDelays == 1 %assign delay = CAST("Number", LibBlockParameterValue(Delay, idx)) %assign noZeroDelays = (delay == 0) ? 0 : 1 %endif %endforeach %% %if noZeroDelays real_T *delay = %; int_T *head = &%; int_T i; for (i=0; i<%; i++) { y[i] = buffer[head[i]]; buffer += (int_T) delay[i]; } %else %if RWork[0] > 0 %assign rollVars = ["U", "IWork", "/Delay"] %else %assign rollVars = ["Y", "U", "IWork", "/Delay"] %endif %roll idx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars %assign head = LibBlockIWork(Head, "", lcv, idx) %assign delay = LibBlockParameter(Delay, "", lcv, idx) %assign lhs = (RWork[0] == 0) ? LibBlockOutputSignal(0, "", lcv, idx) : "*y++" if (((int_T) %) == 0) { % = %; } else { % = buffer[%]; %if lcv != "" || idx < (outputLen-1) buffer += (int_T) %; %endif } %endroll %endif %endif %endif } %endfunction %% Outputs %% Function: Update =========================================================== %% %% Abstract: %% %function Update(block, system) Output /* % Block: % (%) */ { %assign outputLen = LibDataOutputPortWidth(0) %% %if outputLen < RollThreshold %% %assign offset = 0 %assign headLen = IWork[0] %% %foreach idx = outputLen %assign delay = CAST("Number", LibBlockParameterValue(Delay, idx)) %if delay > 0 %assign head = LibBlockIWork(Head,"","",idx) %assign indxStr = (offset == 0) ? "%" : "%+%" %assign offset = offset + delay %% %assign lhs = LibBlockRWork(Buffer, indxStr, "", 0) % = %; %% %if (headLen > 1) if ( (++(%)) == % ) { % = 0; } %endif %endif %endforeach %% %assign delay = CAST("Number", LibBlockParameterValue(Delay, 0)) %if (delay > 0) && (headLen == 1) %assign head = LibBlockIWork(Head,"","",0) if ( (++(%)) == % ) { % = 0; } %endif %else %assign delayLen = SIZE(Delay.Value, 1) %% %if delayLen == 1 %assign delay = CAST("Number", LibBlockParameterValue(Delay, 0)) %if delay > 0 real_T *buffer = &%; int_T head = %; %assign rollVars = ["U"] %roll idx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars buffer[head] = %; %if lcv != "" || idx < (outputLen-1) buffer += %; %endif %endroll if ( (++head) == % ) { head = 0; } % = head; %endif %else real_T *buffer = &%; %assign rollVars = ["U", "IWork", "/Delay"] %roll idx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars %assign head = LibBlockIWork(Head, "", lcv, idx) %assign delay = LibBlockParameter(Delay, "", lcv, idx) if (((int_T) %) > 0) { buffer[%] = %; if ( (++(%)) == % ) { % = 0; } %if lcv != "" || idx < (outputLen-1) buffer += (int_T) %; %endif } %endroll %endif %endif } %endfunction %% Update %% EOF: sndelay.tlc