Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 1
/*
2
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *               Gerardo Lamastra <gerardo@sssup.it>
6
 *
7
 * Authors     : Paolo Gai <pj@hartik.sssup.it>
8
 * (see authors.txt for full list of hartik's authors)
9
 *
10
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
11
 *
12
 * http://www.sssup.it
13
 * http://retis.sssup.it
14
 * http://hartik.sssup.it
15
 */
16
 
17
/**
18
 ------------
19
 CVS :        $Id: testg.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
20
 
21
 File:        $File$
22
 Revision:    $Revision: 1.1.1.1 $
23
 Last update: $Date: 2002-09-02 09:37:48 $
24
 ------------
25
 
26
 Test 16 (G):
27
 
28
 This is a part of the cbsmouse.c Hartik's example.
29
 
30
 It only prints the task scheduling in graphic mode...
31
 
32
 There is a parameter to choose the type of scheduling module
33
 to initialize.
34
 
35
 to init correctly the module and task bandwidth parameters, set the defines
36
 NUM and DEN in initg.c and testg.c and remember the "s" (soft) parameter!!!
37
 
38
 to plot the deadlines assigned by CBS or TBS, compile cbs.c or tbs.c with
39
 the TESTG define
40
 (gray dots over the mouse line are the deadlines, green dots are CBS
41
  shifts)
42
 
43
**/
44
 
45
/*
46
 * Copyright (C) 2000 Paolo Gai
47
 *
48
 * This program is free software; you can redistribute it and/or modify
49
 * it under the terms of the GNU General Public License as published by
50
 * the Free Software Foundation; either version 2 of the License, or
51
 * (at your option) any later version.
52
 *
53
 * This program is distributed in the hope that it will be useful,
54
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
55
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
56
 * GNU General Public License for more details.
57
 *
58
 * You should have received a copy of the GNU General Public License
59
 * along with this program; if not, write to the Free Software
60
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
61
 *
62
 */
63
 
64
#include "kernel/kern.h"
65
#include "drivers/glib.h"
66
#include "drivers/keyb.h"
67
#include "drivers/mouse.h"
68
 
69
/*--------------------------------------------------------------*/
70
/*                    TEST ON EDF SCHEDULING                    */
71
/*--------------------------------------------------------------*/
72
 
73
#define LMOUSE          20
74
#define LM              40              /* line of main         */
75
#define OFFSET          20              /* initial phase        */
76
#define CHAR_DIM        8               /* Height of chars in pixels */
77
 
78
int     col[3] = {2, 4, 14};            /* colors of timelines  */
79
int     lev[3] = {80, 120, 160};        /* level of timelines   */
80
int     ptime[3] = {10, 20, 25};        /* number of cycles     */
81
int     period[3] = {40, 50,100};       /* tasks' periods       */
82
int     tick = 1;                       /* system tick          */
83
int     tscale = 1;                     /* time scale           */
84
TIME    starttime = 0;                  /* Simulation start time (scaled) */
85
 
86
char *title;  /* used in initg.c */
87
 
88
/* period[] is scaled with a factor of PERIODSCALE usec */
89
#define PERIODSCALE 5000
90
 
91
// update also initg.c!!!
92
#define NUM 200
93
#define DEN 64000
94
 
95
//SEM     mutex;                                /* Semaphore for graphix*/
96
 
97
//#define IY(y) (480 - y)
98
#define IY(y)    y
99
 
100
/*
101
 * mouse cursor
102
 *
103
 */
104
 
105
#define W WHITE
106
#define R RED
107
#define G GREEN
108
#define M MAGENTA
109
 
110
/* shape */
111
 
112
BYTE mycursor[16*16]= {
113
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
114
   0,W,W,W,W,0,0,0,0,0,0,W,W,W,W,0,
115
   0,W,M,0,0,0,0,0,0,0,0,0,0,M,W,0,
116
   0,W,0,M,0,0,0,0,0,0,0,0,M,0,W,0,
117
   0,W,0,0,M,0,0,0,0,0,0,M,0,0,W,0,
118
   0,0,0,0,0,M,0,0,0,0,M,0,0,0,0,0,
119
   0,0,0,0,0,0,G,G,G,G,0,0,0,0,0,0,
120
   0,0,0,0,0,0,G,0,0,G,0,0,0,0,0,0,
121
   0,0,0,0,0,0,G,0,0,G,0,0,0,0,0,0,
122
   0,0,0,0,0,0,G,0,0,G,0,0,0,0,0,0,
123
   0,0,0,0,0,0,G,G,G,G,0,0,0,0,0,0,
124
   0,0,0,0,0,0,M,M,M,M,0,0,0,0,0,0,
125
   0,0,0,0,0,0,M,M,M,M,0,0,0,0,0,0,
126
   0,0,0,0,0,M,M,M,M,M,M,0,0,0,0,0,
127
   0,0,0,0,M,M,M,M,M,M,M,M,0,0,0,0,
128
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
129
};
130
 
131
#define F 0xff
132
#define B 0x00
133
 
134
/* mask */
135
BYTE mybkg[16*16]= {
136
   B,B,B,B,B,B,F,F,F,F,B,B,B,B,B,B,
137
   B,0,0,0,0,B,F,F,F,F,B,0,0,0,0,B,
138
   B,0,0,B,B,F,F,F,F,F,B,B,B,0,0,B,
139
   B,0,B,0,B,F,F,F,F,F,F,B,0,B,0,B,
140
   B,0,B,B,0,B,F,F,F,F,B,0,B,B,0,B,
141
   B,B,B,F,B,0,B,B,B,B,0,B,F,B,B,B,
142
   F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
143
   F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
144
   F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
145
   F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
146
   F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
147
   F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
148
   F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
149
   F,F,F,F,B,0,0,0,0,0,0,B,F,F,F,F,
150
   F,F,F,B,0,0,0,0,0,0,0,0,B,F,F,F,
151
   F,F,F,B,B,B,B,B,B,B,B,B,B,F,F,F,
152
};
153
 
154
#undef B
155
#define B 0xff
156
 
157
/* bad mask */
158
BYTE mybadbkg[16*16]= {
159
   B,B,B,B,B,B,F,F,F,F,B,B,B,B,B,B,
160
   B,0,0,0,0,B,F,F,F,F,B,0,0,0,0,B,
161
   B,0,0,B,B,F,F,F,F,F,B,B,B,0,0,B,
162
   B,0,B,0,B,F,F,F,F,F,F,B,0,B,0,B,
163
   B,0,B,B,0,B,F,F,F,F,B,0,B,B,0,B,
164
   B,B,B,F,B,0,B,B,B,B,0,B,F,B,B,B,
165
   F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
166
   F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
167
   F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
168
   F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
169
   F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
170
   F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
171
   F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
172
   F,F,F,F,B,0,0,0,0,0,0,B,F,F,F,F,
173
   F,F,F,B,0,0,0,0,0,0,0,0,B,F,F,F,
174
   F,F,F,B,B,B,B,B,B,B,B,B,B,F,F,F,
175
};
176
 
177
/* very bad mask */
178
BYTE myverybadbkg[16*16]= {
179
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
180
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
181
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
182
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
183
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
184
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
185
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
186
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
187
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
188
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
189
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
190
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
191
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
192
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
193
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
194
   F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
195
};
196
 
197
 
198
/*--------------------------------------------------------------*/
199
/*      Prints a grid to show task periods during execution     */
200
/*--------------------------------------------------------------*/
201
 
202
void    print_grid()
203
{
204
  int     i;
205
  int     a1, a2, a3;
206
  int     temp;
207
//  char    str[50];
208
 
209
  a1 = 0;
210
  a2 = 0;
211
  a3 = 0;
212
  temp = 0;
213
 
214
  grx_text(title, 0, 240-10 ,10, 0);
215
 
216
  grx_line(OFFSET, lev[0], 639, lev[0], 5);
217
  grx_line(OFFSET, lev[1], 639, lev[1], 5);
218
  grx_line(OFFSET, lev[2], 639, lev[2], 5);
219
  grx_text("T1", 0, lev[0]-8, 9, 0);
220
  grx_text("T2", 0, lev[1]-8, 9, 0);
221
  grx_text("T3", 0, lev[2]-8, 9, 0);
222
  grx_text("MA", 0,     LM, 8, 0);
223
  grx_text("MO", 0,     LMOUSE, 8, 0);
224
 
225
  for (i = OFFSET; i < 640; i++) {
226
    if (temp >= a1) {
227
      grx_line(i, lev[0] - 1, i, lev[0] - 20, 3);
228
      a1 += period[0];
229
    }
230
    if (temp >= a2) {
231
      grx_line(i, lev[1] - 1, i, lev[1] - 20, 3);
232
      a2 += period[1];
233
    }
234
    if (temp >= a3) {
235
      grx_line(i, lev[2] - 1, i, lev[2] - 20, 3);
236
      a3 += period[2];
237
    }
238
    temp += tick/tscale;
239
  }
240
}
241
 
242
/*--------------------------------------------------------------*/
243
/*      This function is called at system termination           */
244
/*--------------------------------------------------------------*/
245
 
246
void    my_end()
247
{
248
  grx_close();
249
//  sys_status(0xFFFF);
250
//  sys_end();
251
}
252
 
253
/*--------------------------------------------------------------*/
254
/*      GENERIC PERIODIC PROCESS                                */
255
/*--------------------------------------------------------------*/
256
 
257
TASK    color(int k)
258
{
259
  int     i;
260
  DWORD   x = OFFSET;
261
  TIME  t;
262
  while ( x < 640L) {
263
    for (i = 0; i < ptime[k]; i++) {
264
 
265
      t = sys_gettime(NULL) / PERIODSCALE;
266
      x = (t - starttime) + OFFSET;
267
      if (x>=640) break;
268
      //sem_wait(mutex, BLOCK);
269
      kern_cli();
270
      grx_plot(x, lev[k] - 4, col[k]);
271
      grx_plot(x, lev[k] - 5, col[k]);
272
      grx_plot(x, lev[k] - 6, col[k]);
273
      grx_plot(x, lev[k] - 7, col[k]);
274
      //sem_signal(mutex);
275
      kern_sti();
276
      while (sys_gettime(NULL)/PERIODSCALE == t);
277
    }
278
    task_endcycle();
279
  }
280
  return 0;
281
}
282
 
283
void my_mouse_handler(MOUSE_EVT *ev)
284
{
285
  int x;
286
 
287
  x = (sys_gettime(NULL)/PERIODSCALE - starttime) + OFFSET;
288
  if (x>=640) return;
289
  //sem_wait(mutex, BLOCK);
290
  grx_plot(x, LMOUSE, 8);
291
  //while (sys_ticks()==s);
292
  //sem_signal(mutex);  
293
}
294
 
295
/*--------------------------------------------------------------*/
296
/*      MAIN PROCESS                                            */
297
/*--------------------------------------------------------------*/
298
 
299
int  main(int argc, char *argv[])
300
{
301
  int     i;
302
  int     x = OFFSET;
303
 
304
  MOUSE_PARMS mouse = BASE_MOUSE;
305
  HARD_TASK_MODEL mouse_hard;
306
  SOFT_TASK_MODEL mouse_soft;
307
  NRT_TASK_MODEL  mouse_nrt;
308
 
309
  char  c;
310
  KEY_EVT emerg;
311
 
312
  HARD_TASK_MODEL m_per;
313
  int modenum;
314
 
315
  //sys_def_nocheck(si);
316
  //sys_def_tick(si, tick, mSec);
317
  //sys_init(&si);
318
 
319
  //cprintf("Sys GetTick... %lu 100000 / sys_tick: %lu \n", sys_gettick(), 100000 / sys_gettick());
320
 
321
  if (argc>=3)
322
    switch(*argv[2]) {
323
      case 'h':
324
        /* this is not correct, because it don't remember activations */
325
        hard_task_default_model(mouse_hard);
326
        hard_task_def_mit(mouse_hard,DEN);
327
        hard_task_def_wcet(mouse_hard,NUM);
328
        hard_task_def_system(mouse_hard);
329
        hard_task_def_aperiodic(mouse_hard);
330
        mouse_def_task(mouse,(TASK_MODEL *)&mouse_hard);
331
        break;
332
      case 's':
333
        soft_task_default_model(mouse_soft);
334
        soft_task_def_wcet(mouse_soft,NUM);
335
        soft_task_def_met(mouse_soft,NUM);
336
        soft_task_def_period(mouse_soft,DEN);
337
        soft_task_def_system(mouse_soft);
338
        soft_task_def_aperiodic(mouse_soft);
339
        mouse_def_task(mouse,(TASK_MODEL *)&mouse_soft);
340
        break;
341
      case 'n':
342
        /* this is not correct, because it don't remember activations */
343
        nrt_task_default_model(mouse_nrt);
344
        nrt_task_def_system(mouse_nrt);
345
        mouse_def_task(mouse,(TASK_MODEL *)&mouse_nrt);
346
        break;
347
      default:
348
        argc=0;
349
        break;
350
    }
351
  mouse_def_ms(mouse,0);
352
 
353
  if (argc>=4) {
354
    period[0]=atoi(argv[3]);
355
    if (period[0]<ptime[0]) period[0]=ptime[0]+5;
356
  }
357
  if (argc>=5) {
358
    period[1]=atoi(argv[4]);
359
    if (period[1]<ptime[1]) period[1]=ptime[1]+5;
360
  }
361
  if (argc>=6) {
362
    period[2]=atoi(argv[5]);
363
    if (period[2]<ptime[2]) period[2]=ptime[2]+5;
364
  }
365
 
366
  if (argc<2) {
367
    cprintf("syntax: x testg <config> <mouse-task> [t1] [t2] [t3]\n");
368
    cprintf("where <config> can be:\n");
369
    cprintf("\t0 - EDF + CBS                + RR\n");
370
    cprintf("\t1 - RM  + PS (  bkg, U=1/16) + RR, no check Ulub < 0.69\n");
371
    cprintf("\t2 - RM  + PS (nobkg, U=1/16) + RR, no check Ulub < 0.69\n");
372
    cprintf("\t3 - EDF + PS (  bkg, U=1/16) + RR\n");
373
    cprintf("\t4 - EDF + PS (nobkg, U=1/16) + RR\n");
374
    cprintf("\t5 - EDF + TBS(       U=1/16) + RR\n");
375
    cprintf("\t6 - RM  + DS (  bkg, U=1/16) + RR, no check Ulub < 0.69\n");
376
    cprintf("\t7 - RM  + DS (nobkg, U=1/16) + RR, no check Ulub < 0.69\n");
377
    cprintf("\nwhere <mouse-task> can be:\n");
378
    cprintf("\th - Hard\n");
379
    cprintf("\ts - Soft (understimated wcet)\n");
380
    cprintf("\tn - NRT\n");
381
    sys_end();
382
    return -1;
383
  }
384
 
385
  if (grx_init() == -1) {
386
    cprintf("Error initing GraphLib!!!\n");
387
    sys_end();
388
  }
389
  modenum = grx_getmode(640, 480, 8);
390
  cprintf("Modenum :%d\n", modenum);
391
 
392
  if (grx_setmode(modenum) == -1) {
393
    cprintf("No SetMode!!!\n");
394
    sys_end();
395
  }
396
  /* */
397
//  grx_close();
398
  print_grid();
399
  #define DX (640/5-1)
400
  grx_box(DX*0,240,DX*1-1,479,GREEN);
401
  grx_box(DX*1,240,DX*2-1,479,WHITE);
402
  grx_box(DX*2,240,DX*3-1,479,RED);
403
  grx_box(DX*3,240,DX*4-1,479,MAGENTA);
404
  grx_box(DX*4,240,DX*5-1,479,BLACK);
405
 
406
  for (i=0;i<3;i++)  {    
407
     period[i]=period[i]*PERIODSCALE;
408
     //ptime[i]=ptime[i]  *PERIODSCALE; ptime is not scaled
409
  }
410
 
411
  sys_atrunlevel(my_end, NULL, RUNLEVEL_BEFORE_EXIT);
412
 
413
  /* mutex */
414
//  mutex = sem_create(1);
415
 
416
  /* keyboard */
417
  emerg.ascii = 'x';
418
  emerg.scan = KEY_X;
419
  emerg.flag = ALTL_BIT;
420
  keyb_hook(emerg,(void (*)(KEY_EVT *))sys_end);
421
  keyb_getchar();
422
 
423
  /* mouse */
424
  mouse_init(&mouse);
425
  mouse_limit(XMINLIMIT(640,480),
426
              240,
427
              XMAXLIMIT(640,480),
428
              YMAXLIMIT(640,480));
429
  mouse_position(320,280);
430
  mouse_threshold(2);
431
  //grx_setcolor(255,255,255,255);
432
  mouse_grxshape(mycursor,mybkg);
433
  mouse_grxcursor(ENABLE);
434
  mouse_on();
435
  mouse_hook(my_mouse_handler);
436
 
437
  /* hard task creation */
438
 
439
  hard_task_default_model(m_per);
440
  hard_task_def_mit(m_per,period[0]);
441
  hard_task_def_wcet(m_per,ptime[0]*PERIODSCALE);
442
  hard_task_def_group(m_per, 1);
443
  //task_def_wcet(m, ptime[0] * sys_tick);
444
  if (task_create("verde", color, &m_per, NULL) == -1) {
445
    grx_close();
446
    perror("Edf.C(main) Could not create <green>:");
447
    sys_end();
448
    l1_exit(-1);
449
  }
450
  hard_task_def_arg(m_per, (void *)1);
451
  hard_task_def_wcet(m_per, ptime[1]*PERIODSCALE);
452
  hard_task_def_mit(m_per,period[1]);
453
  if (task_create("red", color, &m_per, NULL) == -1) {
454
    grx_close();
455
    perror("Edf.C(main) Could not create <red>:");
456
    sys_end();
457
    l1_exit(-1);
458
  }
459
  hard_task_def_arg(m_per, (void *)2);
460
  hard_task_def_wcet(m_per, ptime[2]*PERIODSCALE);
461
  hard_task_def_mit(m_per,period[2]);
462
  if (task_create("yellow", color, &m_per, NULL) == -1) {
463
    grx_close();
464
    perror("Edf.C(main) Could not create <yellow>:");
465
    sys_end();
466
    l1_exit(-1);
467
  }
468
  starttime = sys_gettime(NULL) / PERIODSCALE;
469
  group_activate(1);
470
 
471
  /* main loop */
472
  while (x < 640L) {
473
    x = (sys_gettime(NULL)/PERIODSCALE - starttime) + OFFSET;
474
    if (x>=640) break;
475
    //sem_wait(mutex, BLOCK);
476
    kern_cli();
477
    grx_plot(x, LM, 7);
478
    kern_sti(); // sem_signal(mutex);
479
  }
480
 
481
  c = keyb_getchar();
482
  return 0;
483
}
484
 
485
/*--------------------------------------------------------------*/