%% $RCSfile: sdspudecode.tlc,v $ %% $Revision: 1.5 $ %% $Date: 1999/04/28 19:53:45 $ %% %% Copyright (c) 1995-98 by The MathWorks, Inc. %% %% Abstract: Uniformly decodes input. %% Uniformly decode the input with positive and negative Peak value. %% The output datatype is double or single. Saturate or wrap in %% overflow mode. %implements sdspudecode "C" %include "dsplib.tlc" %include "dsp_intbounds.tlc" %% Function: BlockInstanceSetup ================================================ %function BlockInstanceSetup(block, system) void %% %assign INPORT = 0 %assign OUTPORT = 0 %assign block = block + INPORT + OUTPORT %% %assign isDouble = (LibBlockOutputSignalDataTypeId(OUTPORT) == tSS_DOUBLE) %assign sl_dtype_in = LibBlockInputSignalDataTypeName(INPORT,"") %assign dtype_cast = (isDouble) ? "Real" : "Real32" %% %assign dtype_in = GetDtypeInForContig(sl_dtype_in) %assign dtype_out = (isDouble) ? "real64_T" : "real32_T" %assign isSigned = IsInputPortSignedInt(sl_dtype_in) %assign N = CAST("Number",SFcnParamSettings.N) %assign V = CAST(dtype_cast,SFcnParamSettings.PEAK) %assign T = CAST(dtype_cast,SFcnParamSettings.T) %assign W = CAST(dtype_cast,SFcnParamSettings.W[0]) %assign isSaturate = CAST("Boolean",SFcnParamSettings.isSaturate) %% %assign block = block + isSigned + dtype_in + dtype_out \ + N + V + T + W + isSaturate %endfunction %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Uniform Decoder (%) - % */ %% % \ %\ %assign isCplx = (LibBlockInputSignalIsComplex(INPORT) != 0) %assign isContig = IsInputPortContiguous(block,INPORT) { % *y = (% *)%; % V = %; /* Peak */ % T = %; /* 2*V / 2^N */ %% %if isContig %% %assign width = LibDataInputPortWidth(INPORT) %if isCplx /* Treating contiguous complex input as a real double length input */ %assign width = width*2 %endif %% % *uptr = (% *)(%); %% int_T i1; for (i1=0; i1<%; i1++) { % u = *uptr++; % } %else %% %% Discontiguous input: %% %assign rollVars = ["U"] %roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars %if !isCplx % %else % %endif %endroll %endif } %endfunction %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Local Functions %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Input Characteristics Fcns %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: IsInputPortSignedInt %function IsInputPortSignedInt(sl_dtype_in) void %if ((sl_dtype_in == "cuint8_T") || (sl_dtype_in == "cuint16_T") || (sl_dtype_in == "cuint32_T") || \ (sl_dtype_in == "uint8_T") || (sl_dtype_in == "uint16_T") || (sl_dtype_in == "uint32_T")) %assign isSigned = 0 %else %assign isSigned = 1 %endif %return isSigned %% %endfunction %% IsInputPortSignedInt %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: GetDtypeInForContig %function GetDtypeInForContig(sl_dtype_in) void %if (sl_dtype_in == "cuint8_T") %return "uint8_T" %elseif (sl_dtype_in == "cuint16_T") %return "uint16_T" %elseif (sl_dtype_in == "cuint32_T") %return "uint32_T" %elseif (sl_dtype_in == "cint8_T") %return "int8_T" %elseif (sl_dtype_in == "cint16_T") %return "int16_T" %elseif (sl_dtype_in == "cint32_T") %return "int32_T" %else %return sl_dtype_in %endif %% %endfunction %% GetDtypeInForContig %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% DECODER (Real/Complex, Saturate, Wrap) Functions %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /%--------------------------------------------------%/ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: Wrap %function Wrap(block) Output { /* Wrap */ %assign LowerBoundMacro = IntBoundMacroName(isSigned,N,"MIN") %if (isSigned) %if ((dtype_in != "int32_T") && (dtype_in != "cint32_T")) % uTemp = u - %; u = (uTemp < 0) ? (%)(-((int_T)(-(uTemp)) % (int32_T)(%))) : (%)( (int_T) (uTemp) % (int32_T)(%)); if (u < 0) u -= %; else u += %; %endif %else %if ((dtype_in != "uint32_T") && (dtype_in != "cuint32_T")) u = (%)((uint32_T)u % (uint32_T)(%)); %endif %endif } %endfunction %% Wrap /%--------------------------------------------------%/ /%--------------------------------------------------%/ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: Saturate %function Saturate(block) Output /* Saturate */ %assign UpperBoundMacro = IntBoundMacroName(isSigned,N,"MAX") %assign LowerBoundMacro = IntBoundMacroName(isSigned,N,"MIN") %% if (u > %) u = (%); %if isSigned else if (u < %) u = %; %endif %endfunction %% Saturate /%--------------------------------------------------%/ /%--------------------------------------------------%/ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: HandleOverFlow %function HandleOverFlow(block) Output %% %if (isSaturate) %\ %else %\ %endif %% %endfunction %% %% Function: HandleOverFlow /%--------------------------------------------------%/ /%--------------------------------------------------%/ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: Decode %function Decode(block,lcv,sigIdx) Output %\ %assign expr = (W == 0) ? "(%)u" : "((%)u + (%)(%))" *y++ = % * T - V; %endfunction %% Decode /%--------------------------------------------------%/ /%--------------------------------------------------%/ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: DecodeReal %function DecodeReal(block,lcv,sigIdx) Output { % u = (%)(%); % } %endfunction %% DecodeReal /%--------------------------------------------------%/ /%--------------------------------------------------%/ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: DecodeCplx %function DecodeCplx(block,lcv,sigIdx) Output { % u = (%)(%%")>); % u = (%)(%%")>); % } %endfunction %% DecodeCplx /%--------------------------------------------------%/ %% [EOF] sdspudecode.tlc