Subversion Repositories shark

Rev

Rev 1085 | Details | Compare with Previous | 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: test6.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 Number 6:
27
 
28
 this is a part of the classic Hartik demo Aster.
29
 
30
 It checks:
31
 - EDF module
32
   . periodic tasks
33
 - an high number of task executing concurrently
34
 
35
**/
36
 
37
/*
38
 * Copyright (C) 2000 Paolo Gai
39
 *
40
 * This program is free software; you can redistribute it and/or modify
41
 * it under the terms of the GNU General Public License as published by
42
 * the Free Software Foundation; either version 2 of the License, or
43
 * (at your option) any later version.
44
 *
45
 * This program is distributed in the hope that it will be useful,
46
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
48
 * GNU General Public License for more details.
49
 *
50
 * You should have received a copy of the GNU General Public License
51
 * along with this program; if not, write to the Free Software
52
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
53
 *
54
 */
55
 
56
/*
57
   Well, this is only a stupid demo which intend to show many
58
   HARTIK+ capabilities; the application is structured in the followig
59
   way: there is an ASTER task wich randomly creates some ASTEROID tasks
60
   which are displayed into the first window; each task is HARD/PERIODIC
61
   and auto-kills itself when it reaches the window end!
62
   An other couple of tasks, TITLE & PUT give an example of port
63
   communication facility; the server task creates the port, the client
64
   task connect to it and uses the server to accomplish some stuff.
65
   Port can be declared READ/WRITE and can model ONE-TO-ONE communication
66
   or MANY-TO-ONE communication.
67
   Finally a second couple of tasks realizes a communiation through CABs;
68
   each time a key is pressed, the ascii code is posted into the CAB by the
69
   CCC task while the second task, WRITE, displays it on the screen and
70
   perform other silly actions.
71
   Finally a CLOCK task is implemented to test system clock.
72
   Please note that usually the HARTIK+ application is made up of a task
73
   group which interacts among them, while the main() function, which
74
   became a task itself when the kernel is activated, is suspended until
75
   the system is ready to terminate; the MAIN task can also be used to make
76
   other background activities, but it should not be killed; when the
77
   application terminates, the control is passed to MAIN which kills
78
   everybody, shut down the system and can handle other operations using
79
   the services available with the previou operating system (I.E. the DOS).
80
   If you need to manage sudden abort/exception you should install your own
81
   exception handler and raise it through the exc_raise() primitive to
82
   make the system abort safely!
83
   Remember that the exit functions posted through sys_atexit() will be
84
   executed in both cases, to allow clean system shutdown.
85
*/
86
 
87
//#include <string.h>
88
//#include <stdlib.h>
89
 
90
//#include "hartik.h"
91
 
92
//#define __VPAGING__
93
/* #define __TRACE__ */
94
 
95
//#ifdef __TRACE__
96
//#include "sys\log.h"
97
//#endif
98
 
99
//#include "keyb.h"
100
//#include "cons.h"
101
//#include "crtwin.h"
102
 
103
#include "kernel/kern.h"
104
 
105
 
106
int num_aster = 0;
107
#define ASTER_LIM       67
108
#define ASTER_MAX       90
109
 
110
//CAB cc;
111
//BYTE esc = FALSE;
112
 
113
TASK asteroide(void)
114
{
115
    int i = 1;
116
    int y = rand() % 20 + 1;
117
    while (i < ASTER_LIM) {
118
        puts_xy(i,y,WHITE,"*");
119
        task_endcycle();
120
 
121
        puts_xy(i,y,WHITE," ");
122
        i++;
123
    }
124
    num_aster--;
125
    return 0;
126
}
127
 
128
DWORD taskCreated = 0;
129
 
130
TASK aster(void)
131
{
132
    PID p;
133
 
134
//    MODEL m = BASE_MODEL;
135
    HARD_TASK_MODEL m;
136
    int r;
137
//    WIN w;
138
 
139
//    win_init(&w,0,0,ASTER_LIM,8);
140
//    win_frame(&w,BLACK,WHITE,"Asteroids",2);
141
 
142
 
143
    hard_task_default_model(m);
144
    hard_task_def_wcet(m,500);
145
 
146
    srand(7);
147
    while (1) {
148
        if (num_aster < ASTER_MAX) {
149
            r = (rand() % 50) - 25;
150
 
151
            hard_task_def_arg(m,(void *)((rand() % 7)+1));
152
            hard_task_def_mit(m, (50+r)*1000);
153
            p = task_create("aaa",asteroide,&m,NULL);
154
            taskCreated++;
155
            task_activate(p);
156
            num_aster++;
157
        }
158
 
159
        task_endcycle();
160
    }
161
}
162
 
163
TASK clock()
164
{
165
    //WIN w;
166
    int s = 0, m = 0;
167
 
168
    //win_init(&w,68,0,11,2);
169
    //win_frame(&w,BLACK,WHITE,"Clk",1);
170
 
171
    while(1) {
172
        printf_xy(70,1,WHITE,"%2d : %2d",m,s);
173
        task_endcycle();
174
 
175
        if (++s > 59) {
176
            s = 0;
177
            m++;
178
        }
179
        printf_xy(70,1,WHITE,"%2d : %2d",m,s);
180
        task_endcycle();
181
    }
182
}
183
 
184
/*
185
TASK title()
186
{
187
    PORT t;
188
    WIN w;
189
    int i,pos = 77;
190
    char msg[85],tmp[85],ss[2];
191
    BYTE c;
192
 
193
    win_init(&w,0,9,79,2);
194
    win_frame(&w,BLACK,WHITE,"Title",2);
195
 
196
    for (i=0; i < 77; i++) msg[i] = ' ';
197
    msg[77] = 0;
198
 
199
    t = port_connect("title",1,STREAM,READ);
200
 
201
    while (1) {
202
        port_receive(t,&c,BLOCK);
203
        ss[0] = c;
204
        ss[1] = 0;
205
        strcat(msg,ss);
206
        puts_xy(1,10,WHITE,msg);
207
        pos++;
208
        if (pos > 77) {
209
            strcpy(tmp,&(msg[1]));
210
            tmp[pos-1] = 0;
211
            pos -= 1;
212
            strcpy(msg,tmp);
213
        }
214
        task_endcycle();
215
    }
216
}
217
 
218
#define STR "..................... Hartik+ ....................."\
219
            "              Guarantees hard tasks                "\
220
            "          Includes soft periodic tasks             "\
221
            "TB server for decrementing the aperiodic response time       "\
222
            "SRP for both hard & soft aperiodic tasks        "\
223
            "Portability toward other compilers/system       "\
224
            "Support for different C compiler: Watcom C 16 bit & 32 bit"\
225
            "   --   GNU C (32 bit)   --   Borland C (16 bit)   --   MS C (16 bit)"\
226
            "                                                             "\
227
            "Programmers :    Gerardo Lamastra (lamastra@sssup2.sssup.it)    "\
228
            "    Giuseppe Lipari (lipari@sssup2.sssup.it)        "\
229
            "Alpha AXP PCI-33 porting by Antonino Casile "\
230
            "(casile@sssup1.sssup.it)                                     "\
231
            "Research coordinator: Giorgio Buttazzo (giorgio@sssup1.sssup.it)"\
232
            "                                                   "\
233
            "                                                   "\
234
            "                                                   "
235
 
236
static char GreetMsg[1600];
237
 
238
TASK put(void)
239
{
240
    PORT p;
241
 
242
    strcpy(GreetMsg,STR);
243
 
244
    p = port_create("title",strlen(GreetMsg),1,STREAM,WRITE);
245
    while(1) {
246
        port_send(p,GreetMsg,BLOCK);
247
        task_endcycle();
248
    }
249
}
250
 
251
TASK ccc(void)
252
{
253
    WIN w;
254
    char *m;
255
 
256
    win_init(&w,68,3,10,3);
257
    win_frame(&w,BLACK,WHITE,"CCC",2);
258
    puts_xy(70,4,WHITE,"Cab");
259
 
260
    while(1) {
261
        m = cab_getmes(cc);
262
        puts_xy(72,5,WHITE,m);
263
        cab_unget(cc,m);
264
        task_endcycle();
265
    }
266
}
267
 
268
 
269
TASK write()
270
{
271
    BYTE c;
272
    char *msg;
273
 
274
    while (1) {
275
        c = keyb_getchar();
276
        if (c == ESC) {
277
            esc = TRUE;
278
            task_sleep();
279
        }
280
        else {     
281
            #ifdef __VPAGING__
282
            if (c == 's') {
283
                if (get_visual_page() == 0) set_visual_page(1);
284
                else if (get_visual_page() == 1) set_visual_page(0);
285
            }
286
            #endif
287
            msg = cab_reserve(cc);
288
            msg[0] = c;
289
            msg[1] = 0;
290
            cab_putmes(cc,msg);
291
        }
292
    }
293
}
294
 
295
#define DELTA 200000.0
296
double carico(double rif,BYTE init)
297
{
298
    double i;
299
    DWORD t1 = 0,t2 = 1000;
300
    double u;
301
 
302
    i = 0.0;
303
    do {
304
        i += 1;
305
    } while (i <= DELTA);
306
 
307
    u = i / ((double) (t2 - t1));
308
 
309
    if (init) return u;
310
    else return (1.0 - u/rif);
311
}
312
 
313
void my_end(KEY_EVT *e)
314
{
315
    sys_end();
316
    cprintf("Ctrl-Brk pressed!\n");
317
    l1_exit(1);
318
}
319
 
320
void res(void)
321
{
322
    sys_status(NORM_STATUS|BLOCKED_STATUS|SLEEP_STATUS|IDLE_STATUS);
323
}
324
*/
325
 
326
int main(int argc, char **argv)
327
{
328
    PID p1,p2; //,p3,p4,p5,p6;
329
    HARD_TASK_MODEL m;
330
 
331
/*    MODEL m = BASE_MODEL;
332
      SYS_PARMS sp = BASE_SYS;
333
      KEY_EVT emerg;
334
      double rif;
335
 
336
    #ifdef __TRACE__
337
        LOG_INFO li = BASE_LOG;
338
        log_set_limit(li,9000);
339
        log_set_name(li,"aster.hrt");
340
    #endif
341
    sys_def_nocheck(sp);
342
    sys_init(&sp);
343
    sys_atexit(res, BEFORE_EXIT);
344
 
345
    #ifdef __TRACE__
346
        log_init(&li);
347
    #endif
348
 
349
    keyb_init(NULL);
350
    keyb_set_map(itaMap);
351
    emerg.ascii = 'x';
352
    emerg.scan = KEY_X;
353
    emerg.flag = ALTL_BIT;
354
    keyb_hook(emerg,my_end);
355
 
356
    #ifdef __VPAGING__
357
    set_active_page(1);
358
    set_visual_page(1);
359
    #endif
360
 
361
 
362
    CRSR_OFF();
363
    clear();
364
    puts_xy(0,20,WHITE,"Press ESC to exit demo.");
365
    cc = cab_create("Cab",2,2);
366
*/
367
 
368
    hard_task_default_model(m);
369
    hard_task_def_mit(m,10000);
370
    hard_task_def_wcet(m,2000);
371
    hard_task_def_group(m,1);
372
//    periodic_task_def_ctrl_jet(m);
373
 
374
    p1 = task_create("Aster",aster,&m,NULL);
375
    if (p1 == -1) {
376
        perror("Aster.C(main): Could not create task <aster> ...");
377
        sys_end();
378
        l1_exit(-1);
379
    }
380
 
381
    hard_task_def_mit(m,500000);
382
    p2 = task_create("Clock",clock,&m,NULL);
383
    if (p2 == -1) {
384
        perror("Aster.C(main): Could not create task <Clock> ...");
385
        sys_end();
386
        l1_exit(-1);
387
    }
388
/*    p3 = task_create("Title",title,SOFT,PERIODIC,50,&m);
389
    if (p3 == -1) {
390
        perror();
391
        cprintf("Aster.C(main): Could not create task <Title>\n");
392
        sys_end();
393
        l1_exit(-1);
394
    }
395
    p4 = task_create("Put",put,SOFT,PERIODIC,1000,&m);
396
    if (p4 == -1) {
397
        perror();
398
        cprintf("Aster.C(main): Could not create task <Put>\n");
399
        sys_end();
400
        l1_exit(-1);
401
    }
402
    p5 = task_create("Write",write,NRT,APERIODIC,10,&m);
403
    if (p5 == -1) {
404
        perror();
405
        cprintf("Aster.C(main): Could not create task <Write>\n");
406
        sys_end();
407
        l1_exit(-1);
408
    }
409
    p6 = task_create("CabTask",ccc,HARD,PERIODIC,50,&m);
410
    if (p6 == -1) {
411
        perror();
412
        cprintf("Aster.C(main): Could not create task <CabTask>\n");
413
        sys_end();
414
        l1_exit(-1);
415
    }
416
    #ifdef __TRACE__
417
    log_loop();
418
    #endif
419
 
420
    task_activate(p1);
421
    task_activate(p2);
422
    task_activate(p3);
423
    task_activate(p4);
424
    task_activate(p5);
425
    task_activate(p6);
426
 
427
    group_activate(1);
428
 
429
    while (!esc) {
430
        printf_xy(0,21,WHITE,"Clock : %lu",sys_time());
431
    }
432
 
433
    #ifdef __TRACE__
434
    log_fix();
435
    #endif
436
    group_kill(1);
437
    clear();
438
    CRSR_STD();
439
    #ifdef __VPAGING__
440
    set_active_page(0);
441
    set_visual_page(0);
442
    #endif
443
    sys_end();
444
    cprintf("System closed\n");
445
    / *
446
    sys_status(NORM_STATUS|BLOCKED_STATUS|SLEEP_STATUS|IDLE_STATUS);
447
    sys_status(NORM_STATUS|SLEEP_STATUS);
448
    */
449
 
450
    group_activate(1);
451
 
452
    {
453
      struct timespec t;
454
      do {
455
        kern_cli();
456
        ll_gettime(TIME_EXACT,&t);
457
        kern_sti();
458
      } while (t.tv_sec < 6);
459
    }
460
    kern_cli();
461
    sys_status(SCHED_STATUS);
462
    sys_end();
463
    return 0;
464
}
465