Subversion Repositories shark

Rev

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