Subversion Repositories shark

Rev

Rev 1120 | Rev 1547 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1120 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
 *
1377 giacomo 37
 * CVS :        $Id: mdemo.c,v 1.2 2004-04-17 11:36:14 giacomo Exp $
1120 pj 38
 
39
 This test verify the correctness of the NOP module. It works with the
40
 PI, PC, SRP module, too.
41
 
42
 The test uses one mutex
43
 
44
 the main task (NRT) creates three tasks.
45
 
46
 J1 with PC priority 0
47
   starts at t=0.5 sec and lock m0
48
 
49
 J2 with PC priority 1
50
   starts at t=1 sec and doesn't lock any mutex
51
 
52
 J3 with PC priority 2
53
   it starts and locks m0
54
   at t=2 sec it unlocks m1
55
 
56
 
57
 The example is similar to the scheduling diagram shown at p. 188 of the
58
 book "Sistemi in tempo Reale", by Giorgio Buttazzo, Pitagora Editrice
59
 
60
*/
61
 
62
#include "kernel/kern.h"
63
#include "modules/srp.h"
64
 
65
mutex_t  m0;
66
 
67
 
68
void startJ(void *a)
69
{
70
  task_activate((PID)a);
71
}
72
 
73
TASK j1()
74
{
75
  cprintf("J1: before locking   m0\n");
76
  mutex_lock(&m0);
77
  cprintf("J1: locked           m0\n");
78
  mutex_unlock(&m0);
79
  cprintf("J1: unlocked         m0, end task\n");
80
  return 0;
81
}
82
 
83
 
84
TASK j2()
85
{
86
  cprintf("J2: waiting t=1.5 sec\n");
87
 
88
  while (sys_gettime(NULL) < 1500000);
89
 
90
  cprintf("J2: end task\n");
91
  return 0;
92
}
93
 
94
 
95
TASK j3()
96
{
97
  cprintf("J3: before locking   m0\n");
98
  mutex_lock(&m0);
99
  cprintf("J3: locked           m0, waiting to t=2 sec\n");
100
 
101
  while (sys_gettime(NULL) < 2000000);
102
 
103
  cprintf("J3: t = 1 sec reached, unlocking m0\n");
104
  mutex_unlock(&m0);
105
  cprintf("J3: unlocked         m0, end task\n");
106
  return 0;
107
}
108
 
109
int main(int argc, char **argv)
110
{
111
  struct timespec t;
112
 
113
  HARD_TASK_MODEL m;
114
  PID      p0,p1,p2;
115
 
116
  PC_mutexattr_t  a;
117
  PI_mutexattr_t  a2;
118
  NOP_mutexattr_t a3;
119
  SRP_mutexattr_t a4;
120
  NPP_mutexattr_t a5;
121
 
122
  PC_RES_MODEL r;
123
  SRP_RES_MODEL srp;
124
 
125
  /* ---------------------------------------------------------------------
126
     Mutex creation
127
     --------------------------------------------------------------------- */
128
 
129
  PC_mutexattr_default(a,0);
130
  PI_mutexattr_default(a2);
131
  NOP_mutexattr_default(a3);
132
  SRP_mutexattr_default(a4);
133
  NPP_mutexattr_default(a5);
134
  mutex_init(&m0,&a4);
135
 
136
  /* ---------------------------------------------------------------------
137
     Task creation
138
     --------------------------------------------------------------------- */
139
 
140
  hard_task_default_model(m);
141
  hard_task_def_wcet(m,20000);
142
  hard_task_def_mit(m,10000000);
143
  PC_res_default_model(r,0);
144
  SRP_res_default_model(srp,3);
145
  p0 = task_createn("J1", j1, (TASK_MODEL *)&m, &r, &srp, SRP_usemutex(&m0), NULL);
146
  if (p0 == NIL)
147
  { cprintf("Can't create J1 task...\n"); return 1; }
148
 
149
  hard_task_def_wcet(m,1600000);
150
  hard_task_def_mit(m,21000000);
151
  PC_res_default_model(r,1);
152
  SRP_res_default_model(srp,2);
153
  p1 = task_createn("J2", j2, (TASK_MODEL *)&m, &r, &srp, NULL);
154
  if (p1 == NIL)
155
  { cprintf("Can't create J2 task...\n"); return 1; }
156
 
157
  hard_task_def_wcet(m,3000000);
158
  hard_task_def_mit(m,100000000);
159
  PC_res_default_model(r,2);
160
  SRP_res_default_model(srp,1);
161
  p2 = task_createn("J3", j3, (TASK_MODEL *)&m, &r, &srp, SRP_usemutex(&m0), NULL);
162
  if (p2 == NIL)
163
  { cprintf("Can't create J3 task...\n"); return 1; }
164
 
165
 
166
  /* ---------------------------------------------------------------------
167
     Event post
168
     --------------------------------------------------------------------- */
169
 
170
  t.tv_sec = 0;
171
  t.tv_nsec = 500000000;
172
 
173
  kern_cli();
174
  kern_event_post(&t,startJ,(void *)p0);
175
 
176
  t.tv_sec = 1;
177
  kern_event_post(&t,startJ,(void *)p1);
178
  kern_sti();
179
 
180
  task_activate(p2);
181
 
1377 giacomo 182
  do {
183
    sys_gettime(&t);
184
  } while (t.tv_sec < 60);
185
 
186
  sys_end();
1120 pj 187
 
188
  return 0;
189
}