Skip to Main Content Skip to Search
Product Documentation

ssWriteRTWParamSettings - Write values of nontunable parameters to the model.rtw file

Syntax

int_T ssWriteRTWParamSettings(SimStruct *S, int_T nParamSettings,
  int_T paramType, const char_T *settingName, ...)

Arguments

S

SimStruct representing an S-Function block.

nParamSettings

Number of parameter settings.

paramType

Type of parameter (see Parameter Setting Type-Specific Arguments).

settingName

Name of the parameter.

...

Remaining arguments depend on the parameter type (see Parameter Setting Type-Specific Arguments).

Returns

An int_T (1 or 0) or boolean_T (true or false) indicating the success or failure of the function.

Description

Use this function in mdlRTW to write nontunable parameter setting information to this S-function's model.rtw file. You can also use this macro to write out other constant values required to generate code for this S-function.

Parameter Setting Type-Specific Arguments

This section lists the parameter-specific arguments required by each parameter type.

Languages

C, C++

Example

See the S-function sfun_frmad.c used in sfcndemo_frame.mdl for a complete example that uses this function. Running this model requires a DSP System Toolbox license.

This S-function begins with the following variable declarations associated with the S-function parameters.

/* Parameters */
enum {FCN_ARGC = 0, AMP_ARGC,     FREQ_ARGC,     TS_ARGC, 
      FRMSIZE_ARGC, NOISAMP_ARGC, NOISFREQ_ARGC, NUM_ARGS};

#define FCN_ARG(S)      (ssGetSFcnParam(S,FCN_ARGC))
#define AMP_ARG(S)      (ssGetSFcnParam(S,AMP_ARGC))
#define FREQ_ARG(S)     (ssGetSFcnParam(S,FREQ_ARGC))
#define TS_ARG(S)       (ssGetSFcnParam(S,TS_ARGC))
#define FRMSIZE_ARG(S)  (ssGetSFcnParam(S,FRMSIZE_ARGC))
#define NOISAMP_ARG(S)  (ssGetSFcnParam(S,NOISAMP_ARGC))
#define NOISFREQ_ARG(S) (ssGetSFcnParam(S,NOISFREQ_ARGC))

#define GET_FRMSIZE(S)  (mxGetPr(FRMSIZE_ARG(S)))[0]

The S-function's mdlRTW function then uses ssWriteRTWParamSettings to write the S-function parameters to the model.rtw file.

real_T  noisA = mxGetPr(NOISAMP_ARG(S))[0];
real_T  noisF = mxGetPr(NOISFREQ_ARG(S))[0];
real_T  ts    = mxGetPr(TS_ARG(S))[0];
int_T   fcn   = (int) (mxGetPr(FCN_ARG(S))[0]);
int32_T fsize = mxGetPr(FRMSIZE_ARG(S))[0];

if (!ssWriteRTWParamSettings(S, 5,
     SSWRITE_VALUE_STR, "Function", (fcn == 1) ? "Constant" : "Sine",
     SSWRITE_VALUE_NUM, "Ts",       ts,
     SSWRITE_VALUE_DTYPE_NUM, "FrameSize", &fsize,
         DTINFO(SS_INT32, COMPLEX_NO),
     SSWRITE_VALUE_NUM, "NoiseAmp",  noisA,
     SSWRITE_VALUE_NUM, "NoiseFreq", noisF)) {
        return; /* An error occurred. */
    }

When code is generated for the model, the Simulink Coder product first writes a structure named SFcnParamSettings to the model.rtw file based on the information provided in the S-function's mdlRTW method. In this example, the resulting SFcnParamSettings is:

SFcnParamSettings {
	Function  Sine
	Ts        0.005
	FrameSize 64
	NoiseAmp  4.0
	NoiseFreq 80.0
      }

The S-function's Target Language Compiler file sfun_frmad.tlc then accesses the S-function parameters using the variable names in the SFcnParamSettings structure. For example:

%assign fnName   = SFcnParamSettings.Function
%assign frmSize  = SFcnParamSettings.FrameSize
%assign ts       = SFcnParamSettings.Ts
%assign noisA    = SFcnParamSettings.NoiseAmp
%assign noisF    = SFcnParamSettings.NoiseFreq

See Also

mdlRTW

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS