1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2009. |
---|
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.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 1 |
---|
13 | #include <tmacros.h> |
---|
14 | #include <intrcritical.h> |
---|
15 | |
---|
16 | #if defined(FIFO_NO_TIMEOUT) |
---|
17 | #define TEST_NAME "01" |
---|
18 | #define TEST_STRING "FIFO/Without Timeout" |
---|
19 | #define SEMAPHORE_OBTAIN_TIMEOUT 0 |
---|
20 | #define SEMAPHORE_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES |
---|
21 | |
---|
22 | #elif defined(FIFO_WITH_TIMEOUT) |
---|
23 | #define TEST_NAME "02" |
---|
24 | #define TEST_STRING "FIFO/With Timeout" |
---|
25 | #define SEMAPHORE_OBTAIN_TIMEOUT 10 |
---|
26 | #define SEMAPHORE_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES |
---|
27 | |
---|
28 | #elif defined(PRIORITY_NO_TIMEOUT) |
---|
29 | #define TEST_NAME "03" |
---|
30 | #define TEST_STRING "Priority/Without Timeout" |
---|
31 | #define SEMAPHORE_OBTAIN_TIMEOUT 0 |
---|
32 | #define SEMAPHORE_ATTRIBUTES RTEMS_PRIORITY |
---|
33 | |
---|
34 | #elif defined(PRIORITY_WITH_TIMEOUT) |
---|
35 | #define TEST_NAME "04" |
---|
36 | #define TEST_STRING "Priority/With Timeout" |
---|
37 | #define SEMAPHORE_OBTAIN_TIMEOUT 10 |
---|
38 | #define SEMAPHORE_ATTRIBUTES RTEMS_PRIORITY |
---|
39 | |
---|
40 | #elif defined(PRIORITY_NO_TIMEOUT_REVERSE) |
---|
41 | #define TEST_NAME "05" |
---|
42 | #define TEST_STRING "Priority/Without Timeout (Reverse)" |
---|
43 | #define SEMAPHORE_OBTAIN_TIMEOUT 0 |
---|
44 | #define SEMAPHORE_ATTRIBUTES RTEMS_PRIORITY |
---|
45 | |
---|
46 | #else |
---|
47 | |
---|
48 | #error "Test Mode not defined" |
---|
49 | #endif |
---|
50 | |
---|
51 | rtems_id Main_task; |
---|
52 | rtems_id Semaphore; |
---|
53 | volatile bool case_hit; |
---|
54 | |
---|
55 | Thread_blocking_operation_States getState(void) |
---|
56 | { |
---|
57 | Objects_Locations location; |
---|
58 | Semaphore_Control *sem; |
---|
59 | |
---|
60 | sem = (Semaphore_Control *)_Objects_Get( |
---|
61 | &_Semaphore_Information, Semaphore, &location ); |
---|
62 | if ( location != OBJECTS_LOCAL ) { |
---|
63 | puts( "Bad object lookup" ); |
---|
64 | rtems_test_exit(0); |
---|
65 | } |
---|
66 | _Thread_Unnest_dispatch(); |
---|
67 | |
---|
68 | return sem->Core_control.semaphore.Wait_queue.sync_state; |
---|
69 | } |
---|
70 | |
---|
71 | rtems_timer_service_routine test_release_from_isr( |
---|
72 | rtems_id timer, |
---|
73 | void *arg |
---|
74 | ) |
---|
75 | { |
---|
76 | rtems_status_code status; |
---|
77 | |
---|
78 | if ( getState() == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) { |
---|
79 | case_hit = true; |
---|
80 | } |
---|
81 | status = rtems_semaphore_release( Semaphore ); |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | rtems_task Init( |
---|
87 | rtems_task_argument ignored |
---|
88 | ) |
---|
89 | { |
---|
90 | rtems_status_code status; |
---|
91 | |
---|
92 | puts( "\n\n*** TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***" ); |
---|
93 | |
---|
94 | puts( "Init - Trying to generate semaphore release from ISR while blocking" ); |
---|
95 | puts( "Init - Variation is: " TEST_STRING ); |
---|
96 | status = rtems_semaphore_create( |
---|
97 | rtems_build_name( 'S', 'M', '1', ' ' ), |
---|
98 | 1, |
---|
99 | SEMAPHORE_ATTRIBUTES, |
---|
100 | RTEMS_NO_PRIORITY, |
---|
101 | &Semaphore |
---|
102 | ); |
---|
103 | directive_failed( status, "rtems_semaphore_create of SM1" ); |
---|
104 | |
---|
105 | Main_task = rtems_task_self(); |
---|
106 | |
---|
107 | interrupt_critical_section_test_support_initialize( test_release_from_isr ); |
---|
108 | |
---|
109 | case_hit = false; |
---|
110 | |
---|
111 | while (!case_hit) { |
---|
112 | interrupt_critical_section_test_support_delay(); |
---|
113 | |
---|
114 | status = rtems_semaphore_obtain( |
---|
115 | Semaphore, |
---|
116 | RTEMS_DEFAULT_OPTIONS, |
---|
117 | SEMAPHORE_OBTAIN_TIMEOUT |
---|
118 | ); |
---|
119 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
120 | } |
---|
121 | |
---|
122 | if ( case_hit ) { |
---|
123 | puts( "Init - Case hit" ); |
---|
124 | puts( "*** END OF TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***" ); |
---|
125 | } else |
---|
126 | puts( "Init - Case not hit - ran too long" ); |
---|
127 | |
---|
128 | rtems_test_exit(0); |
---|
129 | } |
---|
130 | |
---|
131 | /* configuration information */ |
---|
132 | |
---|
133 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
134 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
135 | |
---|
136 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
137 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
138 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
139 | #if defined(PRIORITY_NO_TIMEOUT_REVERSE) |
---|
140 | #define CONFIGURE_INIT_TASK_PRIORITY 250 |
---|
141 | #endif |
---|
142 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
143 | |
---|
144 | #define CONFIGURE_INIT |
---|
145 | #include <rtems/confdefs.h> |
---|
146 | |
---|
147 | /* global variables */ |
---|