Subversion Repositories shark

Rev

Rev 1624 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1624 giacomo 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
 ------------
21
 CVS :        $Id: test7.c,v 1.1.1.1 2004-05-24 17:54:51 giacomo Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1.1.1 $
25
 Last update: $Date: 2004-05-24 17:54:51 $
26
 ------------
27
 
28
 this test shows a set of 5 tasks (+main+dummy+keyboard driver).
29
 
30
 The first 4 tasks are scheduled by a EDFSTAR Module, whereas the
31
 fifth one is a standard traditional EDF task. The 4 tasks uses a
32
 budget of 10000/100000.
33
 
34
 if edfstar.c is compiled with edfstar_printf3 active, a couple
35
 (dline, curtime) is showed (in ms).
36
 
37
 if cbsstar.c is compiled with cbsstar_printf3 active, the budget
38
 replenishments are showed.
39
*/
40
 
41
/*
42
 * Copyright (C) 2002 Paolo Gai
43
 *
44
 * This program is free software; you can redistribute it and/or modify
45
 * it under the terms of the GNU General Public License as published by
46
 * the Free Software Foundation; either version 2 of the License, or
47
 * (at your option) any later version.
48
 *
49
 * This program is distributed in the hope that it will be useful,
50
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
51
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
52
 * GNU General Public License for more details.
53
 *
54
 * You should have received a copy of the GNU General Public License
55
 * along with this program; if not, write to the Free Software
56
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
57
 *
58
 */
59
 
60
#include "kernel/kern.h"
61
#include "modules/edf.h"
62
#include "modules/cbs.h"
63
#include "cbsstar.h"
64
#include "posixstar.h"
65
#include "modules/rr.h"
66
#include "modules/dummy.h"
67
 
68
#include "modules/sem.h"
69
#include "modules/hartport.h"
70
#include "modules/cabs.h"
71
 
72
#include "modules/pi.h"
73
#include "modules/nop.h"
74
 
75
// --------------------------------------------------
76
// --------------------------------------------------
77
// Init Part
78
// --------------------------------------------------
79
// --------------------------------------------------
80
 
81
 
82
/*+ sysyem tick in us +*/
83
#define TICK 0
84
 
85
/*+ RR tick in us +*/
86
#define RRTICK 10000
87
 
88
TIME __kernel_register_levels__(void *arg)
89
{
90
  struct multiboot_info *mb = (struct multiboot_info *)arg;
91
  int cbsstar_level, posixstar_level, mybudget, mybudget1, posixstar_level1;
92
 
93
  EDF_register_level(EDF_ENABLE_ALL);
94
 
95
  cbsstar_level = CBSSTAR_register_level(3, 0);
96
  mybudget = CBSSTAR_setbudget(cbsstar_level, 15000, 30000);
97
  mybudget1 = CBSSTAR_setbudget(cbsstar_level, 14000, 56000);
98
  posixstar_level = POSIXSTAR_register_level(mybudget, cbsstar_level, 3000,1);
99
  posixstar_level1 = POSIXSTAR_register_level(mybudget1, cbsstar_level, 5000,1);
100
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
101
  dummy_register_level();
102
 
103
  // for the keyboard...
104
  //CBS_register_level(CBS_ENABLE_ALL, 0);
105
 
106
  //SEM_register_module();
107
  PI_register_module();
108
  NOP_register_module();
109
  return TICK;
110
}
111
 
112
 
113
TASK __init__(void *arg)
114
{
115
  struct multiboot_info *mb = (struct multiboot_info *)arg;
116
  //CABS_register_module();
117
  //keyb_def_map(kparms,itaMap);
118
  //KEYB_init(&kparms);
119
  __call_main__(mb);
120
 
121
  return (void *)0;
122
}
123
 
124
// --------------------------------------------------
125
// --------------------------------------------------
126
// The Test
127
// --------------------------------------------------
128
// --------------------------------------------------
129
 
130
 
131
#include <kernel/kern.h>
132
#include <drivers/keyb.h>
133
#include <semaphore.h>
134
 
135
mutex_t s;
136
 
137
void *star(void *arg)
138
{
139
  int j;
140
  for (;;) {
141
    for (j=0; j<5000; j++);
142
    //sem_wait(&s);
143
    mutex_lock(&s);
144
    cputc('°');
145
    cputs((char *)arg);
146
    mutex_unlock(&s);
147
    //kern_printf("ril");
148
    //sem_post(&s);
149
    //task_endcycle();
150
  }
151
 
152
  return NULL;
153
}
154
 
155
void *edftask(void *arg)
156
{
157
  int i,j;
158
  while(1) {
159
  for (i=0;i<5; i++) {
160
    for (j=0; j<10; j++);
161
    //sem_wait(&s);
162
    //mutex_lock(&s);
163
    cputc('°');
164
    cputs((char *)arg);
165
    //mutex_unlock(&s);
166
    //sem_post(&s);
167
  }
168
 
169
  task_endcycle();
170
  }
171
 
172
  return NULL;
173
}
174
 
175
 
176
void create1()
177
{
178
  int i;
179
  NRT_TASK_MODEL m1;
180
  HARD_TASK_MODEL m2;
181
  PID p1a, p1b, p1c[20],p2,p3;
182
  struct timespec fineprg;
183
  nrt_task_default_model(m1);
184
  nrt_task_def_group(m1, 1);
185
  nrt_task_def_level(m1,2);
186
  nrt_task_def_arg(m1,(void *)"A");
187
  nrt_task_def_weight(m1,0);
188
  p1a = task_create("a",star,&m1,NULL);
189
  if (p1a == -1) {
190
    perror("Could not create task <Write>");
191
    sys_abort(-1);
192
  }
193
 
194
  nrt_task_def_arg(m1,(void *)"B");
195
  nrt_task_def_group(m1, 1);
196
  nrt_task_def_level(m1,2);
197
    p1b = task_create("b", star, &m1, NULL);
198
  if (p1b == -1) {
199
    perror("Could not create task b ...");
200
    sys_end();
201
  }
202
 
203
 nrt_task_def_arg(m1,(void *)"1");
204
 nrt_task_def_group(m1, 1);
205
 nrt_task_def_level(m1,2);
206
 
207
  p1c[5] = task_create("1", star, &m1, NULL);
208
  if (p1c[5] == -1) {
209
     perror("Could not create task b ...");
210
     sys_end();
211
 }
212
 
213
 
214
  nrt_task_def_arg(m1,(void *)"C");
215
  nrt_task_def_group(m1, 1);
216
  nrt_task_def_level(m1,2);
217
 
218
  p1c[4] = task_create("c", star, &m1, NULL);
219
  if (p1c[4] == -1) {
220
    perror("Could not create task b ...");
221
    sys_end();
222
  }
223
 
224
  nrt_task_def_arg(m1,(void *)"D");
225
  nrt_task_def_group(m1, 1);
226
  nrt_task_def_level(m1,2);
227
 
228
  p1c[5] = task_create("d", star, &m1, NULL);
229
  if (p1c[5] == -1) {
230
    perror("Could not create task b ...");
231
    sys_end();
232
  }
233
 
234
  nrt_task_def_arg(m1,(void *)"E");
235
  nrt_task_def_group(m1, 1);
236
  nrt_task_def_level(m1,2);
237
 
238
  p1c[0] = task_create("e", star, &m1, NULL);
239
  if (p1c[0] == -1) {
240
    perror("Could not create task b ...");
241
    sys_end();
242
  }
243
 
244
  nrt_task_def_arg(m1,(void *)"F");
245
  p1c[1] = task_create("f", star, &m1, NULL);
246
  if (p1c[1] == -1) {
247
    perror("Could not create task b ...");
248
    sys_end();
249
  }
250
 
251
 
252
  nrt_task_def_arg(m1,(void *)"G");
253
  nrt_task_def_group(m1, 1);
254
  nrt_task_def_level(m1,2);
255
 
256
  p1c[2] = task_create("g", star, &m1, NULL);
257
  if (p1c[2] == -1) {
258
    perror("Could not create task b ...");
259
    sys_end();
260
  }
261
 
262
  nrt_task_def_arg(m1,(void *)"H");
263
  p1c[3] = task_create("h", star, &m1, NULL);
264
  if (p1c[3] == -1) {
265
    perror("Could not create task b ...");
266
    sys_end();
267
  }
268
 
269
  nrt_task_def_arg(m1,(void *)"I");
270
  p1c[4] = task_create("h", star, &m1, NULL);
271
  if (p1c[4] == -1) {
272
      perror("Could not create task b ...");
273
      sys_end();
274
  }
275
 
276
 
277
 
278
  hard_task_default_model(m2);
279
  hard_task_def_ctrl_jet(m2);
280
  hard_task_def_mit(m2,32000); // the budget has dline 100,000!
281
  hard_task_def_wcet(m2, 3000);
282
  hard_task_def_arg(m2,(void *)"X");
283
  hard_task_def_group(m2,1);
284
  hard_task_def_periodic(m2);
285
 
286
  p2 = task_create("2", edftask, &m2, NULL);
287
  if (p2 == -1) {
288
    perror("Could not create task edf ...");
289
    sys_end();
290
  }
291
 
292
  hard_task_def_mit(m2,32000); // the budget has dline 100,000!
293
  hard_task_def_wcet(m2, 3000);
294
  hard_task_def_arg(m2,(void *)"K");
295
  p3 = task_create("3", edftask, &m2, NULL);
296
  if (p3 == -1) {
297
    perror("Could not create task edf ...");
298
    sys_end();
299
  }
300
 
301
  cprintf("stars=%d", p2);
302
  fineprg.tv_sec=140;
303
  fineprg.tv_nsec=0;
304
  kern_event_post(&fineprg,(void(*)(void *))sys_end, NULL);
305
  group_activate(1);
306
}
307
 
308
int main(int argc, char **argv)
309
{
310
  char c='t';
311
  PI_mutexattr_t a;
312
  PI_mutexattr_default(a);
313
 
314
  //NOP_mutexattr_t a;
315
  //NOP_mutexattr_default(a);
316
 
317
 
318
  mutex_init(&s,&a);
319
 
320
  clear();
321
 
322
 
323
  cprintf("Hello, world!\nPress ESC to end the demo...\n");
324
 
325
  create1();
326
 
327
  do {
328
    //c =keyb_getch(BLOCK);
329
    //        cprintf("[]");
330
  } while (c != ESC);
331
 
332
  cprintf("ESC pressed!");
333
 
334
  sys_end();
335
 
336
  return 0;
337
}
338