static void mdlSetOutputPortWidth(SimStruct *S, int_T port, int_T outputPortWidth) { if( ((ssGetInputPortWidth(S, 0) != DYNAMICALLY_SIZED) && (ssGetInputPortWidth(S, 0) != outputPortWidth)) || \ ((ssGetOutputPortWidth(S, 1) != DYNAMICALLY_SIZED) && (ssGetOutputPortWidth(S, 1) != outputPortWidth)) ) { ssSetErrorStatus(S,"xdot and x must have the same size"); return; } if( intval(mxGetScalar(paramInitialConditionSource)) > 1 ) { if( (ssGetInputPortWidth(S, 1) != DYNAMICALLY_SIZED) && (ssGetInputPortWidth(S, 1) != outputPortWidth) ) { ssSetErrorStatus(S,"xdot, x0 and x must have the same size"); return; } ssSetInputPortWidth(S, 1, outputPortWidth); } else { if( (mxGetNumberOfElements(paramInitialCondition) != 1) && (mxGetNumberOfElements(paramInitialCondition) != outputPortWidth) ) { ssSetErrorStatus(S,"xdot, x0 and x must have the same size"); return; } } ssSetInputPortWidth(S, 0, outputPortWidth); ssSetOutputPortWidth(S, 1, outputPortWidth); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * Setup sizes of the various vectors. */ static void mdlInitializeSizes(SimStruct *S) { DECL_AND_INIT_DIMSINFO(inputDimsInfo); DECL_AND_INIT_DIMSINFO(outputDimsInfo); ssSetNumSFcnParams(S, NPARAMS); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } ssSetNumContStates(S, NUM_CONT_STATES); ssSetNumDiscStates(S, NUM_DISC_STATES); if (!ssSetNumInputPorts(S, NUM_INPUTS)) return; /*Input Port 0 */ ssSetInputPortWidth(S, 0, INPUT_0_WIDTH); /* */ ssSetInputPortDataType(S, 0, SS_UINT8); ssSetInputPortComplexSignal(S, 0, INPUT_0_COMPLEX); ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH); ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/ /*Input Port 1 */ ssSetInputPortWidth(S, 1, INPUT_1_WIDTH); ssSetInputPortDataType(S, 1, SS_UINT8); ssSetInputPortComplexSignal(S, 1, INPUT_1_COMPLEX); ssSetInputPortDirectFeedThrough(S, 1, INPUT_1_FEEDTHROUGH); ssSetInputPortRequiredContiguous(S, 1, 1); /*direct input signal access*/ /*Input Port 2 */ ssSetInputPortWidth(S, 2, INPUT_2_WIDTH); /* */ ssSetInputPortDataType(S, 2, SS_UINT8); ssSetInputPortComplexSignal(S, 2, INPUT_2_COMPLEX); ssSetInputPortDirectFeedThrough(S, 2, INPUT_2_FEEDTHROUGH); ssSetInputPortRequiredContiguous(S, 2, 1); /*direct input signal access*/ if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return; /* Output Port 0 */ ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH); ssSetOutputPortDataType(S, 0, SS_DOUBLE); ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX); /* Output Port 1 */ ssSetOutputPortWidth(S, 1, OUTPUT_1_WIDTH); ssSetOutputPortDataType(S, 1, SS_DOUBLE); ssSetOutputPortComplexSignal(S, 1, OUTPUT_1_COMPLEX); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetSimulinkVersionGeneratedIn(S, "8.4"); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_USE_TLC_WITH_ACCELERATOR | SS_OPTION_WORKS_WITH_CODE_REUSE)); }
static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, NPAR); if(ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) return; if(!ssSetNumInputPorts(S, NIN)) return; { int_T i; for(i = 0; i < NIN; i++){ ssSetInputPortDirectFeedThrough(S, i, 1); ssSetInputPortDataType(S, i, DYNAMICALLY_TYPED); } ssSetInputPortWidth(S, 0, IP0_SIZE); ssSetInputPortWidth(S, 1, IP1_SIZE); ssSetInputPortWidth(S, 2, IP2_SIZE); } if(!ssSetNumOutputPorts(S, NOUT)) return; { ssSetOutputPortWidth(S, 0, OP0_SIZE); ssSetOutputPortWidth(S, 1, OP1_SIZE); } ssSetNumSampleTimes(S, 1); sensorData.imuData_ptr = &imuData; sensorData.gpsData_ptr = &gpsData; sensorData.adData_ptr = &adData; sensorData.accelData_ptr = &accelData; init_control(); }
static void mdlInitializeSizes(SimStruct *S) { bool dataPort; ssSetNumSFcnParams(S,3); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } dataPort = PARAM(2)[0]; if (dataPort) { if (!ssSetNumInputPorts(S,2)) return; ssSetInputPortWidth(S,1,DYNAMICALLY_SIZED); ssSetInputPortDirectFeedThrough(S,1,1); } else { if (!ssSetNumInputPorts(S,1)) return; } ssSetInputPortWidth(S,0,1); ssSetInputPortDirectFeedThrough(S,0,1); ssSetNumContStates(S,0); ssSetNumDiscStates(S,0); if (!ssSetNumOutputPorts(S,0)) return; ssSetInputPortDataType(S, 0, DYNAMICALLY_TYPED); ssSetNumSampleTimes(S,1); ssSetNumRWork(S,1); ssSetNumIWork(S,1); ssSetNumPWork(S,2); ssSetNumModes(S,0); ssSetNumNonsampledZCs(S,0); ssSetOptions(S,0); }
static void mdlInitializeSizes(SimStruct *S) { int i; ssSetNumSFcnParams(S, NPARAMS); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /* Return if number of expected != number of actual parameters */ return; } for (i = 0; i < NPARAMS; i++) ssSetSFcnParamTunable(S, i, 0); ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 2)) return; ssSetInputPortWidth(S, 0, 7); ssSetInputPortRequiredContiguous(S, 0, true); ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortWidth(S, 1, DYNAMICALLY_SIZED); ssSetInputPortRequiredContiguous(S, 1, true); ssSetInputPortDirectFeedThrough(S, 1, 1); if (!ssSetNumOutputPorts(S, 1)) return; ssSetOutputPortWidth(S, 0, 12); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 5); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); }
/* Function: mdlInitializeSizes */ static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 19); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } ssSetNumContStates(S, 4); /* Number of continuous states*/ if (!ssSetNumInputPorts(S, 3)) return; /*Number of INPUTS*/ ssSetInputPortWidth(S, 0, 1); /* In0.0: I */ ssSetInputPortWidth(S, 1, 1); /* In1.0: x */ ssSetInputPortWidth(S, 2, 1); /* In1.0: dx */ ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); ssSetInputPortDirectFeedThrough(S, 2, 1); if (!ssSetNumOutputPorts(S, 1)) return;/* Number of OUTPUTS */ ssSetOutputPortWidth(S, 0, 1); /* Out0.0: deltaF */ ssSetNumSampleTimes(S, 1); ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); ssSetOptions(S, 0); }
/* Function: mdlSetDefaultPortDimensionInfo =============================== * Abstract: * This method is called when there is not enough information in your * model to uniquely determine the port dimensionality of signals * entering or leaving your block. When this occurs, Simulink's * dimension propagation engine calls this method to ask you to set * your S-functions default dimensions for any input and output ports * that are dynamically sized. * * If you do not provide this method and you have dynamically sized ports * where Simulink does not have enough information to propagate the * dimensionality to your S-function, then Simulink will set these unknown * ports to the 'block width' which is determined by examining any known * ports. If there are no known ports, the width will be set to 1. * */ static void mdlSetDefaultPortDimensionInfo(SimStruct *S) { /* Set input port 4 default dimension */ if (ssGetInputPortWidth(S, 3) == DYNAMICALLY_SIZED) { ssSetInputPortWidth(S, 3, 1); } /* Set input port 5 default dimension */ if (ssGetInputPortWidth(S, 4) == DYNAMICALLY_SIZED) { ssSetInputPortWidth(S, 4, 1); } }
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, NPARAMS); /* Number of expected parameters */ #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; /* Parameter mismatch will be reported by Simulink */ } #endif { int iParam = 0; int nParam = ssGetNumSFcnParams(S); for ( iParam = 0; iParam < nParam; iParam++ ) { ssSetSFcnParamTunable( S, iParam, SS_PRM_SIM_ONLY_TUNABLE ); } } ssSetNumContStates(S, NSTATES); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, NINPUTS)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 0, TRUE); ssSetInputPortWidth(S, 1, 1); ssSetInputPortDirectFeedThrough(S, 1, TRUE); ssSetInputPortWidth(S, 2, 1); ssSetInputPortDirectFeedThrough(S, 2, TRUE); if (!ssSetNumOutputPorts(S, NOUTPUTS)) return; //ssSetOutputPortWidth(S, 0, NOUTPUTS); { ssSetOutputPortWidth(S, 0, 1); } ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { /* See sfuntmpl_doc.c for more details on the macros below */ ssSetNumSFcnParams(S, 1); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /* Return if number of expected != number of actual parameters */ return; } ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 3)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortWidth(S, 1, 1); ssSetInputPortWidth(S, 2, 1); ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/ ssSetInputPortRequiredContiguous(S, 1, true); /*direct input signal access*/ ssSetInputPortRequiredContiguous(S, 2, true); /*direct input signal access*/ /* * Set direct feedthrough flag (1=yes, 0=no). * A port has direct feedthrough if the input is used in either * the mdlOutputs or mdlGetTimeOfNextVarHit functions. * See matlabroot/simulink/src/sfuntmpl_directfeed.txt. */ ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); ssSetInputPortDirectFeedThrough(S, 2, 1); if (!ssSetNumOutputPorts(S, 5)) return; ssSetOutputPortWidth(S, 0, 1); ssSetOutputPortWidth(S, 1, 1); ssSetOutputPortWidth(S, 2, 1); ssSetOutputPortWidth(S, 3, 1); ssSetOutputPortWidth(S, 4, 1); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); /* Specify the sim state compliance to be same as a built-in block */ ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); ssSetOptions(S, 0); }
static void setInputPorts(SimStruct * S){ if (P_ID == -1){ ssSetNumInputPorts(S,2); ssSetInputPortDataType(S,1,SS_UINT32); ssSetInputPortWidth(S,1,1); ssSetInputPortDirectFeedThrough(S,1,true); }else{ ssSetNumInputPorts(S,1); } ssSetInputPortRequiredContiguous(S,0,true); ssSetInputPortDataType(S,0,DYNAMICALLY_TYPED); ssSetInputPortDirectFeedThrough(S,0,true); ssSetInputPortWidth(S,0,DYNAMICALLY_SIZED); }
/*=====================================* * Configuration and execution methods * *=====================================*/ static void mdlInitializeSizes(SimStruct *S) { #ifdef DEBUG debug("mdlInitializeSizes entered.\n"); #endif ssSetNumSFcnParams(S, NPAR); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) return; } ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, NI); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S, 1)) return; ssSetOutputPortWidth(S, 0, NO); 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); #ifdef DEBUG debug("mdlInitializeSizes left.\n"); #endif } /* mdlInitializeSizes */
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { // loop counter int idx; ssSetNumSFcnParams(S, P_NPARMS); /* Number of expected parameters */ // No parameters will be tunable for(idx=0; idx<P_NPARMS; idx++){ ssSetSFcnParamNotTunable(S,idx); } if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /* Return if number of expected != number of actual parameters */ return; } // Setup all the CAN datatypes CAN_Common_MdlInitSizes(S); // Extended frame int_T canExDT = ssGetDataTypeId(S,SL_CAN_EXTENDED_FRAME_DTYPE_NAME ); // Standard frame int_T canStDT = ssGetDataTypeId(S,SL_CAN_STANDARD_FRAME_DTYPE_NAME ); // Setup input port ssSetNumInputPorts(S,1); ssSetInputPortWidth(S,0,1); ssSetInputPortDirectFeedThrough(S,0,true); ssSetInputPortDataType(S,0,DYNAMICALLY_TYPED); // Setup output ports ssSetNumOutputPorts(S,4); ssSetOutputPortWidth(S,0,1); /* ID */ ssSetOutputPortDataType(S,0, SS_DOUBLE); ssSetOutputPortWidth(S,1,1); /* Length */ ssSetOutputPortDataType(S,1, SS_DOUBLE); ssSetOutputPortWidth(S,2,1); /* Type */ ssSetOutputPortDataType(S,2, SS_DOUBLE); ssSetOutputPortWidth(S,3,1); /* Data */ ssSetOutputPortDataType(S,3, SS_DOUBLE); ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); /* use generated code in Accelerator Mode */ ssSetOptions(S, SS_OPTION_USE_TLC_WITH_ACCELERATOR); }
static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, N_PARAMS); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /* Return if number of expected != number of actual parameters */ return; } ssSetNumContStates(S, N_STATES); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, N_INPUTS); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S, 1)) return; ssSetOutputPortWidth(S, 0, N_OUTPUTS); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S, 0); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 0); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 2); if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 2); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S, 1)) return; ssSetOutputPortWidth(S, 0, 2); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * Setup sizes of the various vectors. */ static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 0); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, DYNAMICALLY_SIZED); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S,1)) return; ssSetOutputPortWidth(S, 0, DYNAMICALLY_SIZED); ssSetNumSampleTimes(S, 1); /* specify the sim state compliance to be same as a built-in block */ ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, SS_OPTION_WORKS_WITH_CODE_REUSE | SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_USE_TLC_WITH_ACCELERATOR); /*main();*/ }
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); }
static void mdlInitializeSizes(SimStruct *S) { int i; ssSetNumSFcnParams(S, NPARAMS); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /* Return if number of expected != number of actual parameters */ return; } for (i = 0; i < NPARAMS; i++) ssSetSFcnParamTunable(S, i, 0); ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 3); ssSetInputPortRequiredContiguous(S, 0, true); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S, 1)) return; ssSetOutputPortWidth(S, 0, 1); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S, SS_OPTION_WORKS_WITH_CODE_REUSE | SS_OPTION_USE_TLC_WITH_ACCELERATOR); }
void mdlInitializeSizes(SimStruct *S) /* ======================================================================== */ { /* parameters */ ssSetNumSFcnParams(S, NUM_PARAMS); #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) return; } else return; #endif ssSetSFcnParamTunable(S, FREQUENCY, SS_PRM_SIM_ONLY_TUNABLE); ssSetSFcnParamTunable(S, BANDWIDTH, SS_PRM_NOT_TUNABLE); ssSetSFcnParamTunable(S, TXVGA_GAIN, SS_PRM_SIM_ONLY_TUNABLE); /* ports */ ssSetNumSampleTimes(S, 1); if (!ssSetNumOutputPorts(S, 0) || !ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, DYNAMICALLY_SIZED); ssSetInputPortComplexSignal(S, 0, COMPLEX_YES); ssSetInputPortDataType(S, 0, SS_INT8); ssSetInputPortDirectFeedThrough(S, 0, true); ssSetInputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL); /* work Vectors */ ssSetNumPWork(S, P_WORK_LENGTH); ssSetNumIWork(S, 0); ssSetNumRWork(S, NUM_PARAMS); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); ssSetOptions(S, 0); }
static void set_input_port (SimStruct *S, int_T num, DTypeId type) { ssSetInputPortWidth (S, num, 1); ssSetInputPortDataType (S, num, type); ssSetInputPortComplexSignal (S, num, COMPLEX_NO); ssSetInputPortDirectFeedThrough (S, num, 1); ssSetInputPortRequiredContiguous (S, num, 1); /*direct input signal access*/ }
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { /* See sfuntmpl.doc for more details on the macros below */ ssSetNumSFcnParams(S, 0); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /* Return if number of expected != number of actual parameters */ return; } ssSetNumContStates(S, 1); /* how many continuous states? */ ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 1); /* * Set direct feedthrough flag (1=yes, 0=no). * A port has direct feedthrough if the input is used in either * the mdlOutputs or mdlGetTimeOfNextVarHit functions. * See matlabroot/simulink/src/sfuntmpl_directfeed.txt. */ ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S, 1)) return; ssSetOutputPortWidth(S, 0, 1); ssSetNumSampleTimes(S, 1); /* * If your Fortran code uses REAL for the state, input, and/or output * datatypes, use these DWorks as work areas to downcast continuous * states from double to REAL before calling your code. You could * also put the work vectors in hard-coded local (stack) variables. * * For fixed step code, keep a copy of the variables to be output * in a DWork vector so the mdlOutputs() function can provide output * data when needed. You can use as many DWork vectors as you like * for both input and output (or hard-code local variables). */ if(!ssSetNumDWork( S, 3)) return; ssSetDWorkWidth( S, 0, ssGetOutputPortWidth(S,0)); ssSetDWorkDataType( S, 0, SS_SINGLE); /* use SS_DOUBLE if needed */ ssSetDWorkWidth( S, 1, ssGetInputPortWidth(S,0)); ssSetDWorkDataType( S, 1, SS_SINGLE); ssSetDWorkWidth( S, 2, ssGetNumContStates(S)); ssSetDWorkDataType( S, 2, SS_SINGLE); ssSetNumNonsampledZCs(S, 0); /* Specify the sim state compliance to be same as a built-in block */ /* see sfun_simstate.c for example of other possible settings */ ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); ssSetOptions(S, 0); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * Setup sizes of the various vectors. */ static void mdlInitializeSizes(SimStruct *S) { slDataTypeAccess *dta = ssGetDataTypeAccess(S); int udtId; ssSetNumSFcnParams(S, 0); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /* Return if number of expected != number of actual parameters */ return; } /* Obtain an integer datatype ID for the udt (user-defined type) "Data" */ udtId = ssRegisterDataType(S, "Data"); if ( udtId == INVALID_DTYPE_ID ) return; /* Register the size of the udt */ if (!ssSetDataTypeSize(S, udtId, sizeof(Data))) return; /* Register the zero of the udt */ if (!ssSetDataTypeZero(S, udtId, &zero)) return; /* Register the convert-between datatype function defined above */ if (!dtaSetConvertBetweenFcn(dta, ssGetPath(S), udtId, &DataCnvBtw)) return; /* Register the is-positive datatype function defined above*/ if (!dtaSetIsPositiveFcn(dta, ssGetPath(S), udtId, &DataIsPos)) return; /* Set input-port properties */ if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDataType(S, 0, SS_DOUBLE); ssSetInputPortDirectFeedThrough(S, 0, 1); /* Set output port properties */ if (!ssSetNumOutputPorts(S, 1)) return; ssSetOutputPortDataType(S, 0, udtId); ssSetOutputPortWidth(S, 0, 1); /* Set miscellaneous properties */ ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); /* specify the sim state compliance to be same as a built-in block */ ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); ssSetOptions(S, SS_OPTION_WORKS_WITH_CODE_REUSE | SS_OPTION_USE_TLC_WITH_ACCELERATOR | SS_OPTION_DISALLOW_CONSTANT_SAMPLE_TIME | SS_OPTION_SFUNCTION_INLINED_FOR_RTW); }
static void mdlInitializeSizes(SimStruct *S) { int i,nChannels; static char msg[256]; ssSetNumSFcnParams(S, NUMBER_OF_ARGS); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /* Return if number of expected != number of actual parameters */ sprintf(msg,"Wrong Number of input arguments passed.\n%d arguments are expected\n",NUMBER_OF_ARGS); ssSetErrorStatus(S,msg); return; } ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); ssSetNumInputPorts(S, 0);//there is no input //if (!ssSetNumInputPorts(S, 1)) return; nChannels=(uint_T)mxGetN(CHANNEL_ARG); //if (!ssSetNumOutputPorts(S, 1)) return; ssSetNumOutputPorts(S,nChannels);//set number of outputs ports for(i=0;i<nChannels;i++) { ssSetOutputPortWidth(S, i, 1);//set width of each port to 1 } ssSetInputPortWidth(S, 0, 1); ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/ /* * Set direct feedthrough flag (1=yes, 0=no). * A port has direct feedthrough if the input is used in either * the mdlOutputs or mdlGetTimeOfNextVarHit functions. */ ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetNumSampleTimes(S, 1);//set number of sample time to 1,which means all input ports share same Ts ssSetNumRWork(S, NO_R_WORKS);//number of float in work vector ssSetNumIWork(S, NO_I_WORKS);//number of int in work vector ssSetNumPWork(S, 0);//number of pointer in work vector ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0);//no need for pass-zero check ssSetSFcnParamNotTunable(S,0); ssSetSFcnParamNotTunable(S,1); ssSetSFcnParamNotTunable(S,2); ssSetSFcnParamNotTunable(S,3); ssSetSFcnParamNotTunable(S,4); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE|SS_OPTION_PLACE_ASAP); /* Specify the sim state compliance to be same as a built-in block */ ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 0); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /* Return if number of expected != number of actual parameters */ return; } if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/ ssSetInputPortDirectFeedThrough(S, 0, 0); if (!ssSetNumOutputPorts(S, 2)) return; ssSetOutputPortWidth(S, 0, 1); ssSetOutputPortWidth(S, 1, 1); ssSetNumSampleTimes(S, 1); /* * Create a DWork data structure. */ { int dtId; /* * Use caution to avoid name conflicts when registering the * data type name. The suggested naming convention is to use * a common prefix based on your Blockset's name for each data type * registered by S-functions in your blocks set. If the S-function * is not part of a blockset, then use your company's name as a prefix. * The data type name is limited to 31 characters. */ dtId = ssRegisterDataType(S, "ExampleCounterStateStruct"); if (dtId == INVALID_DTYPE_ID ) return; /* Register the size of the udt */ if (!ssSetDataTypeSize(S, dtId, sizeof(CounterStateStruct))) return; ssSetNumDWork(S,1); ssSetDWorkDataType(S, 0, dtId); ssSetDWorkWidth(S, 0, 1); ssSetDWorkName(S, 0, "CSStruct"); /*optional name, less than 16 chars*/ } /* specify the sim state compliance to be same as a built-in block */ ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); ssSetOptions(S, SS_OPTION_WORKS_WITH_CODE_REUSE | SS_OPTION_RUNTIME_EXCEPTION_FREE_CODE | SS_OPTION_USE_TLC_WITH_ACCELERATOR); }
static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 0); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } /* no states, all computation will be done in output section */ ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); /* one input port: state x(k) + vector of references */ ssSetNumInputPorts(S, 1); /* one output port: control action */ ssSetNumOutputPorts(S, 1); /* width of input vector - number of states of the original problem. * note that tracking includes additional states, here we do not consider them */ if (MPT_TRACKING>0) { ssSetInputPortWidth(S, 0, MPT_NXT + MPT_NREF); } else { /* dimension extended by one to allow empty reference to be passed */ /*ssSetInputPortWidth(S, 0, MPT_NXT + 1); */ ssSetInputPortWidth(S, 0, MPT_NXT); } ssSetInputPortDirectFeedThrough(S, 0, 1); /* width of output - number of control actions */ ssSetOutputPortWidth(S, 0, MPT_NU); ssSetNumSampleTimes(S, 1); /* Take care when specifying exception free code - see sfuntmpl.doc */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); }
static void mdlInitializeSizes(SimStruct *S) { if (!ssSetNumInputPorts(S, 2)) return; ssSetInputPortWidth(S, 0, NUM_STATES); // x0 ssSetInputPortWidth(S, 1, 1); // reference ssSetInputPortDirectFeedThrough(S, 0, true); ssSetInputPortRequiredContiguous(S, 0, true); ssSetInputPortDirectFeedThrough(S, 1, true); ssSetInputPortRequiredContiguous(S, 1, true); ssSetNumPWork(S, 6); if (!ssSetNumOutputPorts(S, 4)) return; ssSetOutputPortWidth(S, 0, NUM_CONTROLS); ssSetOutputPortWidth(S, 1, NUM_STATES); ssSetOutputPortWidth(S, 2, 1); ssSetOutputPortWidth(S, 3, 1); ssSetNumSampleTimes(S, 1); }
void mdlSetInputPortWidth(SimStruct *S, int portIndex, int width) { if (width != protocol->p_input_width) { ssPrintf("AUTOSAR model expects an input port width of %u\n" "Tried to set %u\n", protocol->p_input_width, width); ssSetErrorStatus(S, "Tried to set port width not matching that specified" "by AUTOSAR model"); return; } ssSetInputPortWidth(S, portIndex, width); return; }
static void mdlInitializeSizes(SimStruct *S) { #ifdef MATLAB_MEX_FILE // mexEvalString( "startio;" ); #endif ssSetNumSFcnParams(S, NUMBER_OF_ARGS); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } if (!ssSetNumInputPorts(S, 8)) return; ssSetInputPortWidth(S, 0, 1); // PWMPrescaler / 1 / 0..63 ssSetInputPortDirectFeedThrough(S, 0, 0); ssSetInputPortWidth(S, 1, 3); // PWMWidth / 3 / -1..+1 [Z Y X] ssSetInputPortDirectFeedThrough(S, 1, 0); ssSetInputPortWidth(S, 2, 5); // EncoderReset / 5 / [YAngle XAngle Z Y X] ssSetInputPortDirectFeedThrough(S, 2, 0); ssSetInputPortWidth(S, 3, 3); // EncoderAutoReset / 3 / [Z Y X] ssSetInputPortDirectFeedThrough(S, 3, 0); ssSetInputPortWidth(S, 4, 3); // RailLimit / 3 / [Z Y X] [bit*64] ssSetInputPortDirectFeedThrough(S, 4, 0); ssSetInputPortWidth(S, 5, 3); // RailLimitFlag / 3 / [Z Y X] ssSetInputPortDirectFeedThrough(S, 5, 0); ssSetInputPortWidth(S, 6, 3); // ThermFlag / 3 / [Z Y X] ssSetInputPortDirectFeedThrough(S, 6, 0); ssSetInputPortWidth(S, 7, 1); // TmrCntReset / 1 ssSetInputPortDirectFeedThrough(S, 7, 0); if (!ssSetNumOutputPorts(S, 13)) return; ssSetOutputPortWidth(S, 0, 2 ); // Status / 1 / [LogicVersion ErrorCode] ssSetOutputPortWidth(S, 1, 1 ); // PWMPrescaler / 1 / 0..63 ssSetOutputPortWidth(S, 2, 3 ); // PWMWidth / 3 / -1..+1 [Z Y X] ssSetOutputPortWidth(S, 3, 5 ); // EncoderCounter / 5 / [YAngle XAngle Z Y X] [bit] ssSetOutputPortWidth(S, 4, 5 ); // EncoderReset / 3 / [YAngle XAngle Z Y X] ssSetOutputPortWidth(S, 5, 3 ); // EncoderAutoReset / 3 / [Z Y X] ssSetOutputPortWidth(S, 6, 3 ); // RailLimit / 3 / [Z Y X] [bit*64] ssSetOutputPortWidth(S, 7, 3 ); // RailLimitFlag / 3 / [Z Y X] ssSetOutputPortWidth(S, 8, 3 ); // LimitSwitch / 3 / [Z Y X] ssSetOutputPortWidth(S, 9, 3 ); // ThermStatus / 3 / [Z Y X] ssSetOutputPortWidth(S, 10, 3 ); // ThermFlag / 3 / [Z Y X] ssSetOutputPortWidth(S, 11, 1 ); // TmrCntCounter / 1 ssSetOutputPortWidth(S, 12, 1 ); // TmrCntReset / 1 ssSetNumSampleTimes(S, NSAMPLE_TIMES ); /* Take care when specifying exception free code */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * Setup sizes of the various vectors. */ static void mdlInitializeSizes(SimStruct *S) { slDataTypeAccess *dta = ssGetDataTypeAccess(S); int udtId; ssSetNumSFcnParams(S, 0); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /* Return if number of expected != number of actual parameters */ return; } /* Obtain an integer datatype ID for the udt (user-defined type) "Data" */ udtId = ssRegisterDataType(S, "Data"); if ( udtId == INVALID_DTYPE_ID ) return; /* Register the size of the udt */ if (!ssSetDataTypeSize(S, udtId, sizeof(Data))) return; /* Register the zero of the udt */ if (!ssSetDataTypeZero(S, udtId, &zero)) return; /* Set input-port properties */ if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDataType(S, 0, SS_DOUBLE); ssSetInputPortDirectFeedThrough(S, 0, 1); /* Set output port properties */ if (!ssSetNumOutputPorts(S, 1)) return; ssSetOutputPortDataType(S, 0, udtId); ssSetOutputPortWidth(S, 0, 1); /* Set miscellaneous properties */ ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); /* specify the sim state compliance to be same as a built-in block */ ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); ssSetOptions(S, SS_OPTION_WORKS_WITH_CODE_REUSE); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { /* setup the right number of parameters: distance, coelevation */ ssSetNumSFcnParams(S,0); if(ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)){ /* sfunction is initialised with the wrong number of parameters */ return; } /* set number of continnuert and discrete states. */ ssSetNumContStates(S, 0); /*zero continuert states*/ ssSetNumDiscStates(S, 0); /*zero discrete states*/ /* specify the number of inputs to 1 (|R_sc(I)| and coelecation) */ if (!ssSetNumInputPorts(S, 1)) return; /*wrong number of inputs*/ ssSetInputPortWidth(S, 0, 3); ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/ /* * Set direct feedthrough flag (1=yes, 0=no). * A port has direct feedthrough if the input is used in either * the mdlOutputs or mdlGetTimeOfNextVarHit functions. * See matlabroot/simulink/src/sfuntmpl_directfeed.txt. */ ssSetInputPortDirectFeedThrough(S, 0, 1); /* check if the output is setup right: gravitional potential of earth zonal harmonics. */ if (!ssSetNumOutputPorts(S, 1)) return; /*no output set*/ ssSetOutputPortWidth(S, 0, 3); ssSetNumSampleTimes(S, 1); }
/* Function: mdlInitializeSizes =============================================== * Abstract: * Setup sizes of the various vectors. */ static void mdlInitializeSizes(SimStruct *S) { DECL_AND_INIT_DIMSINFO(inputDimsInfo); DECL_AND_INIT_DIMSINFO(outputDimsInfo); ssSetNumSFcnParams(S, NPARAMS); /* Number of expected parameters */ #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; /* Parameter mismatch will be reported by Simulink */ } #endif ssSetNumContStates(S, NUM_CONT_STATES); ssSetNumDiscStates(S, NUM_DISC_STATES); if (!ssSetNumInputPorts(S, NUM_INPUTS)) return; ssSetInputPortWidth(S, 0, INPUT_0_WIDTH); ssSetInputPortDataType(S, 0, SS_INT16); ssSetInputPortComplexSignal(S, 0, INPUT_0_COMPLEX); ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH); ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/ if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return; ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetSimulinkVersionGeneratedIn(S, "8.3"); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_USE_TLC_WITH_ACCELERATOR | SS_OPTION_WORKS_WITH_CODE_REUSE)); }