Subversion Repositories shark

Rev

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