Rev 1452 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /* |
||
20 | ------------ |
||
1550 | pj | 21 | CVS : $Id: mix.c,v 1.7 2005-01-08 14:33:10 pj Exp $ |
1085 | pj | 22 | |
23 | File: $File$ |
||
1550 | pj | 24 | Revision: $Revision: 1.7 $ |
25 | Last update: $Date: 2005-01-08 14:33:10 $ |
||
1085 | pj | 26 | ------------ |
27 | */ |
||
28 | |||
29 | /* |
||
30 | * Copyright (C) 2000 Giorgio Buttazzo and Paolo Gai |
||
31 | * |
||
32 | * This program is free software; you can redistribute it and/or modify |
||
33 | * it under the terms of the GNU General Public License as published by |
||
34 | * the Free Software Foundation; either version 2 of the License, or |
||
35 | * (at your option) any later version. |
||
36 | * |
||
37 | * This program is distributed in the hope that it will be useful, |
||
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
40 | * GNU General Public License for more details. |
||
41 | * |
||
42 | * You should have received a copy of the GNU General Public License |
||
43 | * along with this program; if not, write to the Free Software |
||
44 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
45 | * |
||
46 | */ |
||
47 | |||
48 | /*--------------------------------------------------------------*/ |
||
49 | /* DEMO with 9 INDEPENDENT TASKS */ |
||
50 | /*--------------------------------------------------------------*/ |
||
51 | |||
52 | #include <kernel/kern.h> |
||
1451 | giacomo | 53 | |
54 | #include <drivers/shark_fb26.h> |
||
55 | #include <drivers/shark_keyb26.h> |
||
56 | |||
1085 | pj | 57 | #include <semaphore.h> |
58 | #include <stdlib.h> |
||
1452 | giacomo | 59 | #include <string.h> |
1085 | pj | 60 | #include <math.h> |
61 | |||
62 | #define PIG 3.1415 |
||
63 | #define DURATA 10000 /* counter duration in tick */ |
||
64 | |||
65 | #define LW 200 /* window length */ |
||
66 | #define HW 150 /* window height */ |
||
67 | #define HLOAD 30 /* Y level for the max load */ |
||
68 | #define LLOAD (HW-HLOAD-5) /* length for the max load */ |
||
69 | |||
70 | #define XWL 10 /* left X of LEFT window */ |
||
71 | #define XWM 220 /* left X of MIDDLE window */ |
||
72 | #define XWR 430 /* left X RIGHT window */ |
||
73 | |||
74 | #define YWH 5 /* top Y of HIGH window */ |
||
75 | #define YWM 165 /* top Y of MIDDLE window */ |
||
76 | #define YWL 325 /* top Y of LOW window */ |
||
77 | |||
1452 | giacomo | 78 | int flen = 0; /* file length */ |
1085 | pj | 79 | int fine = 0; /* ending flag */ |
80 | |||
81 | sem_t mx_mat, mx_grf; /* mutex semaphores */ |
||
82 | |||
83 | int wcet[10]; /* array of task wcets */ |
||
84 | int period[10]; /* array of task periods */ |
||
85 | double load(long); /* load evaluation function */ |
||
86 | |||
87 | PID ptas; |
||
88 | char talk[5][25] = {" SHARK Demonstration ", |
||
89 | " RETIS Lab -- Scuola ", |
||
90 | " Superiore S. Anna ", |
||
91 | " HARD REAL-TIME DEMO ", |
||
92 | " June 5, 2001 "}; |
||
93 | |||
1451 | giacomo | 94 | char fbuf[1000] = "\ |
1452 | giacomo | 95 | TASK NAME PERIOD WCET\n\ |
96 | ------------------------------------------\n\ |
||
97 | task1 watch: 1000000 200\n\ |
||
98 | task2 tasto: 2000 200\n\ |
||
99 | task3 palla: 2000 200\n\ |
||
100 | task4 mosca: 20000 200\n\ |
||
101 | task5 infor: 20000 300\n\ |
||
102 | task6 ruota: 5000 400\n\ |
||
103 | task7 color: 2000 200\n\ |
||
104 | task8 pendo: 5000 400\n\ |
||
105 | ------------------------------------------\n"; |
||
1451 | giacomo | 106 | |
107 | extern int vga16color[16]; |
||
108 | |||
1085 | pj | 109 | /*------------------------------------------------------*/ |
110 | /* file reading */ |
||
111 | /*------------------------------------------------------*/ |
||
112 | |||
113 | void read_file(void) |
||
114 | { |
||
115 | int err; |
||
116 | DOS_FILE *fp; |
||
117 | |||
118 | fp = DOS_fopen("mix.dat","r"); |
||
119 | |||
120 | if (!fp) { |
||
121 | err = DOS_error(); |
||
122 | cprintf("Error %d opening myfile.txt...\n", err); |
||
123 | flen = 0; |
||
124 | return; |
||
125 | } |
||
126 | |||
127 | flen = DOS_fread(&fbuf, 1, 1000, fp); |
||
128 | cprintf("Read %d bytes from file\n", flen); |
||
129 | DOS_fclose(fp); |
||
130 | } |
||
131 | |||
132 | /*------------------------------------------------------*/ |
||
133 | /* get data from buffer */ |
||
134 | /*------------------------------------------------------*/ |
||
135 | |||
136 | void get_par(void) |
||
137 | { |
||
138 | int x = 0; |
||
139 | int i; |
||
140 | |||
1452 | giacomo | 141 | flen = strlen(fbuf); |
142 | |||
1085 | pj | 143 | for (i=1; i<=8; i++) { |
144 | while ((fbuf[x] != ':') && (x < flen)) x++; |
||
145 | x++; |
||
146 | sscanf(&fbuf[x], "%d %d", &period[i], &wcet[i]); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | /*--------------------------------------------------------------*/ |
||
151 | |||
152 | void finish1() |
||
153 | { |
||
1550 | pj | 154 | exit(1); |
1085 | pj | 155 | } |
156 | |||
157 | /*--------------------------------------------------------------*/ |
||
158 | |||
159 | void finish2() |
||
160 | { |
||
161 | fine = 1; |
||
162 | } |
||
163 | |||
164 | /****************************************************************/ |
||
165 | /* PROCESSO OROLOGIO */ |
||
166 | /****************************************************************/ |
||
167 | |||
168 | #define LLAN 40 /* length of watch stick */ |
||
169 | |||
170 | TASK watch() |
||
171 | { |
||
172 | int x0 = XWL + LW/2; |
||
173 | int y0 = YWH + HW/2; |
||
174 | int grad; |
||
175 | int xg, yg; |
||
176 | int xt, yt, d; |
||
177 | int sec, min; |
||
178 | char s[5]; |
||
179 | double rad, x, y; |
||
180 | |||
181 | xg = x0; |
||
182 | yg = y0 - LLAN; |
||
183 | xt = XWL + 78; |
||
184 | yt = YWH + 12; |
||
185 | sec = min = 0; |
||
186 | |||
187 | while (1) { |
||
188 | sec = (sec + 1) % 60; |
||
189 | if (sec == 0) min++; |
||
190 | grad = 90 - sec * 6; |
||
191 | rad = (double)grad * PIG / 180.; |
||
192 | |||
193 | sem_wait(&mx_mat); |
||
194 | x = (double)x0 + (double)LLAN * cos(rad); |
||
195 | y = (double)y0 - (double)LLAN * sin(rad); |
||
196 | sem_post(&mx_mat); |
||
197 | |||
198 | sem_wait(&mx_grf); |
||
1451 | giacomo | 199 | grx_line(x0, y0, xg, yg, vga16color[0]); |
1085 | pj | 200 | sem_post(&mx_grf); |
201 | |||
202 | xg = x; |
||
203 | yg = y; |
||
204 | |||
205 | sem_wait(&mx_grf); |
||
1451 | giacomo | 206 | grx_line(x0, y0, xg, yg, vga16color[14]); |
1085 | pj | 207 | sem_post(&mx_grf); |
208 | |||
209 | sem_wait(&mx_grf); |
||
1451 | giacomo | 210 | grx_text("0 :0 ", xt, yt, vga16color[14], vga16color[0]); |
1085 | pj | 211 | sprintf(s, "%d", min); |
1451 | giacomo | 212 | grx_text(s, xt+8, yt, vga16color[14], vga16color[0]); |
1085 | pj | 213 | sprintf(s, "%d", sec); |
214 | if (sec > 9) d = 24; else d = 32; |
||
1451 | giacomo | 215 | grx_text(s, xt+d, yt, vga16color[14], vga16color[0]); |
1085 | pj | 216 | sem_post(&mx_grf); |
217 | |||
218 | task_endcycle(); |
||
219 | } |
||
220 | } |
||
221 | |||
222 | /****************************************************************/ |
||
223 | /* PROCESSO DI RIEMPIMENTO */ |
||
224 | /****************************************************************/ |
||
225 | |||
226 | #define CIMA (YWH+5) /* fondo del recipiente */ |
||
227 | #define FONDO (YWH+HW-5) /* cima del recipiente */ |
||
228 | #define LREC (XWM+75) /* lato sinistro recipiente */ |
||
229 | #define DREC 50 /* diametro del recipiente */ |
||
230 | |||
231 | TASK tasto() |
||
232 | { |
||
233 | int x, y; |
||
234 | int x0; /* coord. sinistra recipiente */ |
||
235 | int col, cliq, bkg; |
||
236 | int i; |
||
237 | int liv; /* livello del liquido */ |
||
238 | |||
239 | cliq = 9; |
||
240 | bkg = 14; |
||
241 | x0 = LREC; |
||
242 | x = x0 + DREC/2; |
||
243 | y = CIMA; |
||
244 | liv = FONDO; |
||
245 | |||
246 | while (1) { |
||
247 | |||
248 | col = cliq; |
||
249 | for (i=0; i<2; i++) { /* disegna goccia */ |
||
250 | while (y < liv) { |
||
251 | sem_wait(&mx_grf); |
||
1451 | giacomo | 252 | grx_plot(x,y,vga16color[col]); |
1085 | pj | 253 | sem_post(&mx_grf); |
254 | y++; |
||
255 | } |
||
256 | y = CIMA; |
||
257 | col = bkg; |
||
258 | } |
||
259 | |||
260 | liv--; |
||
261 | sem_wait(&mx_grf); |
||
1451 | giacomo | 262 | grx_line(x0+1, liv, x0+DREC-1, liv, vga16color[cliq]); |
1085 | pj | 263 | sem_post(&mx_grf); |
264 | |||
265 | if (liv <= CIMA+1) { /* swap colors */ |
||
266 | i = bkg; bkg = cliq; cliq = i; |
||
267 | liv = FONDO; |
||
268 | } |
||
269 | |||
270 | task_endcycle(); |
||
271 | } |
||
272 | } |
||
273 | |||
274 | /****************************************************************/ |
||
275 | |||
276 | void kboar() |
||
277 | { |
||
278 | task_activate(ptas); |
||
279 | } |
||
280 | |||
281 | /****************************************************************/ |
||
282 | /* PROCESSO PALLA */ |
||
283 | /****************************************************************/ |
||
284 | |||
285 | #define VMIN 11. /* velocit… minima per suono */ |
||
286 | #define LP 3 /* lato della pallina */ |
||
287 | |||
288 | TASK palla() |
||
289 | { |
||
290 | int ox, oy; /* vecchia posizione pallina */ |
||
291 | int x0; /* posizione iniziale pallina */ |
||
292 | int xmin, xmax; |
||
293 | int base, top; |
||
294 | int xg, yg; /* coordinate grafiche pallina */ |
||
295 | double x, y; /* coordinate pallina */ |
||
296 | double G = 9.8; |
||
297 | double vx, vy, v0; /* velocit… della pallina */ |
||
298 | double t, tx; /* variabile temporale */ |
||
299 | double dt; /* incremento temporale */ |
||
300 | double arg; /* variabile di appoggio */ |
||
301 | |||
302 | xmin = XWR+LP+1; |
||
303 | xmax = XWR+LW-LP-1; |
||
304 | base = YWH+HW-LP-1; |
||
305 | top = HW-10-LP; |
||
306 | x = ox = x0 = xmin; |
||
307 | y = oy = top; |
||
308 | arg = 2.*G*(double)top; |
||
309 | vy = v0 = sqrt(arg); |
||
310 | vx = 15.; |
||
311 | tx = 0.0; |
||
312 | t = vy / G; |
||
313 | dt = .02; |
||
314 | |||
315 | while (1) { |
||
316 | x = x0 + vx*tx; |
||
317 | y = base - vy*t + .5*G*t*t; |
||
318 | if (y >= base) { |
||
319 | t = 0.0; |
||
320 | vy = v0; |
||
321 | y = base - vy*t + .5*G*t*t; |
||
322 | } |
||
323 | if (x >= xmax) { |
||
324 | tx = 0.0; |
||
325 | x0 = xmax; |
||
326 | vx = -vx; |
||
327 | x = x0 + vx*tx; |
||
328 | } |
||
329 | if (x <= xmin) { |
||
330 | tx = 0.0; |
||
331 | x0 = xmin; |
||
332 | vx = -vx; |
||
333 | x = x0 + vx*tx; |
||
334 | } |
||
335 | xg = x; yg = y; |
||
336 | sem_wait(&mx_grf); |
||
1451 | giacomo | 337 | grx_disc(ox,oy,LP,vga16color[0]); |
338 | grx_disc(xg,yg,LP,vga16color[10]); |
||
1085 | pj | 339 | sem_post(&mx_grf); |
340 | oy = yg; ox = xg; |
||
341 | t += dt; |
||
342 | tx += dt; |
||
343 | task_endcycle(); |
||
344 | } |
||
345 | } |
||
346 | |||
347 | /****************************************************************/ |
||
348 | /* PROCESSO MOSCA */ |
||
349 | /****************************************************************/ |
||
350 | |||
351 | TASK mosca() |
||
352 | { |
||
353 | int x, y, Ax, Ay, h; |
||
354 | int x0, y0, tet; |
||
355 | int xmax,ymax; |
||
356 | double A, B; |
||
357 | double r; |
||
358 | double rnd; |
||
359 | |||
360 | xmax = LW/2-1; ymax = HW/2-1; |
||
361 | x = 0; y = 0; tet = 0; |
||
362 | x0 = XWL+LW/2; y0 = YWM+HW/2; |
||
363 | A = 5.; B = 30.; |
||
364 | |||
365 | while (1) { |
||
366 | |||
367 | rnd = (rand()%100)/100.; /* rnd = [0,1] */ |
||
368 | h = (2. * B * rnd) - B; /* h = [-B,B] */ |
||
369 | tet = tet + h; |
||
370 | |||
371 | if (tet > 360) tet = tet - 360; |
||
372 | if (tet < 0) tet = tet + 360; |
||
373 | r = tet * PIG / 180.; |
||
374 | |||
375 | sem_wait(&mx_mat); |
||
376 | Ax = (double)(A * cos(r)); |
||
377 | Ay = (double)(A * sin(r)); |
||
378 | sem_post(&mx_mat); |
||
379 | x = x + Ax; |
||
380 | y = y + Ay; |
||
381 | |||
382 | if ((x >= xmax) || (x <= -xmax) || |
||
383 | (y >= ymax) || (y <= -ymax)) { |
||
384 | x = x - Ax; |
||
385 | y = y - Ay; |
||
386 | tet = tet - 180; |
||
387 | if (tet > 360) tet = tet - 360; |
||
388 | if (tet < 0) tet = tet + 360; |
||
389 | r = tet * PIG / 180.; |
||
390 | sem_wait(&mx_mat); |
||
391 | Ax = (double)(A * cos(r)); |
||
392 | Ay = (double)(A * sin(r)); |
||
393 | sem_post(&mx_mat); |
||
394 | x = x + Ax; |
||
395 | y = y + Ay; |
||
396 | } |
||
397 | sem_wait(&mx_grf); |
||
1451 | giacomo | 398 | grx_plot(x+x0, y+y0, vga16color[10]); |
1085 | pj | 399 | sem_post(&mx_grf); |
400 | task_endcycle(); |
||
401 | } |
||
402 | } |
||
403 | |||
404 | /****************************************************************/ |
||
405 | /* PROCESSO INFORMAZIONI */ |
||
406 | /****************************************************************/ |
||
407 | |||
408 | TASK infor() |
||
409 | { |
||
410 | char s[2]; |
||
411 | int x, y; |
||
412 | int r; |
||
413 | int i = 0; |
||
414 | int leng; |
||
415 | int col = 0; |
||
416 | |||
417 | r = 0; |
||
418 | x = XWM + 16; |
||
419 | y = YWM + 40; |
||
420 | s[1] = 0; |
||
421 | |||
422 | leng = 0; |
||
423 | while (talk[0][leng] != 0) leng++; |
||
424 | |||
425 | while (1) { |
||
426 | s[0] = talk[r][i]; |
||
427 | sem_wait(&mx_grf); |
||
1451 | giacomo | 428 | grx_text(s,x+i*8,y+r*8,vga16color[col+10],vga16color[1]); |
1085 | pj | 429 | sem_post(&mx_grf); |
430 | i++; |
||
431 | if (i == leng) { |
||
432 | i = 0; |
||
433 | r = (r + 1) % 5; |
||
434 | if (r == 0) col = (col + 1) % 6; |
||
435 | } |
||
436 | task_endcycle(); |
||
437 | } |
||
438 | } |
||
439 | |||
440 | /****************************************************************/ |
||
441 | /* PROCESSO RUOTA */ |
||
442 | /****************************************************************/ |
||
443 | |||
444 | TASK ruota() |
||
445 | { |
||
446 | int x0 = XWR + LW/2; |
||
447 | int y0 = YWM + HW/2; |
||
448 | int grad = 90; |
||
449 | int xg, yg; |
||
450 | double rad, x, y; |
||
451 | |||
452 | xg = x0; |
||
453 | yg = y0 + LLAN; |
||
454 | |||
455 | while (1) { |
||
456 | |||
457 | rad = (double)grad * PIG / 180.; |
||
458 | |||
459 | sem_wait(&mx_mat); |
||
460 | x = (double)x0 + (double)LLAN * cos(rad); |
||
461 | y = (double)y0 + (double)LLAN * sin(rad); |
||
462 | sem_post(&mx_mat); |
||
463 | |||
464 | sem_wait(&mx_grf); |
||
1451 | giacomo | 465 | grx_disc(xg, yg, 4, vga16color[0]); |
1085 | pj | 466 | sem_post(&mx_grf); |
467 | |||
468 | xg = x; yg = y; |
||
469 | |||
470 | sem_wait(&mx_grf); |
||
1451 | giacomo | 471 | grx_disc(xg, yg, 4, vga16color[13]); |
1085 | pj | 472 | sem_post(&mx_grf); |
473 | |||
474 | grad = (grad + 1) % 360; |
||
475 | |||
476 | task_endcycle(); |
||
477 | } |
||
478 | } |
||
479 | |||
480 | /****************************************************************/ |
||
481 | /* PROCESSO COLORI */ |
||
482 | /****************************************************************/ |
||
483 | |||
484 | TASK color() |
||
485 | { |
||
486 | int xx0 = XWL+5; |
||
487 | int yy0 = YWL+5; |
||
488 | int n, col; |
||
489 | int x, y; |
||
490 | |||
491 | x = 0; y = 0; |
||
492 | |||
493 | while (1) { |
||
494 | n = 19. * ((rand()%100)/100.); |
||
495 | x = xx0 + n * 10; |
||
496 | n = 14. * ((rand()%100)/100.); |
||
497 | y = yy0 + n * 10; |
||
498 | col = 16. * ((rand()%100)/100.); |
||
499 | |||
500 | /* xg = xx0 + x; |
||
501 | yg = yy0 + y; |
||
502 | x = (x + 10)%(LW-10); |
||
503 | y = (y + 10)%(HW-10); |
||
504 | */ |
||
505 | sem_wait(&mx_grf); |
||
1451 | giacomo | 506 | grx_box(x, y, x+9, y+9, vga16color[col]); |
1085 | pj | 507 | sem_post(&mx_grf); |
508 | |||
509 | task_endcycle(); |
||
510 | } |
||
511 | } |
||
512 | |||
513 | /****************************************************************/ |
||
514 | /* PROCESSO PENDOLO */ |
||
515 | /****************************************************************/ |
||
516 | |||
517 | TASK pendo() |
||
518 | { |
||
519 | int x0 = XWM+LW/2; |
||
520 | int y0 = YWL+10; |
||
521 | int xg, yg; |
||
522 | int col = 11; |
||
523 | double x, y, teta; |
||
524 | double v, a, dt; |
||
525 | double g, l; |
||
526 | |||
527 | g = 9.8; |
||
528 | l = 80.; |
||
529 | dt = 0.1; |
||
530 | teta = 40. * PIG / 180.; |
||
531 | v = 0.; |
||
532 | sem_wait(&mx_mat); |
||
533 | x = l * sin((double)teta); |
||
534 | y = l * cos((double)teta); |
||
535 | a = -(g/l) * sin((double)teta); |
||
536 | sem_post(&mx_mat); |
||
537 | xg = x0 + x; |
||
538 | yg = y0 + y; |
||
539 | |||
540 | while (1) { |
||
541 | |||
542 | v += a * dt; |
||
543 | teta += v * dt; |
||
544 | sem_wait(&mx_mat); |
||
545 | x = l * sin((double)teta); |
||
546 | y = l * cos((double)teta); |
||
547 | a = -(g/l) * sin((double)teta); |
||
548 | sem_post(&mx_mat); |
||
549 | |||
550 | sem_wait(&mx_grf); |
||
1451 | giacomo | 551 | grx_line(x0, y0, xg, yg, vga16color[0]); |
552 | grx_circle(xg, yg, 5, vga16color[0]); |
||
553 | grx_disc(xg, yg, 4, vga16color[0]); |
||
1085 | pj | 554 | sem_post(&mx_grf); |
555 | |||
556 | xg = x0+x; yg = y0+y; |
||
557 | |||
558 | sem_wait(&mx_grf); |
||
1451 | giacomo | 559 | grx_line(x0, y0, xg, yg, vga16color[col]); |
560 | grx_circle(xg, yg, 5, vga16color[col+2]); |
||
561 | grx_disc(xg, yg, 4, vga16color[col+1]); |
||
1085 | pj | 562 | sem_post(&mx_grf); |
563 | |||
564 | task_endcycle(); |
||
565 | } |
||
566 | } |
||
567 | |||
568 | /****************************** gener ******************************/ |
||
569 | |||
570 | TASK gener() |
||
571 | { |
||
572 | HARD_TASK_MODEL m; |
||
573 | SOFT_TASK_MODEL am; |
||
574 | PID pid; |
||
575 | |||
576 | //--------------------------------------------- |
||
577 | hard_task_default_model(m); |
||
578 | hard_task_def_wcet (m, wcet[1]); |
||
579 | hard_task_def_mit (m, period[1]); |
||
580 | hard_task_def_usemath (m); |
||
581 | pid = task_create("watch", watch, &m, NULL); |
||
582 | task_activate(pid); |
||
583 | keyb_getch(BLOCK); |
||
584 | //--------------------------------------------- |
||
585 | soft_task_default_model(am); |
||
586 | soft_task_def_met (am, wcet[2]); |
||
587 | soft_task_def_period (am, period[2]); |
||
588 | soft_task_def_aperiodic(am); |
||
589 | soft_task_def_usemath (am); |
||
590 | ptas = task_create("tasto", tasto, &am, NULL); |
||
591 | task_activate(ptas); |
||
592 | keyb_getch(BLOCK); |
||
593 | //--------------------------------------------- |
||
594 | hard_task_default_model(m); |
||
595 | hard_task_def_wcet (m, wcet[3]); |
||
596 | hard_task_def_mit (m, period[3]); |
||
597 | hard_task_def_usemath (m); |
||
598 | pid = task_create("palla", palla, &m, NULL); |
||
599 | task_activate(pid); |
||
600 | keyb_getch(BLOCK); |
||
601 | //--------------------------------------------- |
||
602 | hard_task_default_model(m); |
||
603 | hard_task_def_wcet (m, wcet[4]); |
||
604 | hard_task_def_mit (m, period[4]); |
||
605 | hard_task_def_usemath (m); |
||
606 | pid = task_create("mosca", mosca, &m, NULL); |
||
607 | task_activate(pid); |
||
608 | keyb_getch(BLOCK); |
||
609 | //--------------------------------------------- |
||
610 | hard_task_default_model(m); |
||
611 | hard_task_def_wcet (m, wcet[5]); |
||
612 | hard_task_def_mit (m, period[5]); |
||
613 | hard_task_def_usemath (m); |
||
614 | pid = task_create("infor", infor, &m, NULL); |
||
615 | task_activate(pid); |
||
616 | keyb_getch(BLOCK); |
||
617 | //--------------------------------------------- |
||
618 | hard_task_default_model(m); |
||
619 | hard_task_def_wcet (m, wcet[6]); |
||
620 | hard_task_def_mit (m, period[6]); |
||
621 | hard_task_def_usemath (m); |
||
622 | pid = task_create("ruota", ruota, &m, NULL); |
||
623 | task_activate(pid); |
||
624 | keyb_getch(BLOCK); |
||
625 | //--------------------------------------------- |
||
626 | hard_task_default_model(m); |
||
627 | hard_task_def_wcet (m, wcet[7]); |
||
628 | hard_task_def_mit (m, period[7]); |
||
629 | hard_task_def_usemath (m); |
||
630 | pid = task_create("color", color, &m, NULL); |
||
631 | task_activate(pid); |
||
632 | keyb_getch(BLOCK); |
||
633 | //--------------------------------------------- |
||
634 | hard_task_default_model(m); |
||
635 | hard_task_def_wcet (m, wcet[8]); |
||
636 | hard_task_def_mit (m, period[8]); |
||
637 | hard_task_def_usemath (m); |
||
638 | pid = task_create("pendo", pendo, &m, NULL); |
||
639 | task_activate(pid); |
||
640 | //--------------------------------------------- |
||
641 | |||
642 | return NULL; |
||
643 | } |
||
644 | |||
645 | /****************************** MAIN ******************************/ |
||
646 | |||
1111 | pj | 647 | int main() |
1085 | pj | 648 | { |
649 | char s[20]; /* carattere letto da tastiera */ |
||
650 | int x0, y0; |
||
651 | int x, y; |
||
652 | TIME t1, count; /* contatori valutazione carico */ |
||
653 | double car; /* valore del carico corrente */ |
||
654 | TIME seme; |
||
655 | PID pid; |
||
656 | NRT_TASK_MODEL m2; |
||
657 | KEY_EVT eva, evx, evs; |
||
658 | |||
659 | /* set the keyboard handler */ |
||
660 | eva.ascii = 'a'; |
||
661 | eva.scan = KEY_A; |
||
662 | eva.flag = 0; |
||
1451 | giacomo | 663 | eva.status = KEY_PRESSED; |
664 | keyb_hook(eva,kboar,FALSE); |
||
1085 | pj | 665 | |
666 | evx.ascii = 'x'; |
||
667 | evx.scan = KEY_X; |
||
668 | evx.flag = ALTL_BIT; |
||
1451 | giacomo | 669 | evx.status = KEY_PRESSED; |
670 | keyb_hook(evx,finish1,FALSE); |
||
1085 | pj | 671 | |
672 | evs.ascii = ESC; |
||
673 | evs.scan = KEY_ESC; |
||
674 | evs.flag = 0; |
||
1451 | giacomo | 675 | evs.status = KEY_PRESSED; |
676 | keyb_hook(evs,finish2,FALSE); |
||
1085 | pj | 677 | |
678 | sem_init(&mx_mat,0,1); |
||
679 | sem_init(&mx_grf,0,1); |
||
680 | |||
681 | seme = sys_gettime(NULL); |
||
682 | srand(seme); |
||
683 | |||
684 | get_par(); |
||
685 | |||
1451 | giacomo | 686 | grx_rect(XWL,YWH,XWL+LW,YWH+HW,vga16color[14]); |
687 | grx_rect(XWM,YWH,XWM+LW,YWH+HW,vga16color[14]); |
||
688 | grx_rect(XWR,YWH,XWR+LW,YWH+HW,vga16color[14]); |
||
1085 | pj | 689 | |
1451 | giacomo | 690 | grx_rect(XWL,YWM,XWL+LW,YWM+HW,vga16color[14]); |
691 | grx_rect(XWM,YWM,XWM+LW,YWM+HW,vga16color[14]); |
||
692 | grx_rect(XWR,YWM,XWR+LW,YWM+HW,vga16color[14]); |
||
1085 | pj | 693 | |
1451 | giacomo | 694 | grx_rect(XWL,YWL,XWL+LW,YWL+HW,vga16color[14]); |
695 | grx_rect(XWM,YWL,XWM+LW,YWL+HW,vga16color[14]); |
||
696 | grx_rect(XWR,YWL,XWR+LW,YWL+HW,vga16color[14]); |
||
1085 | pj | 697 | |
698 | x0 = XWL + LW/2; |
||
699 | y0 = YWH + HW/2; |
||
1451 | giacomo | 700 | grx_circle(x0, y0, LLAN+3, vga16color[12]); |
701 | grx_rect(XWL+74, YWH+7, XWL+120, YWH+22, vga16color[12]); |
||
1085 | pj | 702 | |
703 | x0 = LREC; |
||
1451 | giacomo | 704 | grx_line(x0, CIMA, x0, FONDO, vga16color[15]); |
705 | grx_line(x0+DREC, CIMA, x0+DREC, FONDO, vga16color[15]); |
||
706 | grx_line(x0, FONDO, x0+DREC, FONDO, vga16color[15]); |
||
707 | grx_box(x0+1, CIMA, x0+DREC-1, FONDO-1, vga16color[14]); |
||
708 | grx_text("Press A", XWM+16, YWH+48, vga16color[10], vga16color[0]); |
||
709 | grx_text("to fill", XWM+16, YWH+64, vga16color[10], vga16color[0]); |
||
1085 | pj | 710 | |
1451 | giacomo | 711 | grx_text("Press:", XWM+18, YWM+HW-50, vga16color[10], vga16color[0]); |
712 | grx_text("ESC to exit", XWM+18, YWM+HW-40, vga16color[10], vga16color[0]); |
||
713 | grx_text("SPACE to create", XWM+18, YWM+HW-30, vga16color[10], vga16color[0]); |
||
1085 | pj | 714 | |
715 | x0 = XWR + LW/2; |
||
716 | y0 = YWM + HW/2; |
||
1451 | giacomo | 717 | grx_circle(x0, y0, LLAN/3, vga16color[14]); |
718 | grx_disc(x0, y0, LLAN/3-1, vga16color[12]); |
||
1085 | pj | 719 | |
720 | x0 = XWR+5; |
||
721 | y0 = YWL+HW-5; |
||
1451 | giacomo | 722 | grx_line(x0, YWL+HLOAD, x0+LW-10, YWL+HLOAD, vga16color[12]); |
723 | grx_text("SYSTEM WORKLOAD:", x0+5, YWL+HLOAD-10, vga16color[10], vga16color[0]); |
||
1085 | pj | 724 | |
725 | count = 0; |
||
726 | t1 = sys_gettime(NULL); |
||
727 | do count++; while (sys_gettime(NULL) < (t1 + DURATA)); |
||
728 | |||
729 | nrt_task_default_model(m2); |
||
730 | pid = task_create("gener", gener, &m2, NULL); |
||
731 | task_activate(pid); |
||
732 | |||
733 | x = 0; |
||
734 | while (!fine) { |
||
735 | car = load(count); |
||
736 | y = (double)LLOAD*car; |
||
737 | sem_wait(&mx_grf); |
||
1451 | giacomo | 738 | grx_line(x0+x, y0-LLOAD+1, x0+x, y0, vga16color[0]); |
739 | grx_line(x0+x, y0-y, x0+x, y0, vga16color[15]); |
||
740 | grx_text(" ", x0+LW-60, YWL+HLOAD-10, vga16color[0], vga16color[0]); |
||
1085 | pj | 741 | sprintf(s, "%.3f", car); |
1451 | giacomo | 742 | grx_text(s, x0+LW-50, YWL+HLOAD-10, vga16color[15], vga16color[0]); |
1085 | pj | 743 | sem_post(&mx_grf); |
744 | x = (x + 1) % (LW-10); |
||
745 | } |
||
746 | |||
1550 | pj | 747 | exit(1); |
1085 | pj | 748 | |
1144 | pj | 749 | return 0; |
1085 | pj | 750 | } |
751 | |||
752 | /****************************************************************/ |
||
753 | |||
754 | double load(long n) |
||
755 | { |
||
756 | TIME i, t1; |
||
757 | double carico; |
||
758 | |||
759 | i = 0; |
||
760 | t1 = sys_gettime(NULL); |
||
761 | do i++; while (sys_gettime(NULL) < (t1 + DURATA)); |
||
762 | carico = 1. - (double)i / (double)n; |
||
763 | return(carico); |
||
764 | } |
||
765 | |||
766 | /****************************************************************/ |