static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 4); /* B,x0,U,P Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) return; else { if (CheckPar(S)) return; } ssSetNumContStates(S, (int) B(S,"CStates")); ssSetNumDiscStates(S, (int) B(S,"DStates")); if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, (int) (U(S,"Number")*B(S,"WaterIn")+B(S,"Setpoints"))); ssSetInputPortDirectFeedThrough(S, 0, (int) B(S,"Direct")); ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/ if (!ssSetNumOutputPorts(S,1)) return; ssSetOutputPortWidth(S, 0, (int) (U(S,"Number")*B(S,"WaterOut")+B(S,"Measurements")) ); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_USE_TLC_WITH_ACCELERATOR); }
/* * Input-output request */ LOCAL INT rwfn(BOOL rd, ID devid, INT start, INT size, void *buf, SDI sdi) { INT er; W dsz; switch (start) { case DN_CKEVENT: /* RW: Event notification message buffer ID */ er = CheckPar(size, dsz = sizeof(W)); if (er > E_OK) { if (rd) { *(W*)buf = evtMbf; } else { evtMbf = *(W*)buf; } } break; case DN_CKDATETIME: /* RW: Current time */ er = CheckPar(size, dsz = sizeof(DATE_TIM)); if (er > E_OK) { if (rd) { er = cdGetDateTime(buf); } else { er = cdSetDateTime(buf); } } break; case DN_CKAUTOPWON: /* RW: Automatic power-ON time */ er = CheckPar(size, dsz = sizeof(DATE_TIM)); if (er > E_OK) { if (rd) { er = cdGetAutoPwOn(buf); } else { er = cdSetAutoPwOn(buf); } } break; case DN_CKREGISTER: /* RW: Unvolatile register */ if (rd) { er = cdGetRegister(buf, size); } else { er = cdSetRegister(buf, size); } dsz = er; break; default: /* Data number error */ dsz = er = E_PAR; break; } if (er >= E_OK) { er = dsz; } else { DEBUG_PRINT(("rwData dn:%d err = %d\n", start, er)); } return er; }