Subversion Repositories shark

Rev

Rev 1547 | 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
 *
1547 pj 37
 * CVS :        $Id: pidemo.c,v 1.4 2005-01-08 14:31:38 pj Exp $
1120 pj 38
 
39
 This test verify the correctness of the PI module.
40
 
41
 the main task (NRT) lock a PI mutex.
42
 then 2 tasks arrives, with priority higher than the main
43
 
44
 the first try to lock the mutex, but it can't, so the main inherit
45
 his priority. The second simply prints a string.
46
 
47
 If all works, the string of the second task is printed after the end of
48
 the first task.
49
 
50
*/
51
 
52
#include "kernel/kern.h"
53
 
54
mutex_t        m1;
55
 
56
 
57
TASK goofy1(void *a)
58
{
59
  cprintf("goofy1 before mutex_lock\n");
60
  mutex_lock(&m1);
61
  cprintf("goofy1 after mutex_lock\n");
62
 
63
  mutex_unlock(&m1);
64
  cprintf("goofy1 after mutex_unlock\n");
65
 
66
  return 0;
67
}
68
 
69
TASK goofy2()
70
{
71
 cprintf("goofy2 inside goofy2\n");
72
 return 0;
73
}
74
 
75
int main(int argc, char **argv)
76
{
77
  HARD_TASK_MODEL m;
78
  PID p2,p3;
79
 
1377 giacomo 80
  struct timespec t;
81
 
1120 pj 82
  PI_mutexattr_t a;
83
 
84
  hard_task_default_model(m);
85
  hard_task_def_mit(m,50000);
86
  hard_task_def_wcet(m,20000);
87
  hard_task_def_group(m,1);
88
 
89
  hard_task_def_arg(m,(void *)1);
90
  p2 = task_create("goofy1", goofy1, &m, NULL);
91
  if (p2 == NIL)
92
  { cprintf("Can't create goofy1 task...\n"); return 1; }
93
 
94
  hard_task_def_mit(m,100000);
95
  p3 = task_create("goofy2", goofy2, &m, NULL);
96
  if (p3 == NIL)
97
  { cprintf("Can't create goofy2 task...\n"); return 1; }
98
 
99
  PI_mutexattr_default(a);
100
  mutex_init(&m1,&a);
101
 
102
  cprintf("main before mutex_lock\n");
103
  mutex_lock(&m1);
104
  cprintf("main after mutex_lock\n");
105
 
106
  group_activate(1);
107
 
108
  cprintf("main after group_activate\n");
109
  mutex_unlock(&m1);
110
  cprintf("main after mutex_unlock\n");
111
 
112
  mutex_destroy(&m1);
113
  cprintf("main after mutex_destroy\n");
114
 
1377 giacomo 115
  do {
116
    sys_gettime(&t);
117
  } while (t.tv_sec < 10);
118
 
1547 pj 119
  exit(0);
1377 giacomo 120
 
1120 pj 121
  return 0;
1377 giacomo 122
 
1120 pj 123
}