1 | /* |
---|
2 | * Classic API Signal to Task from ISR |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2011. |
---|
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.org/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #define CONFIGURE_INIT |
---|
17 | #include "system.h" |
---|
18 | |
---|
19 | #include <intrcritical.h> |
---|
20 | |
---|
21 | #include <rtems/score/threadimpl.h> |
---|
22 | #include <rtems/rtems/eventimpl.h> |
---|
23 | |
---|
24 | const char rtems_test_name[] = "SPINTRCRITICAL 21"; |
---|
25 | |
---|
26 | /* |
---|
27 | * ERROR CHECKING NOTE: |
---|
28 | * |
---|
29 | * We are either at dispatch disable level 1 or 2. Either way, it is |
---|
30 | * safer not to check the dispatch level explicitly so we are using |
---|
31 | * fatal_directive_check_status_only() not directive_failed(). |
---|
32 | */ |
---|
33 | |
---|
34 | static volatile bool case_hit; |
---|
35 | |
---|
36 | static rtems_id main_task; |
---|
37 | |
---|
38 | static Thread_Control *main_thread; |
---|
39 | |
---|
40 | static rtems_id other_task; |
---|
41 | |
---|
42 | static bool is_case_hit( void ) |
---|
43 | { |
---|
44 | return _Thread_Wait_flags_get( main_thread) |
---|
45 | == ( THREAD_WAIT_CLASS_EVENT | THREAD_WAIT_STATE_INTEND_TO_BLOCK ); |
---|
46 | } |
---|
47 | |
---|
48 | static rtems_timer_service_routine test_event_from_isr( |
---|
49 | rtems_id timer, |
---|
50 | void *arg |
---|
51 | ) |
---|
52 | { |
---|
53 | rtems_status_code status; |
---|
54 | |
---|
55 | if ( is_case_hit() ) { |
---|
56 | /* |
---|
57 | * This event send hits the critical section but sends to |
---|
58 | * another task so doesn't impact this critical section. |
---|
59 | */ |
---|
60 | status = rtems_event_send( other_task, 0x02 ); |
---|
61 | fatal_directive_check_status_only( status, RTEMS_SUCCESSFUL, "event send" ); |
---|
62 | |
---|
63 | /* |
---|
64 | * This event send hits the main task but doesn't satisfy |
---|
65 | * it's blocking condition so it will still block |
---|
66 | */ |
---|
67 | status = rtems_event_send( main_task, 0x02 ); |
---|
68 | fatal_directive_check_status_only( status, RTEMS_SUCCESSFUL, "event send" ); |
---|
69 | |
---|
70 | case_hit = true; |
---|
71 | } |
---|
72 | status = rtems_event_send( main_task, 0x01 ); |
---|
73 | fatal_directive_check_status_only( status, RTEMS_SUCCESSFUL, "event send" ); |
---|
74 | } |
---|
75 | |
---|
76 | static bool test_body_event_from_isr( void *arg ) |
---|
77 | { |
---|
78 | rtems_status_code status; |
---|
79 | rtems_event_set out; |
---|
80 | |
---|
81 | (void) arg; |
---|
82 | |
---|
83 | status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 0, &out ); |
---|
84 | rtems_test_assert( status == RTEMS_SUCCESSFUL ); |
---|
85 | |
---|
86 | return case_hit; |
---|
87 | } |
---|
88 | |
---|
89 | static rtems_timer_service_routine test_event_with_timeout_from_isr( |
---|
90 | rtems_id timer, |
---|
91 | void *arg |
---|
92 | ) |
---|
93 | { |
---|
94 | rtems_status_code status; |
---|
95 | |
---|
96 | if ( is_case_hit() ) { |
---|
97 | /* |
---|
98 | * We want to catch the task while it is blocking. Otherwise |
---|
99 | * just send and make it happy. |
---|
100 | */ |
---|
101 | case_hit = true; |
---|
102 | } |
---|
103 | status = rtems_event_send( main_task, 0x01 ); |
---|
104 | fatal_directive_check_status_only( status, RTEMS_SUCCESSFUL, "event send" ); |
---|
105 | } |
---|
106 | |
---|
107 | static bool test_body_event_with_timeout_from_isr( void *arg ) |
---|
108 | { |
---|
109 | rtems_status_code status; |
---|
110 | rtems_event_set out; |
---|
111 | |
---|
112 | (void) arg; |
---|
113 | |
---|
114 | status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 1, &out ); |
---|
115 | rtems_test_assert( status == RTEMS_SUCCESSFUL || status == RTEMS_TIMEOUT ); |
---|
116 | |
---|
117 | return case_hit; |
---|
118 | } |
---|
119 | |
---|
120 | rtems_task Init( |
---|
121 | rtems_task_argument argument |
---|
122 | ) |
---|
123 | { |
---|
124 | rtems_status_code status; |
---|
125 | |
---|
126 | TEST_BEGIN(); |
---|
127 | |
---|
128 | main_task = rtems_task_self(); |
---|
129 | main_thread = _Thread_Get_executing(); |
---|
130 | |
---|
131 | status = rtems_task_create( |
---|
132 | 0xa5a5a5a5, |
---|
133 | 1, |
---|
134 | RTEMS_MINIMUM_STACK_SIZE, |
---|
135 | RTEMS_DEFAULT_MODES, |
---|
136 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
137 | &other_task |
---|
138 | ); |
---|
139 | directive_failed( status, "rtems_task_create" ); |
---|
140 | |
---|
141 | /* |
---|
142 | * Test Event send successful from ISR -- receive is forever |
---|
143 | */ |
---|
144 | |
---|
145 | case_hit = false; |
---|
146 | interrupt_critical_section_test( |
---|
147 | test_body_event_from_isr, |
---|
148 | NULL, |
---|
149 | test_event_from_isr |
---|
150 | ); |
---|
151 | |
---|
152 | printf( |
---|
153 | "Event sent from ISR hitting synchronization point has %soccurred\n", |
---|
154 | case_hit ? "" : "NOT " |
---|
155 | ); |
---|
156 | |
---|
157 | rtems_test_assert( case_hit ); |
---|
158 | |
---|
159 | /* |
---|
160 | * Test Event send successful from ISR -- receive has timeout |
---|
161 | */ |
---|
162 | |
---|
163 | case_hit = false; |
---|
164 | interrupt_critical_section_test( |
---|
165 | test_body_event_with_timeout_from_isr, |
---|
166 | NULL, |
---|
167 | test_event_with_timeout_from_isr |
---|
168 | ); |
---|
169 | |
---|
170 | printf( |
---|
171 | "Event sent from ISR (with timeout) hitting synchronization " |
---|
172 | "point has %soccurred\n", |
---|
173 | case_hit ? "" : "NOT " |
---|
174 | ); |
---|
175 | |
---|
176 | rtems_test_assert( case_hit ); |
---|
177 | |
---|
178 | TEST_END(); |
---|
179 | rtems_test_exit( 0 ); |
---|
180 | } |
---|