1 | /* |
---|
2 | * COPYRIGHT (c) 1989-1999. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.OARcorp.com/rtems/license.html. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #include <stdio.h> |
---|
13 | #include <rtems.h> |
---|
14 | #include <rtems/error.h> |
---|
15 | |
---|
16 | static rtems_id taskId1; |
---|
17 | static rtems_id taskId2; |
---|
18 | rtems_interval ticksPerSecond; |
---|
19 | |
---|
20 | #include "system.h" |
---|
21 | |
---|
22 | static int |
---|
23 | isSuspended (rtems_id tid) |
---|
24 | { |
---|
25 | rtems_status_code sc; |
---|
26 | |
---|
27 | sc = rtems_task_is_suspended (tid); |
---|
28 | if (sc == RTEMS_ALREADY_SUSPENDED) |
---|
29 | return 1; |
---|
30 | if (sc != RTEMS_SUCCESSFUL) |
---|
31 | printf ("rtems_task_is_suspended: %s\n", rtems_status_text (sc)); |
---|
32 | return 0; |
---|
33 | } |
---|
34 | |
---|
35 | static void |
---|
36 | subTask1 (rtems_task_argument arg) |
---|
37 | { |
---|
38 | rtems_status_code sc; |
---|
39 | |
---|
40 | rtems_task_wake_after (ticksPerSecond * 3); |
---|
41 | sc = rtems_event_send (taskId2, 1); |
---|
42 | if (sc != RTEMS_SUCCESSFUL) { |
---|
43 | printf ("subTask1 - Can't send event (%d)\n", sc); |
---|
44 | rtems_task_suspend (RTEMS_SELF); |
---|
45 | } |
---|
46 | rtems_task_wake_after (ticksPerSecond * 3); |
---|
47 | printf ("subTask1 - Event sent\n"); |
---|
48 | rtems_task_suspend (RTEMS_SELF); |
---|
49 | printf ("subTask1 - Back to task 1\n"); |
---|
50 | rtems_task_wake_after (ticksPerSecond * 3); |
---|
51 | rtems_task_suspend (RTEMS_SELF); |
---|
52 | } |
---|
53 | |
---|
54 | static void |
---|
55 | subTask2 (rtems_task_argument arg) |
---|
56 | { |
---|
57 | rtems_status_code sc; |
---|
58 | rtems_event_set ev; |
---|
59 | |
---|
60 | rtems_task_wake_after (ticksPerSecond * 1); |
---|
61 | sc = rtems_event_receive (1, RTEMS_WAIT|RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &ev); |
---|
62 | if (sc != RTEMS_SUCCESSFUL) { |
---|
63 | printf ("subTask2 - Can't receive event (%d)\n", sc); |
---|
64 | rtems_task_suspend (RTEMS_SELF); |
---|
65 | } |
---|
66 | printf ("subTask2 - Task 1 suspended? - should be 0: %d\n", |
---|
67 | isSuspended (taskId1)); |
---|
68 | rtems_task_wake_after (ticksPerSecond * 4); |
---|
69 | printf ("subTask2 - Task 1 suspended? - should be 1: %d\n", |
---|
70 | isSuspended (taskId1)); |
---|
71 | rtems_task_resume (taskId1); |
---|
72 | printf ("subTask2 - Task 1 suspended? - should be 0: %d\n", |
---|
73 | isSuspended (taskId1)); |
---|
74 | rtems_task_wake_after (ticksPerSecond * 4); |
---|
75 | printf ("subTask2 - Task 1 suspended? - should be 1: %d\n", |
---|
76 | isSuspended (taskId1)); |
---|
77 | |
---|
78 | puts( "*** END OF TEST 26 ***" ); |
---|
79 | rtems_test_exit( 0 ); |
---|
80 | } |
---|
81 | |
---|
82 | static void |
---|
83 | createTask (char c, rtems_id *tid) |
---|
84 | { |
---|
85 | rtems_status_code sc; |
---|
86 | |
---|
87 | sc = rtems_task_create (rtems_build_name('S','u','b',c), |
---|
88 | 100, |
---|
89 | RTEMS_MINIMUM_STACK_SIZE * 4, |
---|
90 | RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0), |
---|
91 | RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL, |
---|
92 | tid); |
---|
93 | if (sc != RTEMS_SUCCESSFUL) { |
---|
94 | printf ("Can't create task (%d)\n", sc); |
---|
95 | rtems_task_suspend (RTEMS_SELF); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | static void |
---|
100 | startTask (rtems_id tid, rtems_task_entry entry_point) |
---|
101 | { |
---|
102 | rtems_status_code sc; |
---|
103 | |
---|
104 | sc = rtems_task_start (tid, entry_point, 0); |
---|
105 | if (sc != RTEMS_SUCCESSFUL) { |
---|
106 | printf ("Can't start task (%d)\n", sc); |
---|
107 | rtems_task_suspend (RTEMS_SELF); |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | void |
---|
112 | task1 (void) |
---|
113 | { |
---|
114 | rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond); |
---|
115 | createTask ('1', &taskId1); |
---|
116 | createTask ('2', &taskId2); |
---|
117 | startTask (taskId1, subTask1); |
---|
118 | startTask (taskId2, subTask2); |
---|
119 | rtems_task_suspend (RTEMS_SELF); |
---|
120 | } |
---|