Differences From Artifact [3d56d803b8]:
- File mttroot/mtt/lib/rep/sfun_rep/sfun.cc.tmpl — part of check-in [0ff8fc3bca] at 2002-05-14 20:19:06 on branch origin/master — Fixed some memory leaks. (user: geraint@users.sourceforge.net, size: 3931) [annotate] [blame] [check-ins using] [more...]
To Artifact [cc87f430f2]:
- File
mttroot/mtt/lib/rep/sfun_rep/sfun.cc.tmpl
— part of check-in
[d9e3b30dc2]
at
2002-05-15 14:22:26
on branch origin/master
— Code for Simulink S-function target written direct to sfun.cc instead of
calling .mexglx files. This eliminates the sfun dependency on Octave
ColumnVectors. sys_sfun.cc should build directly on a MS Windows machine
(can't test this yet).added sfun.zip target to create source code to export. (user: geraint@users.sourceforge.net, size: 3634) [annotate] [blame] [check-ins using] [more...]
1 | // -*-c++-*- | | < > > > | | > | | > > | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | // -*-c++-*- // <mtt_model_name>_sfun.c: // Matlab S-function simulation of <mtt_model_name> #define S_FUNCTION_NAME <mtt_model_name>_sfun #define S_FUNCTION_LEVEL 2 #include "simstruc.h" #include "<mtt_model_name>_def.h" static mxArray *dX = mxCreateDoubleMatrix (MTTNX , 1, mxREAL); static mxArray *P = mxCreateDoubleMatrix (MTTNPAR , 1, mxREAL); static mxArray *T = mxCreateDoubleMatrix (1 , 1, mxREAL); static mxArray *U = mxCreateDoubleMatrix (MTTNU , 1, mxREAL); static mxArray *X = mxCreateDoubleMatrix (MTTNX , 1, mxREAL); static mxArray *Y = mxCreateDoubleMatrix (MTTNY , 1, mxREAL); static mxArray *YZ = mxCreateDoubleMatrix (MTTNYZ , 1, mxREAL); static double *mttdx = mxGetPr (dX); static double *mttu = mxGetPr (U); static double *mttpar = mxGetPr (P); static double *mttx = mxGetPr (X); static double *mtty = mxGetPr (Y); static double *mttyz = mxGetPr (YZ); static double *mtttp = mxGetPr (T); void update_parameters_from_simulink (SimStruct *S) { for (int i = 0; i < MTTNPAR; i++) { mttpar [i] = *mxGetPr (ssGetSFcnParam (S, i)); } } void update_states_from_simulink (SimStruct *S) { static double *x; x = ssGetContStates (S); for (int i = 0; i < MTTNX; i++) { mttx [i] = x [i]; } } void update_inputs_from_simulink (SimStruct *S) { for (int i = 0; i < MTTNU; i++) { mttu [i] = *ssGetInputPortRealSignalPtrs (S, i)[0]; } } void update_simtime_from_simulink (SimStruct *S) { mtttp [0] = ssGetT (S); } // S-function methods static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, MTTNPAR); |
︙ | ︙ | |||
89 90 91 92 93 94 95 | ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); } #define MDL_INITIALIZE_CONDITIONS static void mdlInitializeConditions(SimStruct *S) { | < < < < < < | | | < | > | > > > > | > | > | > > > > | > > | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < | | < < | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); } #define MDL_INITIALIZE_CONDITIONS static void mdlInitializeConditions(SimStruct *S) { update_parameters_from_simulink (S); #include "<mtt_model_name>_state.sfun" for (int i = 0; i < MTTNX; i++) { ssGetContStates (S)[i] = mttx [i]; } } static void mdlOutputs(SimStruct *S, int_T tid) { update_states_from_simulink (S); update_inputs_from_simulink (S); update_simtime_from_simulink (S); update_parameters_from_simulink (S); UNUSED_ARG(tid); // not used in single tasking mode #include "<mtt_model_name>_odeo.sfun" for (int i = 0; i < MTTNY; i++) { ssGetOutputPortRealSignal (S,i)[0] = mtty [i]; } } #define MDL_DERIVATIVES static void mdlDerivatives(SimStruct *S) { update_states_from_simulink (S); update_inputs_from_simulink (S); update_simtime_from_simulink (S); update_parameters_from_simulink (S); #include "<mtt_model_name>_ode.sfun" for (int i = 0; i < MTTNX; i++) { ssGetdX (S)[i] = mttdx [i]; } } static void mdlTerminate(SimStruct *S) { UNUSED_ARG(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 |