/* 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); }
/* 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) { int_T status; // for new type definition DTypeId COM_HANDLE_id; // for new type definition HANDLE handle_aux; // for new type definition //====================================================== new type definition COM_HANDLE_id = ssRegisterDataType(S, "COM_HANDLE"); if(COM_HANDLE_id == INVALID_DTYPE_ID) return; status = ssSetDataTypeSize(S, COM_HANDLE_id, sizeof(handle_aux)); if(status == 0) return; status = ssSetDataTypeZero(S, COM_HANDLE_id, &handle_aux); if(status == 0) return; //=============================================================== parameters ssSetNumSFcnParams(S, 2); // 2 parameters: // - COM port // - baudrate //Parameter mismatch will be reported by Simulink if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) return; //=================================================================== inputs if (!ssSetNumInputPorts(S, 0)) return; // 0 inputs //================================================================== outputs if (!ssSetNumOutputPorts(S, 1)) return; // 1 outputs: // - COM handle ////////////////////////////// com handle ////////////////////////////// ssSetOutputPortWidth(S,0,1); // input 1 width ssSetOutputPortDataType(S, 0, COM_HANDLE_id); // input 1 datatype //============================================================= sample times ssSetNumSampleTimes( S, 1); // number of sample times //============================================================= work vectors ssSetNumRWork(S, 0); // 0 real work vector elements ssSetNumIWork(S, 0); // 0 work vector elements ssSetNumPWork(S, 1); // 1 pwork vector elements: // - COM handle ssSetNumModes(S, 0); // 0 mode work vector elements ssSetNumNonsampledZCs(S, 0); // 0 nonsampled zero crossings }
/* 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); }
static void mdlSetWorkWidths_c3_MPC_framework(SimStruct *S) { if(sim_mode_is_rtw_gen(S)) { int_T chartIsInlinable = (int_T)sf_is_chart_inlinable("MPC_framework",3); ssSetStateflowIsInlinable(S,chartIsInlinable); ssSetEnableFcnIsTrivial(S,1); ssSetDisableFcnIsTrivial(S,1); ssSetNotMultipleInlinable(S,sf_rtw_info_uint_prop("MPC_framework",3,"gatewayCannotBeInlinedMultipleTimes")); if(chartIsInlinable) { ssSetInputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL); ssSetInputPortOptimOpts(S, 1, SS_REUSABLE_AND_LOCAL); ssSetInputPortOptimOpts(S, 2, SS_REUSABLE_AND_LOCAL); ssSetInputPortOptimOpts(S, 3, SS_REUSABLE_AND_LOCAL); ssSetInputPortOptimOpts(S, 4, SS_REUSABLE_AND_LOCAL); ssSetInputPortOptimOpts(S, 5, SS_REUSABLE_AND_LOCAL); ssSetInputPortOptimOpts(S, 6, SS_REUSABLE_AND_LOCAL); ssSetInputPortOptimOpts(S, 7, SS_REUSABLE_AND_LOCAL); sf_mark_chart_expressionable_inputs(S,"MPC_framework",3,8); sf_mark_chart_reusable_outputs(S,"MPC_framework",3,3); } if (!sf_is_chart_instance_optimized_out("MPC_framework",3)) { int dtId; char *chartInstanceTypedefName = sf_chart_instance_typedef_name("MPC_framework",3); dtId = ssRegisterDataType(S, chartInstanceTypedefName); if (dtId == INVALID_DTYPE_ID ) return; /* Register the size of the udt */ if (!ssSetDataTypeSize(S, dtId, 8)) return; if(!ssSetNumDWork(S,1)) return; ssSetDWorkDataType(S, 0, dtId); ssSetDWorkWidth(S, 0, 1); ssSetDWorkName(S, 0, "ChartInstance"); /*optional name, less than 16 chars*/ sf_set_rtw_identifier(S); } ssSetHasSubFunctions(S,!(chartIsInlinable)); ssSetOptions(S,ssGetOptions(S)|SS_OPTION_WORKS_WITH_CODE_REUSE); } ssSetChecksum0(S,(1607393255U)); ssSetChecksum1(S,(1677787762U)); ssSetChecksum2(S,(2097080131U)); ssSetChecksum3(S,(3166642993U)); ssSetExplicitFCSSCtrl(S,1); }
static void mdlSetWorkWidths_c2_object_tracker_intensity(SimStruct *S) { if(sim_mode_is_rtw_gen(S)) { int_T chartIsInlinable = (int_T)sf_is_chart_inlinable("object_tracker_intensity",2); ssSetStateflowIsInlinable(S,chartIsInlinable); ssSetEnableFcnIsTrivial(S,1); ssSetDisableFcnIsTrivial(S,1); ssSetNotMultipleInlinable(S,sf_rtw_info_uint_prop("object_tracker_intensity",2,"gatewayCannotBeInlinedMultipleTimes")); if(chartIsInlinable) { ssSetInputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL); ssSetInputPortOptimOpts(S, 1, SS_REUSABLE_AND_LOCAL); ssSetInputPortOptimOpts(S, 2, SS_REUSABLE_AND_LOCAL); ssSetInputPortOptimOpts(S, 3, SS_REUSABLE_AND_LOCAL); sf_mark_chart_expressionable_inputs(S,"object_tracker_intensity",2,4); sf_mark_chart_reusable_outputs(S,"object_tracker_intensity",2,3); } if (!sf_is_chart_instance_optimized_out("object_tracker_intensity",2)) { int dtId; char *chartInstanceTypedefName = sf_chart_instance_typedef_name("object_tracker_intensity",2); dtId = ssRegisterDataType(S, chartInstanceTypedefName); if (dtId == INVALID_DTYPE_ID ) return; /* Register the size of the udt */ if (!ssSetDataTypeSize(S, dtId, 8)) return; if(!ssSetNumDWork(S,1)) return; ssSetDWorkDataType(S, 0, dtId); ssSetDWorkWidth(S, 0, 1); ssSetDWorkName(S, 0, "ChartInstance"); /*optional name, less than 16 chars*/ sf_set_rtw_identifier(S); } ssSetHasSubFunctions(S,!(chartIsInlinable)); ssSetOptions(S,ssGetOptions(S)|SS_OPTION_WORKS_WITH_CODE_REUSE); } ssSetChecksum0(S,(1312153194U)); ssSetChecksum1(S,(1014398065U)); ssSetChecksum2(S,(1024726701U)); ssSetChecksum3(S,(2475745997U)); ssSetExplicitFCSSCtrl(S,1); }
static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 0); if (S->mdlInfo->genericFcn != NULL) { _GenericFcn fcn = S->mdlInfo->genericFcn; (fcn)(S, GEN_FCN_CHK_MODELREF_SOLVER_TYPE_EARLY, 2, NULL); } ssSetRTWGeneratedSFcn(S, 2); ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 2)) return; if (!ssSetInputPortVectorDimension(S, 0, 1)) return; ssSetInputPortFrameData(S, 0, FRAME_NO); ssSetInputPortBusMode(S, 0, SL_NON_BUS_MODE) if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) { ssSetInputPortDataType(S, 0, SS_DOUBLE); } ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortRequiredContiguous(S, 0, 1); ssSetInputPortOptimOpts(S, 0, SS_NOT_REUSABLE_AND_GLOBAL); ssSetInputPortOverWritable(S, 0, FALSE); ssSetInputPortSampleTime(S, 0, 0.0); ssSetInputPortOffsetTime(S, 0, 0.0); if (!ssSetInputPortVectorDimension(S, 1, 1)) return; ssSetInputPortFrameData(S, 1, FRAME_NO); ssSetInputPortBusMode(S, 1, SL_NON_BUS_MODE) if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) { ssSetInputPortDataType(S, 1, SS_DOUBLE); } ssSetInputPortDirectFeedThrough(S, 1, 1); ssSetInputPortRequiredContiguous(S, 1, 1); ssSetInputPortOptimOpts(S, 1, SS_NOT_REUSABLE_AND_GLOBAL); ssSetInputPortOverWritable(S, 1, FALSE); ssSetInputPortSampleTime(S, 1, 0.0); ssSetInputPortOffsetTime(S, 1, 0.0); if (!ssSetNumOutputPorts(S, 1)) return; if (!ssSetOutputPortVectorDimension(S, 0, 1)) return; ssSetOutputPortFrameData(S, 0, FRAME_NO); ssSetOutputPortBusMode(S, 0, SL_NON_BUS_MODE) if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) { ssSetOutputPortDataType(S, 0, SS_DOUBLE); } ssSetOutputPortSampleTime(S, 0, 0.0); ssSetOutputPortOffsetTime(S, 0, 0.0); ssSetOutputPortOkToMerge(S, 0, SS_OK_TO_MERGE); ssSetOutputPortOptimOpts(S, 0, SS_NOT_REUSABLE_AND_GLOBAL); rt_InitInfAndNaN(sizeof(real_T)); { real_T minValue = rtMinusInf; real_T maxValue = rtInf; ssSetModelRefInputSignalDesignMin(S,0,&minValue); ssSetModelRefInputSignalDesignMax(S,0,&maxValue); } { real_T minValue = rtMinusInf; real_T maxValue = rtInf; ssSetModelRefInputSignalDesignMin(S,1,&minValue); ssSetModelRefInputSignalDesignMax(S,1,&maxValue); } { real_T minValue = rtMinusInf; real_T maxValue = rtInf; ssSetModelRefOutputSignalDesignMin(S,0,&minValue); ssSetModelRefOutputSignalDesignMax(S,0,&maxValue); } { static ssRTWStorageType storageClass[3] = { SS_RTW_STORAGE_AUTO, SS_RTW_STORAGE_AUTO, SS_RTW_STORAGE_AUTO }; ssSetModelRefPortRTWStorageClasses(S, storageClass); } ssSetNumSampleTimes(S, PORT_BASED_SAMPLE_TIMES); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumZeroCrossingSignals(S, 0); ssSetOutputPortIsNonContinuous(S, 0, 0); ssSetOutputPortIsFedByBlockWithModesNoZCs(S, 0, 0); ssSetInputPortIsNotDerivPort(S, 0, 1); ssSetInputPortIsNotDerivPort(S, 1, 1); ssSetModelReferenceSampleTimeInheritanceRule(S, DISALLOW_SAMPLE_TIME_INHERITANCE); ssSetOptimizeModelRefInitCode(S, 0); ssSetModelReferenceNormalModeSupport(S, MDL_START_AND_MDL_PROCESS_PARAMS_OK); ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_DISALLOW_CONSTANT_SAMPLE_TIME | SS_OPTION_SUPPORTS_ALIAS_DATA_TYPES | SS_OPTION_WORKS_WITH_CODE_REUSE | SS_OPTION_CALL_TERMINATE_ON_EXIT); if (S->mdlInfo->genericFcn != NULL) { ssRegModelRefChildModel(S,1,childModels); } #if SS_SFCN_FOR_SIM if (S->mdlInfo->genericFcn != NULL && ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) { mr_vdmultRM_MdlInfoRegFcn(S, "vdmultRM"); } #endif if (!ssSetNumDWork(S, 1)) { return; } #if SS_SFCN_FOR_SIM { int mdlrefDWTypeId; ssRegMdlRefDWorkType(S, &mdlrefDWTypeId); if (mdlrefDWTypeId == INVALID_DTYPE_ID ) return; if (!ssSetDataTypeSize(S, mdlrefDWTypeId, sizeof(rtMdlrefDWork_mr_vdmultRM))) return; ssSetDWorkDataType(S, 0, mdlrefDWTypeId); ssSetDWorkWidth(S, 0, 1); } #endif ssSetNeedAbsoluteTime(S, 1); }