%% $Revision: 1.8 $ %% $RCSfile: sunbuffc.tlc,v $ %% $Date: 1999/03/24 14:58:18 $ %% %% Don Orofino, 09-Jul-97 %% Copyright (c) 1995-1999 The MathWorks, Inc. All Rights Reserved. %% %% Abstract: Target file for the S-Function sunbuffc.c %% %implements "sunbuffc" "C" %% Function: BlockInstanceSetup =============================================== %% %% Abstract: %% Rename the S-Function parameter for easy reference. %% %function BlockInstanceSetup(block, system) void %% % %% % %% % % %% %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 N = LibDataInputPortWidth(0) %if N == 1 /* (Unbuffering a scalar input - no initialization required) */ %else { real_T *circBuf = &%; real_T *outBuf = circBuf + %; int_T i1; % = (void *)circBuf; % = (void *)outBuf; for(i1 = 0; i1 < %; i1++) { *outBuf++ = 0.0; } } %endif %endfunction %% InitializeConditions %% Function: Outputs ========================================================== %% %% Abstract: %% %function Outputs(block, system) Output /* % Block: % (%) */ %assign N = LibDataInputPortWidth(0) %assign nchans = CAST("Number",LibBlockParameterValue(Num_Chans, 0)) %assign buffer_width = N / nchans %if N == 1 %% Scalar input signal and single channel: if (%) { % = %; } %else %% Vector input signal: { if (%) { /* Output the current sample: */ real_T *buf = &%; real_T *outBuf = %; %% %% Check for single-column unbuffering: %% %if nchans == 1 %% One channel (a vector) of data: % = *outBuf++; if (outBuf == buf + %<2*N>) { outBuf = buf; } %else %% Multiple channels (a matrix) of data: { real_T *p = outBuf++; int_T kcnt = %; while (kcnt-- > 0) { %if buffer_width == 1 % = *p++; %else % = *p; p += %; %endif } if (outBuf == buf + %) { outBuf = buf + %; /* wrap circular buffer */ } else if (outBuf == buf + %) { outBuf = buf; } } %endif % = (void *)outBuf; } if (%) { /* Store the next input vector: */ real_T *inBuf = %; %assign rollVars = ["U"] %roll sigIdx = RollRegions, lcv = RollThreshold, block,... "Roller", rollVars *inBuf++ = %; %endroll { real_T *buf = &%; if (inBuf == buf + %<2*N>) { inBuf = buf; /* wrap circular buffer */ } } % = (void *)inBuf; } } %endif %endfunction %% Outputs %% EOF: sunbuffc.tlc