Rev 1419 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1342 | giacomo | 1 | #include "tmwtypes.h" |
2 | #include "rtmodel.h" |
||
3 | #include "rt_sim.h" |
||
4 | #include "rt_logging.h" |
||
5 | #include "rt_nonfinite.h" |
||
6 | |||
7 | #include "ext_work.h" |
||
8 | #include "rt_nonfinite.h" |
||
9 | |||
10 | #include "kernel/kern.h" |
||
1418 | giacomo | 11 | #include "modules/cabs.h" |
1419 | giacomo | 12 | #include "percorso.h" |
1342 | giacomo | 13 | |
1418 | giacomo | 14 | #include "rtw.h" |
15 | |||
1342 | giacomo | 16 | /*=========* |
17 | * Defines * |
||
18 | *=========*/ |
||
19 | |||
20 | #ifndef TRUE |
||
21 | #define FALSE (0) |
||
22 | #define TRUE (1) |
||
23 | #endif |
||
24 | |||
25 | #ifndef EXIT_FAILURE |
||
26 | #define EXIT_FAILURE 1 |
||
27 | #endif |
||
28 | #ifndef EXIT_SUCCESS |
||
29 | #define EXIT_SUCCESS 0 |
||
30 | #endif |
||
31 | |||
32 | #define QUOTE1(name) #name |
||
33 | #define QUOTE(name) QUOTE1(name) /* need to expand name */ |
||
34 | |||
35 | #define RUN_FOREVER -1.0 |
||
36 | |||
37 | #define EXPAND_CONCAT(name1,name2) name1 ## name2 |
||
38 | #define CONCAT(name1,name2) EXPAND_CONCAT(name1,name2) |
||
39 | #define RT_MODEL CONCAT(MODEL,_rtModel) |
||
40 | |||
41 | extern RT_MODEL *MODEL(void); |
||
42 | |||
43 | extern void MdlInitializeSizes(void); |
||
44 | extern void MdlInitializeSampleTimes(void); |
||
45 | extern void MdlStart(void); |
||
46 | extern void MdlOutputs(int_T tid); |
||
47 | extern void MdlUpdate(int_T tid); |
||
48 | extern void MdlTerminate(void); |
||
49 | |||
50 | real_T rtInf; |
||
51 | real_T rtMinusInf; |
||
52 | real_T rtNaN; |
||
53 | |||
1418 | giacomo | 54 | CAB input_cid[NINPUTCAB]; |
55 | CAB output_cid[NOUTPUTCAB]; |
||
56 | |||
1415 | giacomo | 57 | #ifdef EXT_MODE |
58 | # define rtExtModeSingleTaskUpload(S) \ |
||
59 | { \ |
||
60 | int stIdx; \ |
||
61 | rtExtModeUploadCheckTrigger(); \ |
||
62 | for (stIdx=0; stIdx<NUMST; stIdx++) { \ |
||
63 | if (rtmIsSampleHit(S, stIdx, 0 /*unused*/)) { \ |
||
64 | rtExtModeUpload(stIdx,rtmGetTaskTime(S,stIdx)); \ |
||
65 | } \ |
||
66 | } \ |
||
67 | } |
||
68 | #else |
||
69 | # define rtExtModeSingleTaskUpload(S) /* Do nothing */ |
||
70 | #endif |
||
71 | |||
1402 | giacomo | 72 | #if NCSTATES > 0 |
73 | extern void rt_ODECreateIntegrationData(RTWSolverInfo *si); |
||
74 | extern void rt_ODEUpdateContinuousStates(RTWSolverInfo *si); |
||
75 | |||
76 | # define rt_CreateIntegrationData(S) \ |
||
77 | rt_ODECreateIntegrationData(rtmGetRTWSolverInfo(S)); |
||
78 | # define rt_UpdateContinuousStates(S) \ |
||
79 | rt_ODEUpdateContinuousStates(rtmGetRTWSolverInfo(S)); |
||
80 | # else |
||
1342 | giacomo | 81 | # define rt_CreateIntegrationData(S) \ |
82 | rtsiSetSolverName(rtmGetRTWSolverInfo(S),"FixedStepDiscrete"); |
||
83 | # define rt_UpdateContinuousStates(S) \ |
||
84 | rtmSetT(S, rtsiGetSolverStopTime(rtmGetRTWSolverInfo(S))); |
||
1402 | giacomo | 85 | #endif |
1342 | giacomo | 86 | |
87 | /*==================================* |
||
88 | * Global data local to this module * |
||
89 | *==================================*/ |
||
1368 | giacomo | 90 | |
91 | RT_MODEL *S; |
||
92 | const char *status; |
||
93 | real_T finaltime = -2.0; |
||
94 | volatile int simulation_run; |
||
1342 | giacomo | 95 | static struct { |
96 | int_T stopExecutionFlag; |
||
97 | int_T isrOverrun; |
||
98 | int_T overrunFlags[NUMST]; |
||
99 | const char_T *errmsg; |
||
100 | } GBLbuf; |
||
101 | |||
102 | /* Function: rt_InitInfAndNaN ================================================== |
||
103 | * Abstract: |
||
104 | * Initialize the rtInf, rtMinusInf, and rtNaN needed by the |
||
105 | * generated code. NaN is initialized as non-signaling. Assumes IEEE. |
||
106 | */ |
||
107 | void rt_InitInfAndNaN(int_T realSize) |
||
108 | { |
||
109 | short one = 1; |
||
110 | enum { |
||
111 | LittleEndian, |
||
112 | BigEndian |
||
113 | } machByteOrder = (*((char *) &one) == 1) ? LittleEndian : BigEndian; |
||
114 | |||
115 | switch (realSize) { |
||
116 | case 4: |
||
117 | switch (machByteOrder) { |
||
118 | case LittleEndian: { |
||
119 | typedef struct { |
||
120 | uint32_T fraction : 23; |
||
121 | uint32_T exponent : 8; |
||
122 | uint32_T sign : 1; |
||
123 | } LittleEndianIEEEDouble; |
||
124 | |||
125 | (*(LittleEndianIEEEDouble*)&rtInf).sign = 0; |
||
126 | (*(LittleEndianIEEEDouble*)&rtInf).exponent = 0xFF; |
||
127 | (*(LittleEndianIEEEDouble*)&rtInf).fraction = 0; |
||
128 | rtMinusInf = rtInf; |
||
129 | rtNaN = rtInf; |
||
130 | (*(LittleEndianIEEEDouble*)&rtMinusInf).sign = 1; |
||
131 | (*(LittleEndianIEEEDouble*)&rtNaN).fraction = 0x7FFFFF; |
||
132 | } |
||
133 | break; |
||
134 | case BigEndian: { |
||
135 | typedef struct { |
||
136 | uint32_T sign : 1; |
||
137 | uint32_T exponent : 8; |
||
138 | uint32_T fraction : 23; |
||
139 | } BigEndianIEEEDouble; |
||
140 | |||
141 | (*(BigEndianIEEEDouble*)&rtInf).sign = 0; |
||
142 | (*(BigEndianIEEEDouble*)&rtInf).exponent = 0xFF; |
||
143 | (*(BigEndianIEEEDouble*)&rtInf).fraction = 0; |
||
144 | rtMinusInf = rtInf; |
||
145 | rtNaN = rtInf; |
||
146 | (*(BigEndianIEEEDouble*)&rtMinusInf).sign = 1; |
||
147 | (*(BigEndianIEEEDouble*)&rtNaN).fraction = 0x7FFFFF; |
||
148 | } |
||
149 | break; |
||
150 | } |
||
151 | break; |
||
152 | |||
153 | case 8: |
||
154 | switch (machByteOrder) { |
||
155 | case LittleEndian: { |
||
156 | typedef struct { |
||
157 | struct { |
||
158 | uint32_T fraction2; |
||
159 | } wordH; |
||
160 | struct { |
||
161 | uint32_T fraction1 : 20; |
||
162 | uint32_T exponent : 11; |
||
163 | uint32_T sign : 1; |
||
164 | } wordL; |
||
165 | } LittleEndianIEEEDouble; |
||
166 | |||
167 | (*(LittleEndianIEEEDouble*)&rtInf).wordL.sign = 0; |
||
168 | (*(LittleEndianIEEEDouble*)&rtInf).wordL.exponent = 0x7FF; |
||
169 | (*(LittleEndianIEEEDouble*)&rtInf).wordL.fraction1 = 0; |
||
170 | (*(LittleEndianIEEEDouble*)&rtInf).wordH.fraction2 = 0; |
||
171 | |||
172 | rtMinusInf = rtInf; |
||
173 | (*(LittleEndianIEEEDouble*)&rtMinusInf).wordL.sign = 1; |
||
174 | (*(LittleEndianIEEEDouble*)&rtNaN).wordL.sign = 0; |
||
175 | (*(LittleEndianIEEEDouble*)&rtNaN).wordL.exponent = 0x7FF; |
||
176 | (*(LittleEndianIEEEDouble*)&rtNaN).wordL.fraction1 = 0xFFFFF; |
||
177 | (*(LittleEndianIEEEDouble*)&rtNaN).wordH.fraction2 = 0xFFFFFFFF; |
||
178 | } |
||
179 | break; |
||
180 | case BigEndian: { |
||
181 | typedef struct { |
||
182 | struct { |
||
183 | uint32_T sign : 1; |
||
184 | uint32_T exponent : 11; |
||
185 | uint32_T fraction1 : 20; |
||
186 | } wordL; |
||
187 | struct { |
||
188 | uint32_T fraction2; |
||
189 | } wordH; |
||
190 | } BigEndianIEEEDouble; |
||
191 | |||
192 | (*(BigEndianIEEEDouble*)&rtInf).wordL.sign = 0; |
||
193 | (*(BigEndianIEEEDouble*)&rtInf).wordL.exponent = 0x7FF; |
||
194 | (*(BigEndianIEEEDouble*)&rtInf).wordL.fraction1 = 0; |
||
195 | (*(BigEndianIEEEDouble*)&rtInf).wordH.fraction2 = 0; |
||
196 | |||
197 | rtMinusInf = rtInf; |
||
198 | (*(BigEndianIEEEDouble*)&rtMinusInf).wordL.sign = 1; |
||
199 | (*(BigEndianIEEEDouble*)&rtNaN).wordL.sign = 0; |
||
200 | (*(BigEndianIEEEDouble*)&rtNaN).wordL.exponent = 0x7FF; |
||
201 | (*(BigEndianIEEEDouble*)&rtNaN).wordL.fraction1 = 0xFFFFF; |
||
202 | (*(BigEndianIEEEDouble*)&rtNaN).wordH.fraction2 = 0xFFFFFFFF; |
||
203 | } |
||
204 | break; |
||
205 | } |
||
206 | break; |
||
207 | default: |
||
1369 | giacomo | 208 | cprintf("Error: Unable to initialize rtInf, rtMinusInf and rtNaN\n"); |
1342 | giacomo | 209 | sys_end(); |
210 | break; |
||
211 | } |
||
212 | |||
213 | } /* end rt_InitInfAndNaN */ |
||
214 | |||
215 | /* Function: rtOneStep ======================================================== |
||
216 | * |
||
217 | * Abstract: |
||
218 | * Perform one step of the model. This function is modeled such that |
||
219 | * it could be called from an interrupt service routine (ISR) with minor |
||
220 | * modifications. |
||
221 | */ |
||
222 | static void rt_OneStep(RT_MODEL *S) |
||
223 | { |
||
224 | real_T tnext; |
||
1415 | giacomo | 225 | |
1342 | giacomo | 226 | /*********************************************** |
227 | * Check and see if base step time is too fast * |
||
228 | ***********************************************/ |
||
1415 | giacomo | 229 | |
1342 | giacomo | 230 | if (GBLbuf.isrOverrun++) { |
231 | GBLbuf.stopExecutionFlag = 1; |
||
232 | return; |
||
233 | } |
||
1415 | giacomo | 234 | |
1342 | giacomo | 235 | /*********************************************** |
236 | * Check and see if error status has been set * |
||
237 | ***********************************************/ |
||
1415 | giacomo | 238 | |
1342 | giacomo | 239 | if (rtmGetErrorStatus(S) != NULL) { |
240 | GBLbuf.stopExecutionFlag = 1; |
||
241 | return; |
||
242 | } |
||
1415 | giacomo | 243 | |
1342 | giacomo | 244 | /* enable interrupts here */ |
1415 | giacomo | 245 | |
1342 | giacomo | 246 | rtExtModeOneStep(rtmGetRTWExtModeInfo(S), |
1415 | giacomo | 247 | (boolean_T *)&rtmGetStopRequested(S)); |
248 | |||
1342 | giacomo | 249 | tnext = rt_SimGetNextSampleHit(); |
250 | rtsiSetSolverStopTime(rtmGetRTWSolverInfo(S),tnext); |
||
1415 | giacomo | 251 | |
1342 | giacomo | 252 | MdlOutputs(0); |
1415 | giacomo | 253 | |
254 | rtExtModeSingleTaskUpload(S); |
||
255 | |||
256 | if (GBLbuf.errmsg != NULL) { |
||
257 | GBLbuf.stopExecutionFlag = 1; |
||
258 | return; |
||
259 | } |
||
260 | |||
1342 | giacomo | 261 | MdlUpdate(0); |
262 | rt_SimUpdateDiscreteTaskSampleHits(rtmGetNumSampleTimes(S), |
||
263 | rtmGetTimingData(S), |
||
264 | rtmGetSampleHitPtr(S), |
||
265 | rtmGetTPtr(S)); |
||
1415 | giacomo | 266 | |
1342 | giacomo | 267 | if (rtmGetSampleTime(S,0) == CONTINUOUS_SAMPLE_TIME) { |
268 | rt_UpdateContinuousStates(S); |
||
269 | } |
||
1415 | giacomo | 270 | |
1342 | giacomo | 271 | GBLbuf.isrOverrun--; |
1415 | giacomo | 272 | |
1342 | giacomo | 273 | rtExtModeCheckEndTrigger(); |
274 | |||
275 | } /* end rtOneStep */ |
||
276 | |||
1368 | giacomo | 277 | void Init_RealTime_Workshop() { |
1342 | giacomo | 278 | |
1368 | giacomo | 279 | /**************************** |
1342 | giacomo | 280 | * Initialize global memory * |
281 | ****************************/ |
||
1368 | giacomo | 282 | |
1342 | giacomo | 283 | (void)memset(&GBLbuf, 0, sizeof(GBLbuf)); |
284 | |||
1368 | giacomo | 285 | /************************ |
1342 | giacomo | 286 | * Initialize the model * |
287 | ************************/ |
||
1368 | giacomo | 288 | |
1342 | giacomo | 289 | rt_InitInfAndNaN(sizeof(real_T)); |
290 | |||
291 | S = MODEL(); |
||
292 | if (rtmGetErrorStatus(S) != NULL) { |
||
1369 | giacomo | 293 | cprintf("Error: Model registration: %s\n", |
1342 | giacomo | 294 | rtmGetErrorStatus(S)); |
295 | sys_end(); |
||
296 | } |
||
1368 | giacomo | 297 | |
1342 | giacomo | 298 | if (finaltime >= 0.0 || finaltime == RUN_FOREVER) rtmSetTFinal(S,finaltime); |
299 | |||
300 | MdlInitializeSizes(); |
||
301 | MdlInitializeSampleTimes(); |
||
302 | |||
303 | status = rt_SimInitTimingEngine(rtmGetNumSampleTimes(S), |
||
304 | rtmGetStepSize(S), |
||
305 | rtmGetSampleTimePtr(S), |
||
306 | rtmGetOffsetTimePtr(S), |
||
307 | rtmGetSampleHitPtr(S), |
||
308 | rtmGetSampleTimeTaskIDPtr(S), |
||
309 | rtmGetTStart(S), |
||
310 | &rtmGetSimTimeStep(S), |
||
311 | &rtmGetTimingData(S)); |
||
312 | |||
313 | if (status != NULL) { |
||
1369 | giacomo | 314 | cprintf("Error: Failed to initialize sample time engine: %s\n", status); |
1342 | giacomo | 315 | sys_end(); |
316 | } |
||
1368 | giacomo | 317 | |
1342 | giacomo | 318 | rt_CreateIntegrationData(S); |
319 | |||
320 | rtExtModeCheckInit(); |
||
321 | rtExtModeWaitForStartMsg(rtmGetRTWExtModeInfo(S), |
||
322 | (boolean_T *)&rtmGetStopRequested(S)); |
||
323 | |||
1368 | giacomo | 324 | cprintf("\n** Starting the model **\n"); |
1342 | giacomo | 325 | |
326 | MdlStart(); |
||
327 | if (rtmGetErrorStatus(S) != NULL) { |
||
328 | GBLbuf.stopExecutionFlag = 1; |
||
329 | } |
||
330 | |||
331 | /************************************************************************* |
||
332 | * Execute the model. You may attach rtOneStep to an ISR, if so replace * |
||
333 | * the call to rtOneStep (below) with a call to a background task * |
||
334 | * application. * |
||
335 | *************************************************************************/ |
||
336 | |||
337 | if (rtmGetTFinal(S) == RUN_FOREVER) { |
||
338 | cprintf("\n**May run forever. Model stop time set to infinity.**\n"); |
||
339 | } |
||
340 | |||
1368 | giacomo | 341 | } |
1342 | giacomo | 342 | |
1368 | giacomo | 343 | void Close_RealTime_Workshop() { |
1342 | giacomo | 344 | |
345 | /******************** |
||
346 | * Cleanup and exit * |
||
347 | ********************/ |
||
348 | |||
349 | rtExtModeShutdown(); |
||
350 | |||
351 | if (GBLbuf.errmsg) { |
||
1369 | giacomo | 352 | cprintf("Error: %s\n",GBLbuf.errmsg); |
1342 | giacomo | 353 | sys_end(); |
354 | } |
||
355 | |||
356 | if (GBLbuf.isrOverrun) { |
||
1369 | giacomo | 357 | cprintf("Error: %s: ISR overrun - base sampling rate is too fast\n",QUOTE(MODEL)); |
1342 | giacomo | 358 | sys_end(); |
359 | } |
||
360 | |||
361 | if (rtmGetErrorStatus(S) != NULL) { |
||
1369 | giacomo | 362 | cprintf("Error: %s\n", rtmGetErrorStatus(S)); |
1342 | giacomo | 363 | sys_end(); |
364 | } |
||
365 | |||
1368 | giacomo | 366 | MdlTerminate(); |
1344 | giacomo | 367 | |
1368 | giacomo | 368 | } |
369 | |||
370 | TASK RTW_body(void *arg) { |
||
371 | |||
1419 | giacomo | 372 | real_T *input, *p; |
373 | |||
374 | input = (real_T *)rtmGetU(S); |
||
1368 | giacomo | 375 | simulation_run = 1; |
376 | |||
377 | while (!GBLbuf.stopExecutionFlag && |
||
378 | (rtmGetTFinal(S) == RUN_FOREVER || |
||
379 | rtmGetTFinal(S)-rtmGetT(S) > rtmGetT(S)*DBL_EPSILON)) { |
||
380 | |||
381 | rtExtModePauseIfNeeded(rtmGetRTWExtModeInfo(S), |
||
382 | (boolean_T *)&rtmGetStopRequested(S)); |
||
383 | |||
384 | if (rtmGetStopRequested(S)) break; |
||
1419 | giacomo | 385 | |
386 | /* Get PAR0 */ |
||
387 | if (input_cid[0] != -1) { |
||
388 | p = (real_T *)cab_getmes(input_cid[0]); |
||
389 | input[0] = *p; |
||
390 | cab_unget(input_cid[0], p); |
||
391 | } |
||
392 | |||
393 | /* Get PAR1 */ |
||
394 | if (input_cid[1] != -1) { |
||
395 | p = (real_T *)cab_getmes(input_cid[1]); |
||
396 | input[1] = *p; |
||
397 | cab_unget(input_cid[1], p); |
||
398 | } |
||
399 | |||
1368 | giacomo | 400 | rt_OneStep(S); |
401 | |||
402 | task_endcycle(); |
||
403 | |||
404 | } |
||
405 | |||
406 | if (!GBLbuf.stopExecutionFlag && !rtmGetStopRequested(S)) { |
||
407 | /* Execute model last time step */ |
||
408 | rt_OneStep(S); |
||
409 | } |
||
410 | |||
411 | simulation_run = 0; |
||
412 | |||
413 | return NULL; |
||
414 | |||
415 | } |
||
416 | |||
1419 | giacomo | 417 | TASK OUTPUT_body(void *arg) { |
1403 | giacomo | 418 | |
1419 | giacomo | 419 | real_T *output, *p; |
420 | real_T th; |
||
1403 | giacomo | 421 | |
1419 | giacomo | 422 | POINT pos; |
423 | PATH_ELEM *e; |
||
424 | real_T distance = 0; |
||
425 | real_T angle = 0; |
||
426 | real_T curve = 0; |
||
1403 | giacomo | 427 | |
1419 | giacomo | 428 | output_cid[0] = cab_create("DISTANCE", sizeof(real_T), 2); |
429 | output_cid[1] = cab_create("ANGLE", sizeof(real_T), 2); |
||
430 | output_cid[2] = cab_create("CURVE", sizeof(real_T), 2); |
||
1403 | giacomo | 431 | |
1419 | giacomo | 432 | output = (real_T *)rtmGetY(S); |
1403 | giacomo | 433 | |
1419 | giacomo | 434 | while(1) { |
1403 | giacomo | 435 | |
1419 | giacomo | 436 | pos.x = output[0]; |
437 | pos.y = output[1]; |
||
438 | th = output[2]; |
||
439 | |||
440 | e = find_closest_elem(&pos, 1.0); |
||
441 | if (e != 0) { |
||
442 | distance = get_distance_from_elem(&pos, e); |
||
443 | angle = th - get_angle_from_elem(&pos,e); |
||
444 | curve = is_curve(e); |
||
445 | } |
||
446 | |||
447 | /* Send Distance */ |
||
448 | p = (real_T *)cab_reserve(output_cid[0]); |
||
449 | *p = distance; |
||
450 | cab_putmes(output_cid[0], p); |
||
1418 | giacomo | 451 | |
1419 | giacomo | 452 | /* Send Angle */ |
453 | p = (real_T *)cab_reserve(output_cid[1]); |
||
454 | *p = angle; |
||
455 | cab_putmes(output_cid[1], p); |
||
1418 | giacomo | 456 | |
1419 | giacomo | 457 | /* Send Curve */ |
458 | p = (real_T *)cab_reserve(output_cid[2]); |
||
459 | *p = curve; |
||
460 | cab_putmes(output_cid[2], p); |
||
1403 | giacomo | 461 | |
1419 | giacomo | 462 | task_endcycle(); |
463 | } |
||
464 | return NULL; |
||
1403 | giacomo | 465 | } |
466 | |||
1420 | giacomo | 467 | TASK OUTPUT_w_body(void *arg) { |
468 | |||
469 | real_T *output, *p; |
||
470 | |||
471 | real_T wr = 0; |
||
472 | real_T wl = 0; |
||
473 | |||
474 | output_cid[0] = cab_create("WR", sizeof(real_T), 2); |
||
475 | output_cid[1] = cab_create("WL", sizeof(real_T), 2); |
||
476 | |||
477 | output = (real_T *)rtmGetY(S); |
||
478 | |||
479 | while(1) { |
||
480 | |||
481 | wr = output[3]; |
||
482 | wl = output[4]; |
||
483 | |||
484 | /* Send wr */ |
||
485 | p = (real_T *)cab_reserve(output_cid[3]); |
||
486 | *p = wr; |
||
487 | cab_putmes(output_cid[3], p); |
||
488 | |||
489 | /* Send wl */ |
||
490 | p = (real_T *)cab_reserve(output_cid[4]); |
||
491 | *p = wl; |
||
492 | cab_putmes(output_cid[4], p); |
||
493 | |||
494 | task_endcycle(); |
||
495 | |||
496 | } |
||
497 | |||
498 | return NULL; |
||
499 | |||
500 | } |
||
501 | |||
1419 | giacomo | 502 | void Init_Rtw() { |
1418 | giacomo | 503 | |
1419 | giacomo | 504 | HARD_TASK_MODEL RTW_task,OUTPUT_task; |
1420 | giacomo | 505 | PID RTW_pid,OUTPUT_pid,OUTPUT_w_pid; |
1416 | giacomo | 506 | |
1419 | giacomo | 507 | int i; |
1416 | giacomo | 508 | |
509 | int RTW_period; |
||
510 | int RTW_wcet; |
||
1419 | giacomo | 511 | |
1416 | giacomo | 512 | int OUTPUT_period; |
513 | int OUTPUT_wcet; |
||
514 | |||
1368 | giacomo | 515 | Init_RealTime_Workshop(); |
1419 | giacomo | 516 | Init_All_Path(); |
1368 | giacomo | 517 | |
1418 | giacomo | 518 | for (i=0;i<NINPUTCAB;i++) input_cid[i] = -1; |
519 | for (i=0;i<NOUTPUTCAB;i++) output_cid[i] = -1; |
||
1419 | giacomo | 520 | |
1416 | giacomo | 521 | RTW_period =(int)(rtmGetStepSize(S) * 1000000.0); |
522 | RTW_wcet = (int)(rtmGetStepSize(S) * 1000000.0 * 0.45); |
||
1419 | giacomo | 523 | |
1418 | giacomo | 524 | OUTPUT_period = (int)(10000.0); |
525 | OUTPUT_wcet = (int)(10000.0 * 0.10); |
||
1419 | giacomo | 526 | |
1416 | giacomo | 527 | cprintf("Task Setup\n"); |
528 | cprintf("RTW (P %8d W %8d)\n",RTW_period,RTW_wcet); |
||
529 | cprintf("OUTPUT (P %8d W %8d)\n",OUTPUT_period,OUTPUT_wcet); |
||
1419 | giacomo | 530 | |
1368 | giacomo | 531 | hard_task_default_model(RTW_task); |
1416 | giacomo | 532 | hard_task_def_mit(RTW_task,RTW_period); |
533 | hard_task_def_wcet(RTW_task,RTW_wcet); |
||
1368 | giacomo | 534 | hard_task_def_usemath(RTW_task); |
535 | hard_task_def_ctrl_jet(RTW_task); |
||
1419 | giacomo | 536 | |
1368 | giacomo | 537 | RTW_pid = task_create("RTW",RTW_body,&RTW_task,NULL); |
538 | if (RTW_pid == NIL) { |
||
1419 | giacomo | 539 | cprintf("Error: Cannot create RealTime Workshop [RTW] Task\n"); |
1403 | giacomo | 540 | sys_end(); |
541 | } |
||
542 | |||
1416 | giacomo | 543 | hard_task_default_model(OUTPUT_task); |
544 | hard_task_def_mit(OUTPUT_task,OUTPUT_period); |
||
545 | hard_task_def_wcet(OUTPUT_task,OUTPUT_wcet); |
||
546 | hard_task_def_usemath(OUTPUT_task); |
||
547 | hard_task_def_ctrl_jet(OUTPUT_task); |
||
548 | |||
1419 | giacomo | 549 | OUTPUT_pid = task_create("OUTPUT",OUTPUT_body,&OUTPUT_task,NULL); |
1416 | giacomo | 550 | if (OUTPUT_pid == NIL) { |
1419 | giacomo | 551 | cprintf("Error: Cannot create RealTime Workshop [OUTPUT] Task\n"); |
1416 | giacomo | 552 | sys_end(); |
553 | } |
||
1420 | giacomo | 554 | |
555 | hard_task_def_mit(OUTPUT_task,OUTPUT_period); |
||
556 | hard_task_def_wcet(OUTPUT_task,OUTPUT_wcet); |
||
557 | |||
558 | OUTPUT_w_pid = task_create("OUTPUTW",OUTPUT_w_body,&OUTPUT_task,NULL); |
||
559 | if (OUTPUT_pid == NIL) { |
||
560 | cprintf("Error: Cannot create RealTime Workshop [OUTPUTW] Task\n"); |
||
561 | sys_end(); |
||
562 | } |
||
563 | |||
1368 | giacomo | 564 | task_activate(RTW_pid); |
1420 | giacomo | 565 | task_activate(OUTPUT_pid); |
566 | task_activate(OUTPUT_w_pid); |
||
1368 | giacomo | 567 | |
1419 | giacomo | 568 | } |
569 | |||
570 | int main() { |
||
571 | |||
572 | Init_Rtw(); |
||
573 | |||
1418 | giacomo | 574 | activate_sensors(); |
1419 | giacomo | 575 | activate_control(); |
1418 | giacomo | 576 | |
1368 | giacomo | 577 | while(simulation_run); |
578 | |||
579 | Close_RealTime_Workshop(); |
||
580 | |||
581 | sys_end(); |
||
582 | |||
1342 | giacomo | 583 | return 0; |
584 | |||
1368 | giacomo | 585 | } |