Subversion Repositories shark

Rev

Rev 1123 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1099 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
 * Copyright (C) 2000 Paolo Gai
21
 *
22
 * This program is free software; you can redistribute it and/or modify
23
 * it under the terms of the GNU General Public License as published by
24
 * the Free Software Foundation; either version 2 of the License, or
25
 * (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
 *
36
 *
37
 * CVS :        $Id: aster1.c,v 1.1 2002-10-28 08:13:37 pj Exp $
38
 
39
 this is a reduced verion of the classic Hartik demo Aster.
40
 
41
 It uses:
42
 - EDF module
43
   . periodic tasks
44
 - an high number of task executing concurrently
45
 
46
 The demo ends after 6 seconds.
47
 
48
*/
49
 
50
/*
51
   Well, this is only a stupid demo which intend to show many
52
   HARTIK+ capabilities; the application is structured in the followig
53
   way: there is an ASTER task wich randomly creates some ASTEROID tasks
54
   which are displayed into the first window; each task is HARD/PERIODIC
55
   and auto-kills itself when it reaches the window end!
56
   Finally a CLOCK task is implemented to test system clock.
57
   Please note that usually the HARTIK+ application is made up of a task
58
   group which interacts among them, while the main() function, which
59
   became a task itself when the kernel is activated, is suspended until
60
   the system is ready to terminate; the MAIN task can also be used to make
61
   other background activities, but it should not be killed; when the
62
   application terminates, the control is passed to MAIN which kills
63
   everybody, shut down the system and can handle other operations using
64
   the services available with the previou operating system (I.E. the DOS).
65
   If you need to manage sudden abort/exception you should install your own
66
   exception handler and raise it through the exc_raise() primitive to
67
   make the system abort safely!
68
   Remember that the exit functions posted through sys_atexit() will be
69
   executed in both cases, to allow clean system shutdown.
70
*/
71
 
72
#include "kernel/kern.h"
73
 
74
int num_aster = 0;
75
#define ASTER_LIM       67
76
#define ASTER_MAX       90
77
 
78
TASK asteroide(void)
79
{
80
  int i = 1;
81
  int y = rand() % 20 + 1;
82
  while (i < ASTER_LIM) {
83
    puts_xy(i,y,WHITE,"*");
84
    task_endcycle();
85
 
86
    puts_xy(i,y,WHITE," ");
87
    i++;
88
  }
89
  num_aster--;
90
  return 0;
91
}
92
 
93
DWORD taskCreated = 0;
94
 
95
TASK aster(void)
96
{
97
  PID p;
98
 
99
  HARD_TASK_MODEL m;
100
  int r;
101
 
102
  hard_task_default_model(m);
103
  hard_task_def_wcet(m,500);
104
 
105
  srand(7);
106
  while (1) {
107
    if (num_aster < ASTER_MAX) {
108
      r = (rand() % 50) - 25;
109
 
110
      hard_task_def_arg(m,(void *)((rand() % 7)+1));
111
      hard_task_def_mit(m, (50+r)*1000);
112
      p = task_create("aaa",asteroide,&m,NULL);
113
      taskCreated++;
114
      task_activate(p);
115
      num_aster++;
116
    }
117
 
118
    task_endcycle();
119
  }
120
}
121
 
122
TASK clock()
123
{
124
  int s = 0, m = 0;
125
 
126
  while(1) {
127
    printf_xy(70,1,WHITE,"%2d : %2d",m,s);
128
    task_endcycle();
129
 
130
    if (++s > 59) {
131
      s = 0;
132
      m++;
133
    }
134
    printf_xy(70,1,WHITE,"%2d : %2d",m,s);
135
    task_endcycle();
136
  }
137
}
138
 
139
int main(int argc, char **argv)
140
{
141
  PID p1,p2;
142
  HARD_TASK_MODEL m;
143
  struct timespec t;
144
 
145
  clear();
146
 
147
  hard_task_default_model(m);
148
  hard_task_def_mit(m,10000);
149
  hard_task_def_wcet(m,2000);
150
  hard_task_def_group(m,1);
151
 
152
  p1 = task_create("Aster",aster,&m,NULL);
153
  if (p1 == -1) {
154
    perror("Aster.C(main): Could not create task <aster> ...");
155
    sys_end();
156
  }
157
 
158
  hard_task_def_mit(m,500000);
159
  p2 = task_create("Clock",clock,&m,NULL);
160
  if (p2 == -1) {
161
    perror("Aster.C(main): Could not create task <Clock> ...");
162
    sys_end();
163
  }
164
 
165
  group_activate(1);
166
 
167
  do {
168
    sys_gettime(&t);
169
  } while (t.tv_sec < 6);
170
 
171
  sys_status(SCHED_STATUS);
172
  sys_end();
173
  return 0;
174
}
175