1 | /* |
---|
2 | * Classic API Signal to Task from ISR |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2008. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #define TEST_INIT |
---|
15 | #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 1 |
---|
16 | #include "system.h" |
---|
17 | |
---|
18 | volatile boolean case_hit; |
---|
19 | |
---|
20 | rtems_id main_task; |
---|
21 | rtems_id Semaphore; |
---|
22 | |
---|
23 | Thread_blocking_operation_States getState(void) |
---|
24 | { |
---|
25 | Objects_Locations location; |
---|
26 | Semaphore_Control *sem; |
---|
27 | |
---|
28 | sem = (Semaphore_Control *)_Objects_Get( |
---|
29 | &_Semaphore_Information, Semaphore, &location ); |
---|
30 | if ( location != OBJECTS_LOCAL ) { |
---|
31 | puts( "Bad object lookup" ); |
---|
32 | rtems_test_exit(0); |
---|
33 | } |
---|
34 | _Thread_Unnest_dispatch(); |
---|
35 | |
---|
36 | return sem->Core_control.semaphore.Wait_queue.sync_state; |
---|
37 | } |
---|
38 | |
---|
39 | rtems_timer_service_routine test_release_from_isr( |
---|
40 | rtems_id timer, |
---|
41 | void *arg |
---|
42 | ) |
---|
43 | { |
---|
44 | rtems_status_code status; |
---|
45 | |
---|
46 | if ( getState() == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) { |
---|
47 | case_hit = TRUE; |
---|
48 | } |
---|
49 | status = rtems_semaphore_release( Semaphore ); |
---|
50 | } |
---|
51 | |
---|
52 | rtems_timer_service_routine test_release_with_timeout_from_isr( |
---|
53 | rtems_id timer, |
---|
54 | void *arg |
---|
55 | ) |
---|
56 | { |
---|
57 | rtems_status_code status; |
---|
58 | |
---|
59 | if ( getState() == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) { |
---|
60 | /* |
---|
61 | * We want to catch the task while it is blocking. Otherwise |
---|
62 | * just send and make it happy. |
---|
63 | */ |
---|
64 | case_hit = TRUE; |
---|
65 | } |
---|
66 | status = rtems_semaphore_release( Semaphore ); |
---|
67 | } |
---|
68 | |
---|
69 | rtems_task Init( |
---|
70 | rtems_task_argument argument |
---|
71 | ) |
---|
72 | { |
---|
73 | rtems_status_code status; |
---|
74 | rtems_id timer; |
---|
75 | int i; |
---|
76 | int max; |
---|
77 | int iterations = 0; |
---|
78 | |
---|
79 | puts( "\n\n*** TEST 41 ***" ); |
---|
80 | |
---|
81 | main_task = rtems_task_self(); |
---|
82 | |
---|
83 | /* |
---|
84 | * Timer used in multiple ways |
---|
85 | */ |
---|
86 | status = rtems_timer_create( 1, &timer ); |
---|
87 | directive_failed( status, "rtems_timer_create" ); |
---|
88 | |
---|
89 | status = rtems_semaphore_create( |
---|
90 | rtems_build_name( 'S', 'M', '1', ' ' ), |
---|
91 | 1, |
---|
92 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
93 | RTEMS_NO_PRIORITY, |
---|
94 | &Semaphore |
---|
95 | ); |
---|
96 | directive_failed( status, "rtems_semaphore_create of SM1" ); |
---|
97 | |
---|
98 | /* |
---|
99 | * Test semaphore release successful from ISR -- obtain is forever |
---|
100 | */ |
---|
101 | case_hit = FALSE; |
---|
102 | iterations = 0; |
---|
103 | max = 1; |
---|
104 | |
---|
105 | while (1) { |
---|
106 | if ( case_hit ) |
---|
107 | break; |
---|
108 | status = rtems_timer_fire_after( timer, 1, test_release_from_isr, NULL ); |
---|
109 | directive_failed( status, "timer_fire_after failed" ); |
---|
110 | |
---|
111 | for (i=0 ; i<max ; i++ ) |
---|
112 | if ( getState() == THREAD_BLOCKING_OPERATION_SATISFIED ) |
---|
113 | break; |
---|
114 | |
---|
115 | status = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 0 ); |
---|
116 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
117 | if ( case_hit == TRUE ) |
---|
118 | break; |
---|
119 | max += 2; |
---|
120 | |
---|
121 | /* with our clock tick, this is about 30 seconds */ |
---|
122 | if ( ++iterations >= 4 * 1000 * 30) |
---|
123 | break; |
---|
124 | } |
---|
125 | |
---|
126 | status = rtems_semaphore_release( Semaphore ); |
---|
127 | directive_failed( status, "rtems_semaphore_release" ); |
---|
128 | printf( |
---|
129 | "Release from ISR hitting synchronization point has %soccurred\n", |
---|
130 | (( case_hit == TRUE ) ? "" : "NOT ") |
---|
131 | ); |
---|
132 | |
---|
133 | /* |
---|
134 | * Test semaphore release successful from ISR -- obtain has timeout |
---|
135 | */ |
---|
136 | case_hit = FALSE; |
---|
137 | iterations = 0; |
---|
138 | max = 1; |
---|
139 | |
---|
140 | while (1) { |
---|
141 | if ( case_hit ) |
---|
142 | break; |
---|
143 | status = rtems_timer_fire_after( |
---|
144 | timer, 1, test_release_with_timeout_from_isr, NULL ); |
---|
145 | directive_failed( status, "timer_fire_after failed" ); |
---|
146 | |
---|
147 | for (i=0 ; i<max ; i++ ) |
---|
148 | if ( getState() == THREAD_BLOCKING_OPERATION_SATISFIED ) |
---|
149 | break; |
---|
150 | |
---|
151 | status = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 10 ); |
---|
152 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
153 | if ( case_hit == TRUE ) |
---|
154 | break; |
---|
155 | max += 2; |
---|
156 | |
---|
157 | /* with our clock tick, this is about 30 seconds */ |
---|
158 | if ( ++iterations >= 4 * 1000 * 30) |
---|
159 | break; |
---|
160 | } |
---|
161 | |
---|
162 | printf( |
---|
163 | "Release from ISR (with timeout) hitting synchronization " |
---|
164 | "point has %soccurred\n", |
---|
165 | (( case_hit == TRUE ) ? "" : "NOT ") |
---|
166 | ); |
---|
167 | |
---|
168 | /* |
---|
169 | * Now try for a timeout case -- semaphore must not be available |
---|
170 | */ |
---|
171 | iterations = 0; |
---|
172 | case_hit = FALSE; |
---|
173 | max = 1; |
---|
174 | |
---|
175 | puts( |
---|
176 | "Run multiple times in attempt to hit threadq timeout synchronization point" |
---|
177 | ); |
---|
178 | while (1) { |
---|
179 | |
---|
180 | for (i=0 ; i<max ; i++ ) |
---|
181 | if ( getState() == THREAD_BLOCKING_OPERATION_SATISFIED ) |
---|
182 | break; |
---|
183 | |
---|
184 | status = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 1 ); |
---|
185 | fatal_directive_status( status, RTEMS_TIMEOUT, "rtems_semaphore_obtain" ); |
---|
186 | |
---|
187 | if ( ++max > 10240 ) |
---|
188 | max = 0; |
---|
189 | |
---|
190 | /* with our clock tick, this is about 30 seconds */ |
---|
191 | if ( ++iterations >= 4 * 1000 * 30) |
---|
192 | break; |
---|
193 | } |
---|
194 | |
---|
195 | puts( "*** END OF TEST 41 ***" ); |
---|
196 | rtems_test_exit( 0 ); |
---|
197 | } |
---|