Subversion Repositories shark

Rev

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