Rev 1120 | Rev 1377 | 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 | * |
||
1123 | pj | 37 | * CVS : $Id: pidemo.c,v 1.2 2003-01-07 17:10:15 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 | |||
80 | PI_mutexattr_t a; |
||
81 | |||
82 | hard_task_default_model(m); |
||
83 | hard_task_def_mit(m,50000); |
||
84 | hard_task_def_wcet(m,20000); |
||
85 | hard_task_def_group(m,1); |
||
86 | |||
87 | hard_task_def_arg(m,(void *)1); |
||
88 | p2 = task_create("goofy1", goofy1, &m, NULL); |
||
89 | if (p2 == NIL) |
||
90 | { cprintf("Can't create goofy1 task...\n"); return 1; } |
||
91 | |||
92 | hard_task_def_mit(m,100000); |
||
93 | p3 = task_create("goofy2", goofy2, &m, NULL); |
||
94 | if (p3 == NIL) |
||
95 | { cprintf("Can't create goofy2 task...\n"); return 1; } |
||
96 | |||
97 | PI_mutexattr_default(a); |
||
98 | mutex_init(&m1,&a); |
||
99 | |||
100 | cprintf("main before mutex_lock\n"); |
||
101 | mutex_lock(&m1); |
||
102 | cprintf("main after mutex_lock\n"); |
||
103 | |||
104 | group_activate(1); |
||
105 | |||
106 | cprintf("main after group_activate\n"); |
||
107 | mutex_unlock(&m1); |
||
108 | cprintf("main after mutex_unlock\n"); |
||
109 | |||
110 | mutex_destroy(&m1); |
||
111 | cprintf("main after mutex_destroy\n"); |
||
112 | |||
113 | return 0; |
||
114 | } |