1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
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.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <tmacros.h> |
---|
15 | #include <intrcritical.h> |
---|
16 | |
---|
17 | #include <rtems/score/threadimpl.h> |
---|
18 | #include <rtems/score/threadimpl.h> |
---|
19 | #include <rtems/score/watchdogimpl.h> |
---|
20 | |
---|
21 | const char rtems_test_name[] = "SPINTRCRITICAL 9"; |
---|
22 | |
---|
23 | static Thread_Control *thread; |
---|
24 | |
---|
25 | static rtems_id Semaphore; |
---|
26 | |
---|
27 | static bool case_hit; |
---|
28 | |
---|
29 | static bool is_interrupt_timeout(void) |
---|
30 | { |
---|
31 | Thread_Wait_flags flags = _Thread_Wait_flags_get( thread ); |
---|
32 | |
---|
33 | return flags == ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_READY_AGAIN ); |
---|
34 | } |
---|
35 | |
---|
36 | static rtems_timer_service_routine test_release_from_isr( |
---|
37 | rtems_id timer, |
---|
38 | void *arg |
---|
39 | ) |
---|
40 | { |
---|
41 | Per_CPU_Control *cpu_self = _Per_CPU_Get(); |
---|
42 | Watchdog_Header *header = &cpu_self->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ]; |
---|
43 | Watchdog_Control *watchdog = (Watchdog_Control *) header->first; |
---|
44 | |
---|
45 | if ( |
---|
46 | watchdog != NULL |
---|
47 | && watchdog->expire == cpu_self->Watchdog.ticks |
---|
48 | && watchdog->routine == _Thread_Timeout |
---|
49 | ) { |
---|
50 | _Watchdog_Per_CPU_remove( watchdog, cpu_self, header ); |
---|
51 | |
---|
52 | (*watchdog->routine)( watchdog ); |
---|
53 | |
---|
54 | if ( is_interrupt_timeout() ) { |
---|
55 | case_hit = true; |
---|
56 | } |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | static bool test_body( void *arg ) |
---|
61 | { |
---|
62 | (void) arg; |
---|
63 | |
---|
64 | rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 1 ); |
---|
65 | |
---|
66 | return case_hit; |
---|
67 | } |
---|
68 | |
---|
69 | static rtems_task Init( |
---|
70 | rtems_task_argument ignored |
---|
71 | ) |
---|
72 | { |
---|
73 | rtems_status_code sc; |
---|
74 | |
---|
75 | TEST_BEGIN(); |
---|
76 | |
---|
77 | thread = _Thread_Get_executing(); |
---|
78 | |
---|
79 | puts( "Init - Test may not be able to detect case is hit reliably" ); |
---|
80 | puts( "Init - Trying to generate timeout from ISR while blocking" ); |
---|
81 | sc = rtems_semaphore_create( |
---|
82 | rtems_build_name( 'S', 'M', '1', ' ' ), |
---|
83 | 0, |
---|
84 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
85 | RTEMS_NO_PRIORITY, |
---|
86 | &Semaphore |
---|
87 | ); |
---|
88 | directive_failed( sc, "rtems_semaphore_create of SM1" ); |
---|
89 | |
---|
90 | interrupt_critical_section_test( test_body, NULL, test_release_from_isr ); |
---|
91 | |
---|
92 | if ( case_hit ) { |
---|
93 | puts( "Init - It appears the case has been hit" ); |
---|
94 | TEST_END(); |
---|
95 | } else |
---|
96 | puts( "Init - Case not hit - ran too long" ); |
---|
97 | |
---|
98 | rtems_test_exit(0); |
---|
99 | } |
---|
100 | |
---|
101 | /* configuration information */ |
---|
102 | |
---|
103 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
104 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
105 | |
---|
106 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
107 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
108 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
109 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 |
---|
110 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
111 | |
---|
112 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
113 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 |
---|
114 | |
---|
115 | #define CONFIGURE_INIT |
---|
116 | #include <rtems/confdefs.h> |
---|
117 | |
---|
118 | /* global variables */ |
---|