1 | /* |
---|
2 | * Interrupt Disable/Enable Tests |
---|
3 | * Clock Tick from task level |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-2009. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.com/license/LICENSE. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ |
---|
16 | #define CONFIGURE_INIT |
---|
17 | #include "system.h" |
---|
18 | |
---|
19 | /* HACK: API visibilty violation */ |
---|
20 | extern rtems_attribute rtems_interrupt_level_attribute(uint32_t level); |
---|
21 | |
---|
22 | /* prototypes */ |
---|
23 | void test_interrupt_inline(void); |
---|
24 | void check_isr_in_progress_inline(void); |
---|
25 | rtems_task blocked_task(rtems_task_argument argument); |
---|
26 | rtems_timer_service_routine test_unblock_task( |
---|
27 | rtems_id timer, |
---|
28 | void *arg |
---|
29 | ); |
---|
30 | rtems_timer_service_routine test_unblock_task( |
---|
31 | rtems_id timer, |
---|
32 | void *arg |
---|
33 | ); |
---|
34 | void check_isr_worked( |
---|
35 | char *s, |
---|
36 | int result |
---|
37 | ); |
---|
38 | rtems_timer_service_routine test_isr_in_progress( |
---|
39 | rtems_id timer, |
---|
40 | void *arg |
---|
41 | ); |
---|
42 | |
---|
43 | /* test bodies */ |
---|
44 | void test_interrupt_inline(void) |
---|
45 | { |
---|
46 | rtems_interrupt_level level; |
---|
47 | rtems_attribute level_attribute, level_attribute_macro; |
---|
48 | bool in_isr; |
---|
49 | |
---|
50 | puts( "interrupt is in progress (use body)" ); |
---|
51 | in_isr = rtems_interrupt_is_in_progress(); |
---|
52 | if ( in_isr ) { |
---|
53 | puts( "interrupt reported to be is in progress (body)" ); |
---|
54 | rtems_test_exit( 0 ); |
---|
55 | } |
---|
56 | |
---|
57 | puts( "interrupt disable (use inline)" ); |
---|
58 | rtems_interrupt_disable( level ); |
---|
59 | |
---|
60 | puts( "interrupt flash (use inline)" ); |
---|
61 | rtems_interrupt_flash( level ); |
---|
62 | |
---|
63 | puts( "interrupt enable (use inline)" ); |
---|
64 | rtems_interrupt_enable( level ); |
---|
65 | |
---|
66 | puts( "interrupt level attribute (use inline)" ); |
---|
67 | level_attribute = rtems_interrupt_level_attribute( level ); |
---|
68 | level_attribute_macro = RTEMS_INTERRUPT_LEVEL(level); |
---|
69 | if ( level_attribute_macro == level_attribute ) { |
---|
70 | puts( "test case working.." ); |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | volatile int isr_in_progress_body; |
---|
75 | volatile int isr_in_progress_inline; |
---|
76 | |
---|
77 | void check_isr_in_progress_inline(void) |
---|
78 | { |
---|
79 | bool in_isr; |
---|
80 | |
---|
81 | in_isr = rtems_interrupt_is_in_progress(); |
---|
82 | isr_in_progress_inline = ( in_isr ) ? 1 : 2; |
---|
83 | } |
---|
84 | |
---|
85 | #undef rtems_interrupt_disable |
---|
86 | extern rtems_interrupt_level rtems_interrupt_disable(void); |
---|
87 | #undef rtems_interrupt_enable |
---|
88 | extern void rtems_interrupt_enable(rtems_interrupt_level previous_level); |
---|
89 | #undef rtems_interrupt_flash |
---|
90 | extern void rtems_interrupt_flash(rtems_interrupt_level previous_level); |
---|
91 | #undef rtems_interrupt_is_in_progress |
---|
92 | extern bool rtems_interrupt_is_in_progress(void); |
---|
93 | |
---|
94 | rtems_timer_service_routine test_isr_in_progress( |
---|
95 | rtems_id timer, |
---|
96 | void *arg |
---|
97 | ) |
---|
98 | { |
---|
99 | bool in_isr; |
---|
100 | |
---|
101 | check_isr_in_progress_inline(); |
---|
102 | |
---|
103 | in_isr = rtems_interrupt_is_in_progress(); |
---|
104 | isr_in_progress_body = ( in_isr ) ? 1 : 2; |
---|
105 | } |
---|
106 | |
---|
107 | void check_isr_worked( |
---|
108 | char *s, |
---|
109 | int result |
---|
110 | ) |
---|
111 | { |
---|
112 | switch (result) { |
---|
113 | case -1: |
---|
114 | printf( "isr_in_progress(%s) timer did not fire\n", s ); |
---|
115 | break; |
---|
116 | case 1: |
---|
117 | printf( "isr_in_progress(%s) from ISR -- OK\n", s ); |
---|
118 | break; |
---|
119 | case 2: |
---|
120 | printf( "isr_in_progress(%s) from ISR -- returned bad value\n", s); |
---|
121 | rtems_test_exit(0); |
---|
122 | break; |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | volatile int blocked_task_status; |
---|
127 | rtems_id blocked_task_id; |
---|
128 | |
---|
129 | rtems_task blocked_task( |
---|
130 | rtems_task_argument argument |
---|
131 | ) |
---|
132 | { |
---|
133 | rtems_status_code status; |
---|
134 | |
---|
135 | puts( "Blocking task... suspending self" ); |
---|
136 | blocked_task_status = 1; |
---|
137 | status = rtems_task_suspend( RTEMS_SELF ); |
---|
138 | directive_failed( status, "rtems_task_suspend" ); |
---|
139 | |
---|
140 | blocked_task_status = 3; |
---|
141 | status = rtems_task_delete( RTEMS_SELF ); |
---|
142 | directive_failed( status, "rtems_task_delete" ); |
---|
143 | } |
---|
144 | |
---|
145 | /* |
---|
146 | * Timer Service Routine |
---|
147 | * |
---|
148 | * If we are in an ISR, then this is a normal clock tick. |
---|
149 | * If we are not, then it is the test case. |
---|
150 | */ |
---|
151 | rtems_timer_service_routine test_unblock_task( |
---|
152 | rtems_id timer, |
---|
153 | void *arg |
---|
154 | ) |
---|
155 | { |
---|
156 | bool in_isr; |
---|
157 | rtems_status_code status; |
---|
158 | |
---|
159 | in_isr = rtems_interrupt_is_in_progress(); |
---|
160 | status = rtems_task_is_suspended( blocked_task_id ); |
---|
161 | if ( in_isr ) { |
---|
162 | status = rtems_timer_fire_after( timer, 1, test_unblock_task, NULL ); |
---|
163 | directive_failed( status, "timer_fire_after failed" ); |
---|
164 | return; |
---|
165 | } |
---|
166 | |
---|
167 | if ( (status != RTEMS_ALREADY_SUSPENDED) ) { |
---|
168 | status = rtems_timer_fire_after( timer, 1, test_unblock_task, NULL ); |
---|
169 | directive_failed( status, "timer_fire_after failed" ); |
---|
170 | return; |
---|
171 | } |
---|
172 | |
---|
173 | blocked_task_status = 2; |
---|
174 | _Thread_Disable_dispatch(); |
---|
175 | status = rtems_task_resume( blocked_task_id ); |
---|
176 | _Thread_Unnest_dispatch(); |
---|
177 | directive_failed( status, "rtems_task_resume" ); |
---|
178 | } |
---|
179 | |
---|
180 | rtems_task Init( |
---|
181 | rtems_task_argument argument |
---|
182 | ) |
---|
183 | { |
---|
184 | rtems_time_of_day time; |
---|
185 | rtems_status_code status; |
---|
186 | rtems_interrupt_level level; |
---|
187 | rtems_attribute level_attribute,level_attribute_macro; |
---|
188 | bool in_isr; |
---|
189 | rtems_id timer; |
---|
190 | int i; |
---|
191 | |
---|
192 | puts( "\n\n*** TEST 37 ***" ); |
---|
193 | |
---|
194 | build_time( &time, 12, 31, 1988, 9, 0, 0, 0 ); |
---|
195 | status = rtems_clock_set( &time ); |
---|
196 | directive_failed( status, "rtems_clock_set" ); |
---|
197 | |
---|
198 | /* |
---|
199 | * Timer used in multiple ways |
---|
200 | */ |
---|
201 | status = rtems_timer_create( 1, &timer ); |
---|
202 | directive_failed( status, "rtems_timer_create" ); |
---|
203 | |
---|
204 | /* |
---|
205 | * Test clock tick from outside ISR |
---|
206 | */ |
---|
207 | status = rtems_clock_tick(); |
---|
208 | directive_failed( status, "rtems_clock_tick" ); |
---|
209 | puts( "clock_tick from task level" ); |
---|
210 | |
---|
211 | /* |
---|
212 | * Now do a dispatch directly out of a clock tick that is |
---|
213 | * called from a task. We need to create a task that will |
---|
214 | * block so we have one to unblock. Then we schedule a TSR |
---|
215 | * to run in the clock tick but it has to be careful to |
---|
216 | * make sure it is not called from an ISR and that the |
---|
217 | * dispatching critical section is managed properly to |
---|
218 | * make the dispatch happen. |
---|
219 | */ |
---|
220 | |
---|
221 | blocked_task_status = -1; |
---|
222 | |
---|
223 | status = rtems_task_create( |
---|
224 | rtems_build_name( 'T', 'A', '1', ' ' ), |
---|
225 | 1, |
---|
226 | RTEMS_MINIMUM_STACK_SIZE, |
---|
227 | RTEMS_DEFAULT_MODES, |
---|
228 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
229 | &blocked_task_id |
---|
230 | ); |
---|
231 | directive_failed( status, "rtems_task_create" ); |
---|
232 | |
---|
233 | status = rtems_task_start( blocked_task_id, blocked_task, 0 ); |
---|
234 | directive_failed( status, "rtems_task_start" ); |
---|
235 | |
---|
236 | status = rtems_task_wake_after( 10 ); |
---|
237 | directive_failed( status, "rtems_task_wake_after" ); |
---|
238 | |
---|
239 | status = rtems_timer_fire_after( timer, 1, test_unblock_task, NULL ); |
---|
240 | directive_failed( status, "timer_fire_after failed" ); |
---|
241 | |
---|
242 | /* we expect to be preempted from this call */ |
---|
243 | for ( i=0 ; i<100 && blocked_task_status != 3 ; i++ ) { |
---|
244 | status = rtems_clock_tick(); |
---|
245 | directive_failed( status, "rtems_clock_tick" ); |
---|
246 | } |
---|
247 | switch ( blocked_task_status ) { |
---|
248 | case -1: |
---|
249 | puts( "clock_tick with task preempt -- task blocked, timer did not fire" ); |
---|
250 | rtems_test_exit(0); |
---|
251 | break; |
---|
252 | case 1: |
---|
253 | puts( "clock_tick with task preempt -- timer fired case 1" ); |
---|
254 | rtems_test_exit(0); |
---|
255 | break; |
---|
256 | case 2: |
---|
257 | puts( "clock_tick with task preempt -- timer fired case 2" ); |
---|
258 | rtems_test_exit(0); |
---|
259 | break; |
---|
260 | case 3: |
---|
261 | puts( "clock_tick from task level with preempt -- OK" ); |
---|
262 | break; |
---|
263 | } |
---|
264 | |
---|
265 | /* |
---|
266 | * Test interrupt inline versions |
---|
267 | */ |
---|
268 | test_interrupt_inline(); |
---|
269 | |
---|
270 | /* |
---|
271 | * Test interrupt bodies |
---|
272 | */ |
---|
273 | puts( "interrupt is in progress (use body)" ); |
---|
274 | in_isr = rtems_interrupt_is_in_progress(); |
---|
275 | if ( in_isr ) { |
---|
276 | puts( "interrupt reported to be is in progress (body)" ); |
---|
277 | rtems_test_exit( 0 ); |
---|
278 | } |
---|
279 | |
---|
280 | puts( "interrupt disable (use body)" ); |
---|
281 | level = rtems_interrupt_disable(); |
---|
282 | |
---|
283 | puts( "interrupt disable (use body)" ); |
---|
284 | level = rtems_interrupt_disable(); |
---|
285 | |
---|
286 | puts( "interrupt flash (use body)" ); |
---|
287 | rtems_interrupt_flash( level ); |
---|
288 | |
---|
289 | puts( "interrupt enable (use body)" ); |
---|
290 | rtems_interrupt_enable( level ); |
---|
291 | |
---|
292 | puts( "interrupt level attribute (use body)" ); |
---|
293 | level_attribute = rtems_interrupt_level_attribute( level ); |
---|
294 | level_attribute_macro = RTEMS_INTERRUPT_LEVEL(level); |
---|
295 | if ( level_attribute_macro == level_attribute ) { |
---|
296 | puts("test seems to work"); |
---|
297 | } |
---|
298 | |
---|
299 | /* |
---|
300 | * Test ISR in progress from actual ISR |
---|
301 | */ |
---|
302 | isr_in_progress_body = -1; |
---|
303 | isr_in_progress_inline = -1; |
---|
304 | |
---|
305 | status = rtems_timer_fire_after( timer, 10, test_isr_in_progress, NULL ); |
---|
306 | directive_failed( status, "timer_fire_after failed" ); |
---|
307 | |
---|
308 | status = rtems_task_wake_after( 100 ); |
---|
309 | directive_failed( status, "wake_after failed" ); |
---|
310 | |
---|
311 | check_isr_worked( "inline", isr_in_progress_body ); |
---|
312 | |
---|
313 | check_isr_worked( "body", isr_in_progress_body ); |
---|
314 | |
---|
315 | |
---|
316 | puts( "*** END OF TEST 37 ***" ); |
---|
317 | rtems_test_exit( 0 ); |
---|
318 | } |
---|