Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1178 trimarchi 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 2003-06-18 08:16:00 trimarchi Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1 $
25
 Last update: $Date: 2003-06-18 08:16:00 $
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
 
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, 10000, 100000);
97
  mybudget1 = CBSSTAR_setbudget(cbsstar_level, 10000, 70000);
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
 
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 *)"#");
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_level(m1,1);
195
  nrt_task_def_arg(m1,(void *)"+");
196
  nrt_task_def_group(m1, 1);
197
  nrt_task_def_level(m1,2);
198
  p1b = task_create("b", star, &m1, NULL);
199
  if (p1b == -1) {
200
    perror("Could not create task b ...");
201
    sys_end();
202
  }
203
 
204
 
205
 
206
  nrt_task_def_arg(m1,(void *)"Q");
207
  nrt_task_def_group(m1, 1);
208
  nrt_task_def_level(m1,3);
209
 
210
  p1c[0] = task_create("c", star, &m1, NULL);
211
  if (p1c[0] == -1) {
212
    perror("Could not create task b ...");
213
    sys_end();
214
  }
215
 
216
  nrt_task_def_arg(m1,(void *)"E");
217
  p1c[1] = task_create("d", star, &m1, NULL);
218
  if (p1c[1] == -1) {
219
    perror("Could not create task b ...");
220
    sys_end();
221
  }
222
 
223
 
224
  nrt_task_def_arg(m1,(void *)"R");
225
  p1c[2] = task_create("e", star, &m1, NULL);
226
  if (p1c[2] == -1) {
227
    perror("Could not create task b ...");
228
    sys_end();
229
  }
230
 
231
 
232
  hard_task_default_model(m2);
233
  hard_task_def_ctrl_jet(m2);
234
  hard_task_def_mit(m2,50000); // the budget has dline 100,000!
235
  hard_task_def_wcet(m2, 3000);
236
  hard_task_def_arg(m2,(void *)"Û");
237
  hard_task_def_group(m2,1);
238
  hard_task_def_periodic(m2);
239
 
240
  p2 = task_create("2", edftask, &m2, NULL);
241
  if (p2 == -1) {
242
    perror("Could not create task edf ...");
243
    sys_end();
244
  }
245
  hard_task_def_mit(m2,6000); // the budget has dline 100,000!
246
  hard_task_def_wcet(m2, 3000);
247
  hard_task_def_arg(m2,(void *)"A");
248
  p3 = task_create("3", edftask, &m2, NULL);
249
  if (p3 == -1) {
250
    perror("Could not create task edf ...");
251
    sys_end();
252
  }
253
 
254
  cprintf("stars=%d", p2);
255
  fineprg.tv_sec=550;
256
  fineprg.tv_nsec=0;
257
  kern_event_post(&fineprg,(void(*)(void *))sys_end, NULL);
258
  group_activate(1);
259
}
260
 
261
int main(int argc, char **argv)
262
{
263
  char c='t';
264
  PI_mutexattr_t a;
265
  PI_mutexattr_default(a);
266
  mutex_init(&s,&a);
267
 
268
  clear();
269
 
270
 
271
  cprintf("Hello, world!\nPress ESC to end the demo...\n");
272
 
273
  create1();
274
 
275
  do {
276
    //c =keyb_getch(BLOCK);
277
  } while (c != ESC);
278
 
279
  cprintf("ESC pressed!");
280
 
281
  sys_end();
282
 
283
  return 0;
284
}
285