1 | /* Init |
---|
2 | * |
---|
3 | * This routine is the initialization task for this test program. |
---|
4 | * It is a user initialization task and has the responsibility for creating |
---|
5 | * and starting the tasks that make up the test. If the time of day |
---|
6 | * clock is required for the test, it should also be set to a known |
---|
7 | * value by this function. |
---|
8 | * |
---|
9 | * Input parameters: |
---|
10 | * argument - task argument |
---|
11 | * |
---|
12 | * Output parameters: NONE |
---|
13 | * |
---|
14 | * COPYRIGHT (c) 1989-1999. |
---|
15 | * On-Line Applications Research Corporation (OAR). |
---|
16 | * |
---|
17 | * The license and distribution terms for this file may be |
---|
18 | * found in the file LICENSE in this distribution or at |
---|
19 | * http://www.OARcorp.com/rtems/license.html. |
---|
20 | * |
---|
21 | * $Id$ |
---|
22 | */ |
---|
23 | |
---|
24 | #define TEST_INIT |
---|
25 | #include "system.h" |
---|
26 | |
---|
27 | rtems_task Init( |
---|
28 | rtems_task_argument argument |
---|
29 | ) |
---|
30 | { |
---|
31 | rtems_time_of_day time; |
---|
32 | rtems_status_code rtems_status; |
---|
33 | |
---|
34 | #ifdef RTEMS_POSIX_API |
---|
35 | int posix_status; |
---|
36 | #endif |
---|
37 | |
---|
38 | #ifdef RTEMS_ITRON_API |
---|
39 | ER itron_status; |
---|
40 | T_CTSK pk_ctsk; |
---|
41 | #endif |
---|
42 | |
---|
43 | puts( "\n\n*** Thread Iteration Test ***" ); |
---|
44 | |
---|
45 | build_time( &time, 12, 31, 2000, 9, 0, 0, 0 ); |
---|
46 | rtems_status = rtems_clock_set( &time ); |
---|
47 | directive_failed( rtems_status, "rtems_clock_set" ); |
---|
48 | |
---|
49 | Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' ); |
---|
50 | Task_name[ 2 ] = rtems_build_name( 'T', 'A', '2', ' ' ); |
---|
51 | Task_name[ 3 ] = rtems_build_name( 'T', 'A', '3', ' ' ); |
---|
52 | |
---|
53 | rtems_status = rtems_task_create( |
---|
54 | Task_name[ 1 ], |
---|
55 | 1, |
---|
56 | RTEMS_MINIMUM_STACK_SIZE * 2, |
---|
57 | RTEMS_INTERRUPT_LEVEL(31), |
---|
58 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
59 | &Task_id[ 1 ] |
---|
60 | ); |
---|
61 | directive_failed( rtems_status, "rtems_task_create of TA1" ); |
---|
62 | |
---|
63 | rtems_status = rtems_task_create( |
---|
64 | Task_name[ 2 ], |
---|
65 | 1, |
---|
66 | RTEMS_MINIMUM_STACK_SIZE * 2, |
---|
67 | RTEMS_DEFAULT_MODES, |
---|
68 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
69 | &Task_id[ 2 ] |
---|
70 | ); |
---|
71 | directive_failed( rtems_status, "rtems_task_create of TA2" ); |
---|
72 | |
---|
73 | rtems_status = rtems_task_create( |
---|
74 | Task_name[ 3 ], |
---|
75 | 1, |
---|
76 | RTEMS_MINIMUM_STACK_SIZE * 3, |
---|
77 | RTEMS_DEFAULT_MODES, |
---|
78 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
79 | &Task_id[ 3 ] |
---|
80 | ); |
---|
81 | directive_failed( rtems_status, "rtems_task_create of TA3" ); |
---|
82 | |
---|
83 | rtems_status = rtems_task_start( Task_id[ 1 ], RTEMS_task_1_through_3, 0 ); |
---|
84 | if ( rtems_status == RTEMS_SUCCESSFUL ) |
---|
85 | printf("Created and started an RTEMS task with id = 0x%08x\n", Task_id[1] ); |
---|
86 | else |
---|
87 | directive_failed( rtems_status, "rtems_task_start of TA1" ); |
---|
88 | |
---|
89 | rtems_status = rtems_task_start( Task_id[ 2 ], RTEMS_task_1_through_3, 0 ); |
---|
90 | if ( rtems_status == RTEMS_SUCCESSFUL ) |
---|
91 | printf("Created and started an RTEMS task with id = 0x%08x\n", Task_id[2] ); |
---|
92 | else |
---|
93 | directive_failed( rtems_status, "rtems_task_start of TA2" ); |
---|
94 | |
---|
95 | rtems_status = rtems_task_start( Task_id[ 3 ], RTEMS_task_1_through_3, 0 ); |
---|
96 | if ( rtems_status == RTEMS_SUCCESSFUL ) |
---|
97 | printf("Created and started an RTEMS task with id = 0x%08x\n", Task_id[3] ); |
---|
98 | else |
---|
99 | directive_failed( rtems_status, "rtems_task_start of TA3" ); |
---|
100 | |
---|
101 | #ifdef RTEMS_POSIX_API |
---|
102 | posix_status = pthread_create( &pthread_id[0], NULL, pthread_1_through_3, NULL ); |
---|
103 | if ( !posix_status ) |
---|
104 | printf("Created and started a pthread with id = 0x%08x\n", pthread_id[0] ); |
---|
105 | else |
---|
106 | assert( !posix_status ); |
---|
107 | |
---|
108 | posix_status = pthread_create( &pthread_id[1], NULL, pthread_1_through_3, NULL ); |
---|
109 | if ( !posix_status ) |
---|
110 | printf("Created and started a pthread with id = 0x%08x\n", pthread_id[1] ); |
---|
111 | else |
---|
112 | assert( !posix_status ); |
---|
113 | |
---|
114 | posix_status = pthread_create( &pthread_id[2], NULL, pthread_1_through_3, NULL ); |
---|
115 | if ( !posix_status ) |
---|
116 | printf("Created and started a pthread with id = 0x%08x\n", pthread_id[2] ); |
---|
117 | else |
---|
118 | assert( !posix_status ); |
---|
119 | |
---|
120 | #endif |
---|
121 | |
---|
122 | #ifdef RTEMS_ITRON_API |
---|
123 | |
---|
124 | #define ITRON_GET_TASK_ID(_index) \ |
---|
125 | _ITRON_Task_Information.local_table[_index]->id |
---|
126 | |
---|
127 | pk_ctsk.exinf = NULL; |
---|
128 | pk_ctsk.tskatr = TA_HLNG; |
---|
129 | pk_ctsk.itskpri = 1; |
---|
130 | pk_ctsk.task = ITRON_task_2_through_4; |
---|
131 | pk_ctsk.stksz = RTEMS_MINIMUM_STACK_SIZE * 2; |
---|
132 | |
---|
133 | itron_status = cre_tsk( 2, &pk_ctsk ); |
---|
134 | directive_failed( itron_status, "cre_tsk of task" ); |
---|
135 | |
---|
136 | pk_ctsk.stksz = RTEMS_MINIMUM_STACK_SIZE * 2; |
---|
137 | itron_status = cre_tsk( 3, &pk_ctsk ); |
---|
138 | directive_failed( itron_status, "cre_tsk of TA2" ); |
---|
139 | |
---|
140 | pk_ctsk.stksz = RTEMS_MINIMUM_STACK_SIZE * 3; |
---|
141 | itron_status = cre_tsk( 4, &pk_ctsk ); |
---|
142 | directive_failed( itron_status, "cre_tsk of TA3" ); |
---|
143 | |
---|
144 | itron_status = sta_tsk( 2, 0 ); |
---|
145 | if ( !itron_status ) |
---|
146 | printf("Created and started an ITRON task with id = 0x%08x\n", ITRON_GET_TASK_ID( 2 ) ); |
---|
147 | else |
---|
148 | directive_failed( itron_status, "sta_tsk of ITRON task 2" ); |
---|
149 | |
---|
150 | itron_status = sta_tsk( 3, 0 ); |
---|
151 | if ( !itron_status ) |
---|
152 | printf("Created and started an ITRON task with id = 0x%08x\n", ITRON_GET_TASK_ID( 3 ) ); |
---|
153 | else |
---|
154 | directive_failed( itron_status, "sta_tsk of ITRON task 3" ); |
---|
155 | |
---|
156 | itron_status = sta_tsk( 4, 0 ); |
---|
157 | if ( !itron_status ) |
---|
158 | printf("Created and started an ITRON task with id = 0x%08x\n", ITRON_GET_TASK_ID( 4 ) ); |
---|
159 | else |
---|
160 | directive_failed( itron_status, "sta_tsk of ITRON task 4" ); |
---|
161 | #endif |
---|
162 | |
---|
163 | printf( "Sleeping for 5 seconds\n" ); |
---|
164 | fflush( stdout ); |
---|
165 | |
---|
166 | rtems_status = rtems_task_wake_after( 5 * TICKS_PER_SECOND ); |
---|
167 | directive_failed( rtems_status, "rtems_task_wake_after" ); |
---|
168 | |
---|
169 | printf( "\nLooking for all threads\n\n" ); |
---|
170 | _Thread_Local_iterate( print_thread_info, NULL, FALSE ); |
---|
171 | |
---|
172 | printf( "That was it. Sleeping for 20 seconds.\n" ); |
---|
173 | |
---|
174 | rtems_status = rtems_task_wake_after( 20 * TICKS_PER_SECOND ); |
---|
175 | directive_failed( rtems_status, "rtems_task_wake_after" ); |
---|
176 | |
---|
177 | /* If we get here, all threads were created */ |
---|
178 | printf( "\nDeleting the second thread of each type\n\n" ); |
---|
179 | |
---|
180 | rtems_status = rtems_task_suspend( Task_id[2] ); |
---|
181 | directive_failed( rtems_status, "rtems_task_suspend" ); |
---|
182 | rtems_status = rtems_task_delete( Task_id[2] ); |
---|
183 | directive_failed( rtems_status, "rtems_task_delete" ); |
---|
184 | |
---|
185 | #ifdef RTEMS_POSIX_API |
---|
186 | posix_status = pthread_cancel( pthread_id[2] ); |
---|
187 | assert( !posix_status ); |
---|
188 | #endif |
---|
189 | |
---|
190 | #ifdef RTEMS_ITRON_API |
---|
191 | itron_status = ter_tsk( 3 ); |
---|
192 | directive_failed( itron_status, "ter_tsk of ITRON task 3" ); |
---|
193 | #endif |
---|
194 | |
---|
195 | printf( "\nLooking for all threads\n\n" ); |
---|
196 | _Thread_Local_iterate( print_thread_info, NULL, FALSE ); |
---|
197 | |
---|
198 | printf( "That was it. Exiting\n" ); |
---|
199 | fflush( stdout ); |
---|
200 | |
---|
201 | exit( 0 ); |
---|
202 | } |
---|