%% %% $RCSfile: dsp_intbounds.tlc,v $ %% $Revision: 1.7 $ %% $Date: 1999/10/15 14:11:06 $ %% %% Copyright (c) 1995-1999 The MathWorks, Inc. %% %% Usage (from a block TLC): %% %% % \ %% %\ %% %include "dsplib.tlc" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Macro Definition Functions %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% POWER OF 2 MACROS %% %% %% %% Functions: %% %% ---------- %% %% Pow2CacheDefine: Write the definition in model.h. %% %% Pow2MacroDef: Generate the definition line. %% %% Pow2MacroName: Generate the POW2_N macro. %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: Pow2MacroName =================================================== %% Abstract: %% Pow2MacroName(N) %% Generate the string POW2_N where POW2_N is 2^N. %% (Called by Pow2MacroDef) %% Ex: POW2_3 %% %function Pow2MacroName(N) void %return "DSP_POW2_" + STRING(N) %endfunction %% Pow2MacroName %% Function: Pow2MacroDef ==================================================== %% Abstract: %% Pow2MacroDef(isSigned,N,Value) %% Generate the definition line as a string. %% (Called by Pow2CacheDefine). %% Ex: "#define POW2_3 8" %% %function Pow2MacroDef(isSigned,N,Value) void %return "#define " + Pow2MacroName(N) + " " + STRING(Value) %endfunction %% Pow2MacroDef %% Function: Pow2CacheDefine ================================================= %% Abstract: %% Pow2CacheDefine(N) %% Write the definition in the model.h file. %% %function Pow2CacheDefine(N) void %assign dataTypeMacro = Pow2MacroName(N) %% POW2_3, etc. %assign recordName = "dsp_" + dataTypeMacro %% Check info so that we do not redefine this macro more than once: %% %if JustCreatedCompiledModelRecord(recordName) %assign Pow2 = FEVAL("pow2", N) %assign strPow2 = Pow2MacroDef(isSigned,N,Pow2) + "\n" % %endif %endfunction %% Pow2CacheDefine %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% MAX, MIN INTEGER MACROS %% %% %% %% Functions: %% %% ---------- %% %% IntBoundCacheDefine: Write the definition in the model.h file %% %% IntBoundMacroDef: Generate the definition line %% %% IntBoundMacroName: Generate integer bound macro name %% %% IntMacroName: Generate integer macro name %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: IntMacroName ==================================================== %% Abstract: %% IntMacroName(isSigned,N) %% Generate integer macro name. %% (Called by IntBoundMacroName). %% %% Ex: UINT8, INT3 %% %function IntMacroName(isSigned,N) void %assign SignStr = (isSigned) ? "INT" : "UINT" %return "DSP_" + SignStr + STRING(N) %endfunction %% IntMacroName %% Function: IntBoundMacroName =============================================== %% Abstract: %% IntBoundMacroName(isSigned,N,Param) %% Generate integer bound (min/max) macro names. %% (Called by IntBoundMacroDef) %% %% Ex: UINT8_MAX, INT3_MIN %% %function IntBoundMacroName(isSigned,N,Param) void %return IntMacroName(isSigned,N) + "_" + Param %endfunction %% IntBoundMacroName %% Function: GetIntDataType ================================================== %% %% IntDataType(isSigned,N) %% Determine integer datatype needed for casting. %% %function GetIntDataType(isSigned,N) void %if isSigned %if (N <= 8) %return("int8_T") %elseif (N <= 16) %return("int16_T") %else %return("int32_T") %endif %else %if (N <= 8) %return("uint8_T") %elseif (N <= 16) %return("uint16_T") %else %return("uint32_T") %endif %endif %endfunction %% GetIntDataType %% Function: IntBoundMacroDef ================================================ %% Abstract: %% IntBoundMacroDef(isSigned,N,Param,Value) %% Generate the definition line as a string. %% %% Ex: "#define UINT5_MAX ((uint8_T)(32))" %% %function IntBoundMacroDef(isSigned,N,Param,Value) void %assign valueStr = "((" + GetIntDataType(isSigned,N) + ")(" + STRING(Value) + "))" %return "#define " + IntBoundMacroName(isSigned,N,Param) + " " + valueStr %endfunction %% IntBoundMacroDef %% Function: IntBoundCacheDefine ============================================= %% Abstract: %% IntBoundCacheDefine(isSigned,N) %% Write the definition in the model.h file. %% %function IntBoundCacheDefine(isSigned,N) void %assign dataTypeMacro = IntMacroName(isSigned,N) %% UINT8, etc. %assign recordName = "dsp_intbounds_" + dataTypeMacro %% Check info so that we do not redefine this macro more than once: %% %if JustCreatedCompiledModelRecord(recordName) %assign PowN = FEVAL("pow2", N) %assign LowerBnd = (isSigned) ? -PowN/2 : 0 %assign UpperBnd = (isSigned) ? PowN/2 - 1: PowN - 1 %assign strMin = IntBoundMacroDef(isSigned,N,"MIN",LowerBnd) + "\n" %assign strMax = IntBoundMacroDef(isSigned,N,"MAX",UpperBnd) + "\n" % % %endif %endfunction %% IntBoundCacheDefine %% [EOF] dsp_intbounds.tlc