%% %% Function-Call Code Generation for the DSP Blockset %% %% dsp_sfcncache.tlc - Cache buffer/file management functions for %% non-tunable S-function parameters. %% %% Author: D. Orofino %% Copyright (c) 1995-1999 The MathWorks, Inc. All Rights Reserved. %% $Revision: 1.2 $ % $Date: 1999/04/30 18:21:26 $ %% Function: DSPCacheSFcnParamList ================================================== %% Abstract: %% Cache the s-fcn param code %% %function DSPCacheSFcnParamList(buffer,useSeparator) void %if !EXISTS("DSPSFcnParamList") %openfile header /* * DSP Blockset S-Function non-tunable parameter list */ SFcnParameters rtSFcnP = { %% Begin structure element initialization %closefile header %assign DSPSFcnParamList = header %assign ::CompiledModel = ::CompiledModel + DSPSFcnParamList %% First buffer in list; no comma: %assign separator = "" %else %% Subsequent buffer in list; use comma: %assign separator = useSeparator ? ",\n" : "" %endif %assign ::CompiledModel.DSPSFcnParamList = ... ::CompiledModel.DSPSFcnParamList + separator + buffer %endfunction %% DSPCacheSFcnParamList %% Function: DSPWriteSFcnParamList ================================================== %% Abstract: %% Write out the S-fcn parameter list %% %function DSPWriteSFcnParamList() void %% Add a trailing comment to prototype definition section: %% %openfile buffer }; %% Close structure initialization /* (end of DSP Blockset s-function parameter list initialization) */ %closefile buffer % %% Cache the parameter definition prototypes to the model.h file: %% %% Place into model.prm: % %endfunction %% DSPWriteSFcnParamList %% Function: DSPCacheSFcnParamProto ================================================= %% Abstract: %% Create and cache the s-function parameter prototype %% %% Parameter prototype is: %% paramDataType blockIdentifier_paramName[vectLen] %% Ex: %% real_T s5_sdyad_HFILT[16]; %% %function DSPCacheSFcnParamProto(buffer) void %if !EXISTS("DSPSFcnParamProto") %openfile header /* * DSP Blockset S-Function non-tunable parameter definitions */ typedef struct SFcnParameters_tag { %% Begin structure definition %closefile header %assign DSPSFcnParamProto = header %assign ::CompiledModel = ::CompiledModel + DSPSFcnParamProto %endif %assign ::CompiledModel.DSPSFcnParamProto = ... ::CompiledModel.DSPSFcnParamProto + buffer + "\n" %endfunction %% DSPCacheSFcnParamProto %% Function: DSPWriteSFcnParamProto ================================================= %% Abstract: %% Write out the s-function param prototypes cache %% %function DSPWriteSFcnParamProto() void %% Add a trailing comment to prototype definition section: %% %openfile buffer } SFcnParameters; %% Close and name the structure definition /* (end of DSP Blockset s-function param definitions) */ %closefile buffer % %% Cache the parameter definition prototypes to the model.h file: %% % %endfunction %% DSPWriteSFcnParamProto %% Function: DSPAnySFcnParamsGenerated ============================================== %% Abstract: %% Determine if any param list was generated %% %% Assumes that if a param list was generated, then %% so were the corresponding param prototypes. %% %function DSPAnySFcnParamsGenerated() void %if EXISTS("::CompiledModel.DSPSFcnParamList") %return !WHITE_SPACE(::CompiledModel.DSPSFcnParamList) %else %return 0 %endif %endfunction %% DSPAnySFcnParamsGenerated %% Function: DSPWriteSFcnParams ===================================================== %% Abstract: %% Write out the s-function params and prototypes, and %% add the DSP s-function param file to the RTW's source list, %% if any s-function params were generated. %% %function DSPWriteSFcnParams() void %if DSPAnySFcnParamsGenerated() % % %endif %endfunction %% DSPWriteSFcnParams %% Function: DSPDefineSFcnParam ================================================= %% Abstract: %% %function DSPDefineSFcnParam(block,varStr) void %% Cache data type, complexity, variable name, data length, data %assign sfcnVar = "SFcnParamSettings." + varStr %assign sfcnDType = "SFcnParamSettings." + varStr + "_DTYPE" %assign sfcnValue = % %assign varName = block.Identifier + "_" + varStr %assign varDType = % %assign varSize = SIZE(sfcnValue) %assign varEle = varSize[0]*varSize[1] %assign varProto = varDType + " " + varName + "[" + STRING(varEle) + "];" %assign varComment = "/* Block: " + Name + ", Variable: " + varName + " */\n" %% Loop over each element of the parameter and build up %% a C-expression to initialize the variable. %% %% Need to do this in a loop to prevent the brackets ([...]) %% and to add commas between each element of a vector %% %assign varInit = "" %foreach i=varEle %assign prec = (i==0) ? "" : ", " %assign postc = (i==varEle-1) ? "" : ",\n" %if varDType == "real_T" %assign valueStr = STRING(sfcnValue[i]) %elseif varDType == "creal_T" %assign re_valueStr = STRING(REAL(sfcnValue[i])) %assign im_valueStr = STRING(IMAG(sfcnValue[i])) %assign valueStr = "{" + re_valueStr + ", " + im_valueStr + "}" %else %exit Unsupported data type "%"in S-Function parameter cache %endif %%assign varInit = varInit + prec + valueStr %assign varInit = varInit + valueStr + postc %endforeach %assign varInit = "{" + varInit + "}" % % %endfunction %% DSPDefineSFcnParam %% [EOF] dsp_sfcncache.tlc