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: testi.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 18 (I):
27
 
28
 This test verify the correctness of the PC module.
29
 
30
 The test uses 3 mutexes
31
 m0 with ceiling 0
32
 m1 with ceiling 0
33
 m2 with ceiling 1
34
 
35
 the main task (NRT) creates three tasks.
36
 
37
 J0 with PC priority 0
38
   starts at t=1.5 sec and lock m0, unlock m0, then lock and unlock m1
39
 
40
 J1 with PC priority 1
41
   starts at t=0.5 sec and try to lock m2
42
 
43
 J2 with PC priority 2
44
   it starts and locks m2
45
   at t=1 sec it locks m1
46
   at t=1.5 sec it unlocks m1
47
 
48
 
49
 The example is similar to the scheduling diagram shown at p. 197 of the
50
 book "Sistemi in tempo Reale", by Giorgio Buttazzo, Pitagora Editrice
51
 
52
**/
53
 
54
/*
55
 * Copyright (C) 2000 Paolo Gai
56
 *
57
 * This program is free software; you can redistribute it and/or modify
58
 * it under the terms of the GNU General Public License as published by
59
 * the Free Software Foundation; either version 2 of the License, or
60
 * (at your option) any later version.
61
 *
62
 * This program is distributed in the hope that it will be useful,
63
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
64
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
65
 * GNU General Public License for more details.
66
 *
67
 * You should have received a copy of the GNU General Public License
68
 * along with this program; if not, write to the Free Software
69
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
70
 *
71
 */
72
 
73
#include "kernel/kern.h"
74
#include "drivers/keyb.h"
75
 
76
mutex_t  m0,m1,m2;
77
 
78
 
79
TIME gt(void)
80
{
81
  TIME t;
82
  kern_cli();
83
  t = ll_gettime(TIME_EXACT,NULL);
84
  kern_sti();
85
  return t;
86
}
87
 
88
void startJ(void *a)
89
{
90
//  task_activate((PID)a);
91
  PID p = (PID) a;
92
  LEVEL l;
93
 
94
  kern_printf("startJ: %d\n",p);
95
 
96
  l = proc_table[p].task_level;
97
  level_table[l]->task_activate(l,p);
98
  event_need_reschedule();
99
}
100
 
101
TASK j0()
102
{
103
  kern_printf("J0: before locking   m0\n");
104
  mutex_lock(&m0);
105
  kern_printf("J0: locked           m0\n");
106
  mutex_unlock(&m0);
107
  kern_printf("J0: unlocked         m0, locking m1\n");
108
 
109
  mutex_lock(&m1);
110
  kern_printf("J0: locked           m1\n");
111
  mutex_unlock(&m1);
112
  kern_printf("J0: unlocked         m1, end task\n");
113
  return 0;
114
}
115
 
116
 
117
TASK j1()
118
{
119
  kern_printf("J1: before locking   m2\n");
120
  mutex_lock(&m2);
121
  kern_printf("J1: locked           m2\n");
122
  mutex_unlock(&m2);
123
  kern_printf("J1: unlocked         m2, end task\n");
124
  return 0;
125
}
126
 
127
 
128
TASK j2()
129
{
130
//  struct timespec t;
131
  kern_printf("J2: before locking   m2\n");
132
  mutex_lock(&m2);
133
  kern_printf("J2: locked           m2, waiting to t=1 sec\n");
134
 
135
  while (gt() < 1000000);
136
 
137
  kern_printf("J2: t = 1 sec reached\n");
138
  mutex_lock(&m1);
139
  kern_printf("J2: locked           m1, waiting to t=2 sec\n");
140
 
141
  while (gt() < 2000000);
142
 
143
  kern_printf("J2: t = 2 sec reached\n");
144
  mutex_unlock(&m1);
145
  kern_printf("J2: unlocked         m1\n");
146
 
147
  mutex_unlock(&m2);
148
  kern_printf("J2: unlocked         m2, end task\n");
149
  return 0;
150
}
151
 
152
void fine(KEY_EVT *e)
153
{
154
  sys_end();
155
}
156
 
157
 
158
int main(int argc, char **argv)
159
{
160
  struct timespec t;
161
 
162
  HARD_TASK_MODEL m;
163
  PID      p0,p1,p2;
164
 
165
  PC_mutexattr_t a;
166
  PI_mutexattr_t a2;
167
  PC_RES_MODEL r;
168
 
169
  KEY_EVT emerg;
170
 
171
  //keyb_set_map(itaMap);
172
  emerg.ascii = 'x';
173
  emerg.scan = KEY_X;
174
  emerg.flag = ALTL_BIT;
175
  keyb_hook(emerg,fine);
176
 
177
  /* ---------------------------------------------------------------------
178
     Task creation
179
     --------------------------------------------------------------------- */
180
 
181
  hard_task_default_model(m);
182
  hard_task_def_mit(m, 1000000);
183
  hard_task_def_wcet(m, 20000);
184
  PC_res_default_model(r,0);
185
  p0 = task_create("J0", j0, &m, &r);
186
  if (p0 == NIL)
187
  { kern_printf("Can't create J0 task...\n"); return 1; }
188
 
189
  hard_task_default_model(m);
190
  hard_task_def_mit(m, 2100000);
191
  hard_task_def_wcet(m, 20000);
192
  PC_res_default_model(r,1);
193
  p1 = task_create("J1", j1, &m, &r);
194
  if (p1 == NIL)
195
  { kern_printf("Can't create J1 task...\n"); return 1; }
196
 
197
  hard_task_default_model(m);
198
  hard_task_def_mit(m, 10000000);
199
  hard_task_def_wcet(m, 3000000);
200
  PC_res_default_model(r,2);
201
  p2 = task_create("J2", j2, &m, &r);
202
  if (p2 == NIL)
203
  { kern_printf("Can't create J2 task...\n"); return 1; }
204
 
205
  /* ---------------------------------------------------------------------
206
     Mutex creation
207
     --------------------------------------------------------------------- */
208
 
209
  PI_mutexattr_default(a2);
210
  PC_mutexattr_default(a,0);
211
  mutex_init(&m0,(mutexattr_t *)&a);
212
  mutex_init(&m1,(mutexattr_t *)&a);
213
 
214
  PC_mutexattr_default(a,1);
215
  mutex_init(&m2,(mutexattr_t *)&a);
216
 
217
  /* ---------------------------------------------------------------------
218
     Event post
219
     --------------------------------------------------------------------- */
220
 
221
  t.tv_sec = 0;
222
  t.tv_nsec = 500000000;
223
//  t.tv_nsec = 30000000;
224
  kern_event_post(&t,startJ,(void *)p1);
225
 
226
  t.tv_sec = 1;
227
  kern_event_post(&t,startJ,(void *)p0);
228
 
229
  task_activate(p2);
230
 
231
  kern_printf("END main\n");
232
 
233
  return 0;
234
}