/* Copyright 2002-2004 The MathWorks, Inc. */ /* $Revision: 1.1.4.2 $ */ /* * File: sfbuilder_mport.c * * * * --- THIS FILE GENERATED BY S-FUNCTION BUILDER: 2.0 --- * * This file is an S-function produced by the S-Function * Builder which only recognizes certain fields. Changes made * outside these fields will be lost the next time the block is * used to load, edit, and resave this file. This file will be overwritten * by the S-function Builder block. If you want to edit this file by hand, * you must change it only in the area defined as: * * %%%-SFUNWIZ_defines_Changes_BEGIN * #define NAME 'replacement text' * %%% SFUNWIZ_defines_Changes_END * * DO NOT change NAME--Change the 'replacement text' only. * * For better compatibility with the Real-Time Workshop, the * "wrapper" S-function technique is used. This is discussed * in the Real-Time Workshop User's Manual in the Chapter titled, * "Wrapper S-functions". * * ------------------------------------------------------------------------- * | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template | * ------------------------------------------------------------------------- * Created: Thu May 16 10:32:22 2002 * * */ #define S_FUNCTION_NAME sfbuilder_mport #define S_FUNCTION_LEVEL 2 /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ /* %%%-SFUNWIZ_defines_Changes_BEGIN --- EDIT HERE TO _END */ #define NUM_INPUTS 2 /* Input Port 0 */ #define IN_PORT_0_NAME in1 #define INPUT_0_WIDTH 2 #define INPUT_DIMS_0_COL 3 #define INPUT_0_DTYPE real32_T #define INPUT_0_COMPLEX COMPLEX_NO #define IN_0_FRAME_BASED FRAME_NO #define IN_0_DIMS 2-D #define INPUT_0_FEEDTHROUGH 1 /* Input Port 1 */ #define IN_PORT_1_NAME in2 #define INPUT_1_WIDTH 2 #define INPUT_DIMS_1_COL 3 #define INPUT_1_DTYPE int32_T #define INPUT_1_COMPLEX COMPLEX_NO #define IN_1_FRAME_BASED FRAME_NO #define IN_1_DIMS 2-D #define INPUT_1_FEEDTHROUGH 1 #define NUM_OUTPUTS 2 /* Output Port 0 */ #define OUT_PORT_0_NAME out1 #define OUTPUT_0_WIDTH 2 #define OUTPUT_DIMS_0_COL 3 #define OUTPUT_0_DTYPE int8_T #define OUTPUT_0_COMPLEX COMPLEX_NO #define OUT_0_FRAME_BASED FRAME_NO #define OUT_0_DIMS 2-D /* Output Port 1 */ #define OUT_PORT_1_NAME out2 #define OUTPUT_1_WIDTH 2 #define OUTPUT_DIMS_1_COL 3 #define OUTPUT_1_DTYPE creal32_T #define OUTPUT_1_COMPLEX COMPLEX_YES #define OUT_1_FRAME_BASED FRAME_NO #define OUT_1_DIMS 2-D #define NPARAMS 0 #define SAMPLE_TIME_0 INHERITED_SAMPLE_TIME #define NUM_DISC_STATES 0 #define DISC_STATES_IC [0] #define NUM_CONT_STATES 0 #define CONT_STATES_IC [0] #define SFUNWIZ_GENERATE_TLC 1 #define SOURCEFILES "" #define PANELINDEX 0 #define SFUNWIZ_REVISION 2.0 /* %%%-SFUNWIZ_defines_Changes_END --- EDIT HERE TO _BEGIN */ /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ #include "simstruc.h" extern void sfbuilder_mport_Outputs_wrapper(const real32_T *in1, const int32_T *in2, int8_T *out1, creal32_T *out2); extern void sfbuilder_mport_Update_wrapper(const real32_T *in1, const int32_T *in2, const int8_T *out1, const creal32_T *out2 ); extern void sfbuilder_mport_Derivatives_wrapper(const real32_T *in1, const int32_T *in2, const int8_T *out1, const creal32_T *out2, real_T *dx ); /*====================* * S-function methods * *====================*/ /* 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 */ inputDimsInfo.width = INPUT_0_WIDTH; ssSetInputPortDimensionInfo(S, 0, &inputDimsInfo); ssSetInputPortMatrixDimensions( S ,0, INPUT_0_WIDTH, INPUT_DIMS_0_COL); ssSetInputPortFrameData(S, 0, IN_0_FRAME_BASED); ssSetInputPortDataType(S, 0, SS_SINGLE); ssSetInputPortComplexSignal(S, 0, INPUT_0_COMPLEX); ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH); ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/ /*Input Port 1 */ inputDimsInfo.width = INPUT_1_WIDTH; ssSetInputPortDimensionInfo(S, 1, &inputDimsInfo); ssSetInputPortMatrixDimensions( S ,1, INPUT_1_WIDTH, INPUT_DIMS_1_COL); ssSetInputPortFrameData(S, 1, IN_1_FRAME_BASED); ssSetInputPortDataType(S, 1, SS_INT32); ssSetInputPortComplexSignal(S, 1, INPUT_1_COMPLEX); ssSetInputPortDirectFeedThrough(S, 1, INPUT_1_FEEDTHROUGH); ssSetInputPortRequiredContiguous(S, 1, 1); /*direct input signal access*/ if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return; /*Output Port 0 */ outputDimsInfo.width = OUTPUT_0_WIDTH; ssSetOutputPortDimensionInfo(S, 0, &outputDimsInfo); ssSetOutputPortMatrixDimensions( S ,0, OUTPUT_0_WIDTH, OUTPUT_DIMS_0_COL); ssSetOutputPortFrameData(S, 0, OUT_0_FRAME_BASED); ssSetOutputPortDataType(S, 0, SS_INT8); ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX); /*Output Port 1 */ outputDimsInfo.width = OUTPUT_1_WIDTH; ssSetOutputPortDimensionInfo(S, 1, &outputDimsInfo); ssSetOutputPortMatrixDimensions( S ,1, OUTPUT_1_WIDTH, OUTPUT_DIMS_1_COL); ssSetOutputPortFrameData(S, 1, OUT_1_FRAME_BASED); ssSetOutputPortDataType(S, 1, SS_SINGLE); ssSetOutputPortComplexSignal(S, 1, OUTPUT_1_COMPLEX); 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 | SS_OPTION_WORKS_WITH_CODE_REUSE)); } # define MDL_SET_INPUT_PORT_FRAME_DATA static void mdlSetInputPortFrameData(SimStruct *S, int_T port, Frame_T frameData) { ssSetInputPortFrameData(S, port, frameData); } /* Function: mdlInitializeSampleTimes ========================================= * Abstract: * Specifiy the sample time. */ static void mdlInitializeSampleTimes(SimStruct *S) { ssSetSampleTime(S, 0, SAMPLE_TIME_0); ssSetOffsetTime(S, 0, 0.0); ssSetModelReferenceSampleTimeDefaultInheritance(S); } #define MDL_SET_INPUT_PORT_DATA_TYPE static void mdlSetInputPortDataType(SimStruct *S, int port, DTypeId dType) { ssSetInputPortDataType( S, 0, dType); } #define MDL_SET_OUTPUT_PORT_DATA_TYPE static void mdlSetOutputPortDataType(SimStruct *S, int port, DTypeId dType) { ssSetOutputPortDataType(S, 0, dType); } #define MDL_SET_DEFAULT_PORT_DATA_TYPES static void mdlSetDefaultPortDataTypes(SimStruct *S) { ssSetInputPortDataType( S, 0, SS_DOUBLE); ssSetOutputPortDataType(S, 0, SS_DOUBLE); } /* Function: mdlOutputs ======================================================= * */ static void mdlOutputs(SimStruct *S, int_T tid) { const real32_T *in1 = (const real32_T*) ssGetInputPortSignal(S,0); const int32_T *in2 = (const int32_T*) ssGetInputPortSignal(S,1); int8_T *out1 = (int8_T *)ssGetOutputPortRealSignal(S,0); creal32_T *out2 = (creal32_T *)ssGetOutputPortRealSignal(S,1); sfbuilder_mport_Outputs_wrapper(in1,in2,out1,out2); } #undef MDL_UPDATE /* Change to #define to use the function */ #if defined(MDL_UPDATE) /* Function: mdlUpdate ====================================================== * Abstract: * This function is called once for every major integration time step. * Discrete states are typically updated here, but this function is useful * for performing any tasks that should only take place once per * integration step. */ static void mdlUpdate(SimStruct *S, int_T tid) { const real32_T *in1 = (const real32_T*) ssGetInputPortSignal(S,0); const int32_T *in2 = (const int32_T*) ssGetInputPortSignal(S,1); real_T *xD = ssGetDiscStates(S); int8_T *out1 = (int8_T *)ssGetOutputPortRealSignal(S,0); creal32_T *out2 = (creal32_T *)ssGetOutputPortRealSignal(S,1); sfbuilder_mport_Update_wrapper(in1,in2,out1,out2); } #endif /* MDL_UPDATE */ #undef MDL_DERIVATIVES /* Change to #define to use function */ #if defined(MDL_DERIVATIVES) /* Function: mdlDerivatives ================================================= * Abstract: * In this function, you compute the S-function block's derivatives. * The derivatives are placed in the derivative vector, ssGetdX(S). */ static void mdlDerivatives(SimStruct *S) { const real32_T *in1 = (const real32_T*) ssGetInputPortSignal(S,0); const int32_T *in2 = (const int32_T*) ssGetInputPortSignal(S,1); real_T *dx = ssGetdX(S); real_T *xC = ssGetContStates(S); int8_T *out1 = (int8_T *) ssGetOutputPortRealSignal(S,0); creal32_T *out2 = (creal32_T *) ssGetOutputPortRealSignal(S,1); sfbuilder_mport_Derivatives_wrapper(in1,in2,out1,out2, dx); } #endif /* MDL_DERIVATIVES */ /* Function: mdlTerminate ===================================================== * Abstract: * No termination needed, but we are required to have this routine. */ static void mdlTerminate(SimStruct *S) { } #ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */ #include "simulink.c" /* MEX-file interface mechanism */ #else #include "cg_sfun.h" /* Code generation registration function */ #endif