1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2011. |
---|
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 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <tmacros.h> |
---|
17 | #include "test_support.h" |
---|
18 | |
---|
19 | volatile bool TaskRan = false; |
---|
20 | volatile bool TSRFired = false; |
---|
21 | rtems_id Semaphore; |
---|
22 | |
---|
23 | rtems_task Test_task( |
---|
24 | rtems_task_argument argument |
---|
25 | ) |
---|
26 | { |
---|
27 | int cpu_num; |
---|
28 | rtems_status_code sc; |
---|
29 | char name[5]; |
---|
30 | char *p; |
---|
31 | |
---|
32 | /* Get the task name */ |
---|
33 | p = rtems_object_get_name( RTEMS_SELF, 5, name ); |
---|
34 | rtems_test_assert( p != NULL ); |
---|
35 | |
---|
36 | /* Get the CPU Number */ |
---|
37 | cpu_num = bsp_smp_processor_id(); |
---|
38 | |
---|
39 | /* Print that the task is up and running. */ |
---|
40 | locked_printf(" CPU %d runnng Task %s and blocking\n", cpu_num, name); |
---|
41 | |
---|
42 | sc = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); |
---|
43 | directive_failed( sc,"obtain in test task"); |
---|
44 | |
---|
45 | if ( !TSRFired ) |
---|
46 | locked_printf( "*** ERROR TSR DID NOT FIRE BUT TEST TASK AWAKE***" ); |
---|
47 | |
---|
48 | TaskRan = true; |
---|
49 | |
---|
50 | /* Print that the task is up and running. */ |
---|
51 | locked_printf( |
---|
52 | " CPU %d running Task %s after semaphore release\n", |
---|
53 | cpu_num, |
---|
54 | name |
---|
55 | ); |
---|
56 | |
---|
57 | (void) rtems_task_delete( RTEMS_SELF ); |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | rtems_timer_service_routine TimerMethod( |
---|
62 | rtems_id timer, |
---|
63 | void *arg |
---|
64 | ) |
---|
65 | { |
---|
66 | /* |
---|
67 | * Set flag and release the semaphore, allowing the blocked tasks to start. |
---|
68 | */ |
---|
69 | TSRFired = true; |
---|
70 | |
---|
71 | rtems_semaphore_release( Semaphore ); |
---|
72 | } |
---|
73 | |
---|
74 | rtems_task Init( |
---|
75 | rtems_task_argument argument |
---|
76 | ) |
---|
77 | { |
---|
78 | int cpu_num; |
---|
79 | rtems_id id; |
---|
80 | rtems_status_code status; |
---|
81 | rtems_interval per_second; |
---|
82 | rtems_interval then; |
---|
83 | rtems_id Timer; |
---|
84 | |
---|
85 | locked_print_initialize(); |
---|
86 | locked_printf( "\n\n*** TEST SMP07 ***\n" ); |
---|
87 | |
---|
88 | /* Create/verify semaphore */ |
---|
89 | status = rtems_semaphore_create( |
---|
90 | rtems_build_name ('S', 'E', 'M', '1'), |
---|
91 | 1, |
---|
92 | RTEMS_LOCAL | |
---|
93 | RTEMS_SIMPLE_BINARY_SEMAPHORE | |
---|
94 | RTEMS_PRIORITY, |
---|
95 | 1, |
---|
96 | &Semaphore |
---|
97 | ); |
---|
98 | directive_failed( status, "rtems_semaphore_create" ); |
---|
99 | |
---|
100 | /* Lock semaphore */ |
---|
101 | status = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, 0); |
---|
102 | directive_failed( status,"rtems_semaphore_obtain of SEM1\n"); |
---|
103 | |
---|
104 | /* Create and Start test task. */ |
---|
105 | status = rtems_task_create( |
---|
106 | rtems_build_name( 'T', 'A', '1', ' ' ), |
---|
107 | 1, |
---|
108 | RTEMS_MINIMUM_STACK_SIZE, |
---|
109 | RTEMS_DEFAULT_MODES, |
---|
110 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
111 | &id |
---|
112 | ); |
---|
113 | directive_failed( status, "task create" ); |
---|
114 | |
---|
115 | cpu_num = bsp_smp_processor_id(); |
---|
116 | locked_printf(" CPU %d start task TA1\n", cpu_num ); |
---|
117 | status = rtems_task_start( id, Test_task, 1 ); |
---|
118 | directive_failed( status, "task start" ); |
---|
119 | |
---|
120 | /* Create and start TSR */ |
---|
121 | locked_printf(" CPU %d create and start timer\n", cpu_num ); |
---|
122 | status = rtems_timer_create( rtems_build_name( 'T', 'M', 'R', '1' ), &Timer); |
---|
123 | directive_failed( status, "rtems_timer_create" ); |
---|
124 | |
---|
125 | per_second = rtems_clock_get_ticks_per_second(); |
---|
126 | status = rtems_timer_fire_after( Timer, 2 * per_second, TimerMethod, NULL ); |
---|
127 | directive_failed( status, "rtems_timer_fire_after"); |
---|
128 | |
---|
129 | /* |
---|
130 | * Wait long enough that TSR should have fired. |
---|
131 | * |
---|
132 | * Spin so CPU 0 is consumed. This forces task to run on CPU 1. |
---|
133 | */ |
---|
134 | then = rtems_clock_get_ticks_since_boot() + 4 * per_second; |
---|
135 | while (1) { |
---|
136 | if ( rtems_clock_get_ticks_since_boot() > then ) |
---|
137 | break; |
---|
138 | if ( TSRFired && TaskRan ) |
---|
139 | break; |
---|
140 | }; |
---|
141 | |
---|
142 | /* Validate the timer fired and that the task ran */ |
---|
143 | if ( !TSRFired ) |
---|
144 | locked_printf( "*** ERROR TSR DID NOT FIRE ***" ); |
---|
145 | |
---|
146 | if ( !TaskRan ) { |
---|
147 | locked_printf( "*** ERROR TASK DID NOT RUN ***" ); |
---|
148 | rtems_test_exit(0); |
---|
149 | } |
---|
150 | |
---|
151 | /* End the program */ |
---|
152 | locked_printf( "*** END OF TEST SMP07 ***\n" ); |
---|
153 | rtems_test_exit(0); |
---|
154 | } |
---|
155 | |
---|
156 | /* configuration information */ |
---|
157 | |
---|
158 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
159 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
160 | |
---|
161 | #define CONFIGURE_SMP_APPLICATION |
---|
162 | #define CONFIGURE_SMP_MAXIMUM_PROCESSORS 2 |
---|
163 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
164 | |
---|
165 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
166 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
167 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
168 | |
---|
169 | #define CONFIGURE_INIT |
---|
170 | |
---|
171 | #include <rtems/confdefs.h> |
---|
172 | /* end of file */ |
---|