User`s guide
Implementing Device Drivers
10-15
The following example illustrates the definition of mdlInitializeSizes for a
DAC:
static void mdlInitializeSizes(SimStruct ∗S)
{
uint_T num_channels = mxGetPr(ssGetSFcnParam(S,0)[0]);
uint_T num_sample_times = mxGetPr(ssGetSFcnParams(S,1))[0])
ssSetNumSFcnParams(S, 3); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/* Return if number of expected != number of actual param’s */
return;
}
ssSetNumInputPorts(S, num_channels); /*Number of inputs is now
the number of
channels. */
ssSetNumOutputPorts(S, 0);
{
uint_T i;
for(i=0, i < num_channels, i++){
ssSetInputPortDirectFeedThrough(S,i,1);
}
}
ssSetNumSampleTimes(S, num_sample_times);
}
Initializing Sample Times
Device driver blocks are discrete blocks that require you to set a sample time.
Assuming that all channels run at the same rate, the S-function has only one
sample time — the sample time specified in the dialog box.
The following definition of
mdlInitializeSampleTimes reads the sample time
from the block’s dialog box. In this case, sample time is the second parameter
in the dialog box:
static void mdlInitializeSampleTimes(SimStruct ∗S)
{
ssSetSampleTime(S, 0, mxGetPr(ssGetSFcnParams(S,1))[0]);
ssSetOffsetTime(S, 0, 0.0);
}