1 | /* |
2 | * File: SMD_TF.c |
3 | * |
4 | * Code generated for Simulink model 'SMD_TF'. |
5 | * |
6 | * Model version : 1.7 |
7 | * Simulink Coder version : 8.10 (R2016a) 10-Feb-2016 |
8 | * C/C++ source code generated on : Sun Jun 05 15:55:07 2016 |
9 | * |
10 | * Target selection: ert.tlc |
11 | * Embedded hardware selection: ARM Compatible->ARM Cortex |
12 | * Code generation objectives: |
13 | * 1. Execution efficiency |
14 | * 2. RAM efficiency |
15 | * Validation result: Not run |
16 | */ |
17 | |
18 | #include "SMD_TF.h" |
19 | |
20 | /* Private macros used by the generated code to access rtModel */ |
21 | #ifndef rtmIsMajorTimeStep |
22 | # define rtmIsMajorTimeStep(rtm) (((rtm)->Timing.simTimeStep) == MAJOR_TIME_STEP) |
23 | #endif |
24 | |
25 | #ifndef rtmIsMinorTimeStep |
26 | # define rtmIsMinorTimeStep(rtm) (((rtm)->Timing.simTimeStep) == MINOR_TIME_STEP) |
27 | #endif |
28 | |
29 | #ifndef rtmGetTPtr |
30 | # define rtmGetTPtr(rtm) ((rtm)->Timing.t) |
31 | #endif |
32 | |
33 | #ifndef rtmSetTPtr |
34 | # define rtmSetTPtr(rtm, val) ((rtm)->Timing.t = (val)) |
35 | #endif |
36 | |
37 | /* Continuous states */ |
38 | X rtX; |
39 | |
40 | /* Block signals and states (auto storage) */ |
41 | DW rtDW; |
42 | |
43 | /* Real-time model */ |
44 | RT_MODEL rtM_; |
45 | RT_MODEL *const rtM = &rtM_; |
46 | |
47 | /* private model entry point functions */ |
48 | extern void SMD_TF_derivatives(void); |
49 | |
50 | /* |
51 | * This function updates continuous states using the ODE4 fixed-step |
52 | * solver algorithm |
53 | */ |
54 | static void rt_ertODEUpdateContinuousStates(RTWSolverInfo *si ) |
55 | { |
56 | time_T t = rtsiGetT(si); |
57 | time_T tnew = rtsiGetSolverStopTime(si); |
58 | time_T h = rtsiGetStepSize(si); |
59 | real_T *x = rtsiGetContStates(si); |
60 | ODE4_IntgData *id = (ODE4_IntgData *)rtsiGetSolverData(si); |
61 | real_T *y = id->y; |
62 | real_T *f0 = id->f[0]; |
63 | real_T *f1 = id->f[1]; |
64 | real_T *f2 = id->f[2]; |
65 | real_T *f3 = id->f[3]; |
66 | real_T temp; |
67 | int_T i; |
68 | int_T nXc = 2; |
69 | rtsiSetSimTimeStep(si,MINOR_TIME_STEP); |
70 | |
71 | /* Save the state values at time t in y, we'll use x as ynew. */ |
72 | (void) memcpy(y, x, |
73 | (uint_T)nXc*sizeof(real_T)); |
74 | |
75 | /* Assumes that rtsiSetT and ModelOutputs are up-to-date */ |
76 | /* f0 = f(t,y) */ |
77 | rtsiSetdX(si, f0); |
78 | SMD_TF_derivatives(); |
79 | |
80 | /* f1 = f(t + (h/2), y + (h/2)*f0) */ |
81 | temp = 0.5 * h; |
82 | for (i = 0; i < nXc; i++) { |
83 | x[i] = y[i] + (temp*f0[i]); |
84 | } |
85 | |
86 | rtsiSetT(si, t + temp); |
87 | rtsiSetdX(si, f1); |
88 | SMD_TF_step(); |
89 | SMD_TF_derivatives(); |
90 | |
91 | /* f2 = f(t + (h/2), y + (h/2)*f1) */ |
92 | for (i = 0; i < nXc; i++) { |
93 | x[i] = y[i] + (temp*f1[i]); |
94 | } |
95 | |
96 | rtsiSetdX(si, f2); |
97 | SMD_TF_step(); |
98 | SMD_TF_derivatives(); |
99 | |
100 | /* f3 = f(t + h, y + h*f2) */ |
101 | for (i = 0; i < nXc; i++) { |
102 | x[i] = y[i] + (h*f2[i]); |
103 | } |
104 | |
105 | rtsiSetT(si, tnew); |
106 | rtsiSetdX(si, f3); |
107 | SMD_TF_step(); |
108 | SMD_TF_derivatives(); |
109 | |
110 | /* tnew = t + h |
111 | ynew = y + (h/6)*(f0 + 2*f1 + 2*f2 + 2*f3) */ |
112 | temp = h / 6.0; |
113 | for (i = 0; i < nXc; i++) { |
114 | x[i] = y[i] + temp*(f0[i] + 2.0*f1[i] + 2.0*f2[i] + f3[i]); |
115 | } |
116 | |
117 | rtsiSetSimTimeStep(si,MAJOR_TIME_STEP); |
118 | } |
119 | |
120 | /* Model step function */ |
121 | void SMD_TF_step(void) |
122 | { |
123 | real_T currentTime; |
124 | if (rtmIsMajorTimeStep(rtM)) { |
125 | /* set solver stop time */ |
126 | rtsiSetSolverStopTime(&rtM->solverInfo,((rtM->Timing.clockTick0+1)* |
127 | rtM->Timing.stepSize0)); |
128 | } /* end MajorTimeStep */ |
129 | |
130 | /* Update absolute time of base rate at minor time step */ |
131 | if (rtmIsMinorTimeStep(rtM)) { |
132 | rtM->Timing.t[0] = rtsiGetT(&rtM->solverInfo); |
133 | } |
134 | |
135 | /* Step: '<Root>/Step' */ |
136 | currentTime = rtM->Timing.t[0]; |
137 | rtDW.Step = !(currentTime < 0.0); |
138 | if (rtmIsMajorTimeStep(rtM)) { |
139 | rt_ertODEUpdateContinuousStates(&rtM->solverInfo); |
140 | |
141 | /* Update absolute time for base rate */ |
142 | /* The "clockTick0" counts the number of times the code of this task has |
143 | * been executed. The absolute time is the multiplication of "clockTick0" |
144 | * and "Timing.stepSize0". Size of "clockTick0" ensures timer will not |
145 | * overflow during the application lifespan selected. |
146 | */ |
147 | ++rtM->Timing.clockTick0; |
148 | rtM->Timing.t[0] = rtsiGetSolverStopTime(&rtM->solverInfo); |
149 | |
150 | { |
151 | /* Update absolute timer for sample time: [0.1s, 0.0s] */ |
152 | /* The "clockTick1" counts the number of times the code of this task has |
153 | * been executed. The resolution of this integer timer is 0.1, which is the step size |
154 | * of the task. Size of "clockTick1" ensures timer will not overflow during the |
155 | * application lifespan selected. |
156 | */ |
157 | rtM->Timing.clockTick1++; |
158 | } |
159 | } /* end MajorTimeStep */ |
160 | } |
161 | |
162 | /* Derivatives for root system: '<Root>' */ |
163 | void SMD_TF_derivatives(void) |
164 | { |
165 | XDot *_rtXdot; |
166 | _rtXdot = ((XDot *) rtM->ModelData.derivs); |
167 | |
168 | /* Derivatives for TransferFcn: '<Root>/Transfer Fcn' */ |
169 | _rtXdot->TransferFcn_CSTATE[0] = 0.0; |
170 | _rtXdot->TransferFcn_CSTATE[0] += -0.0 * rtX.TransferFcn_CSTATE[0]; |
171 | _rtXdot->TransferFcn_CSTATE[1] = 0.0; |
172 | _rtXdot->TransferFcn_CSTATE[0] += -10.0 * rtX.TransferFcn_CSTATE[1]; |
173 | _rtXdot->TransferFcn_CSTATE[1] += rtX.TransferFcn_CSTATE[0]; |
174 | _rtXdot->TransferFcn_CSTATE[0] += rtDW.Step; |
175 | } |
176 | |
177 | /* Model initialize function */ |
178 | void SMD_TF_initialize(void) |
179 | { |
180 | /* Registration code */ |
181 | { |
182 | /* Setup solver object */ |
183 | rtsiSetSimTimeStepPtr(&rtM->solverInfo, &rtM->Timing.simTimeStep); |
184 | rtsiSetTPtr(&rtM->solverInfo, &rtmGetTPtr(rtM)); |
185 | rtsiSetStepSizePtr(&rtM->solverInfo, &rtM->Timing.stepSize0); |
186 | rtsiSetdXPtr(&rtM->solverInfo, &rtM->ModelData.derivs); |
187 | rtsiSetContStatesPtr(&rtM->solverInfo, (real_T **) |
188 | &rtM->ModelData.contStates); |
189 | rtsiSetNumContStatesPtr(&rtM->solverInfo, &rtM->Sizes.numContStates); |
190 | rtsiSetNumPeriodicContStatesPtr(&rtM->solverInfo, |
191 | &rtM->Sizes.numPeriodicContStates); |
192 | rtsiSetPeriodicContStateIndicesPtr(&rtM->solverInfo, |
193 | &rtM->ModelData.periodicContStateIndices); |
194 | rtsiSetPeriodicContStateRangesPtr(&rtM->solverInfo, |
195 | &rtM->ModelData.periodicContStateRanges); |
196 | rtsiSetErrorStatusPtr(&rtM->solverInfo, (&rtmGetErrorStatus(rtM))); |
197 | rtsiSetRTModelPtr(&rtM->solverInfo, rtM); |
198 | } |
199 | |
200 | rtsiSetSimTimeStep(&rtM->solverInfo, MAJOR_TIME_STEP); |
201 | rtM->ModelData.intgData.y = rtM->ModelData.odeY; |
202 | rtM->ModelData.intgData.f[0] = rtM->ModelData.odeF[0]; |
203 | rtM->ModelData.intgData.f[1] = rtM->ModelData.odeF[1]; |
204 | rtM->ModelData.intgData.f[2] = rtM->ModelData.odeF[2]; |
205 | rtM->ModelData.intgData.f[3] = rtM->ModelData.odeF[3]; |
206 | rtM->ModelData.contStates = ((X *) &rtX); |
207 | rtsiSetSolverData(&rtM->solverInfo, (void *)&rtM->ModelData.intgData); |
208 | rtsiSetSolverName(&rtM->solverInfo,"ode4"); |
209 | rtmSetTPtr(rtM, &rtM->Timing.tArray[0]); |
210 | rtM->Timing.stepSize0 = 0.1; |
211 | |
212 | /* InitializeConditions for TransferFcn: '<Root>/Transfer Fcn' */ |
213 | rtX.TransferFcn_CSTATE[0] = 0.0; |
214 | rtX.TransferFcn_CSTATE[1] = 0.0; |
215 | } |
216 | |
217 | /* |
218 | * File trailer for generated code. |
219 | * |
220 | * [EOF] |
221 | */ |
222 | |