1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2011. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * Copyright (c) 2009 embedded brains GmbH. |
---|
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 | #include "system.h" |
---|
17 | |
---|
18 | #include <rtems/rtems/timerimpl.h> |
---|
19 | |
---|
20 | rtems_timer_service_routine Should_not_fire_TSR( |
---|
21 | rtems_id ignored_id, |
---|
22 | void *ignored_address |
---|
23 | ); |
---|
24 | |
---|
25 | volatile int TSR_fired; |
---|
26 | |
---|
27 | rtems_timer_service_routine Should_not_fire_TSR( |
---|
28 | rtems_id ignored_id, |
---|
29 | void *ignored_address |
---|
30 | ) |
---|
31 | { |
---|
32 | TSR_fired = 1; |
---|
33 | } |
---|
34 | |
---|
35 | static rtems_timer_service_routine Do_nothing( |
---|
36 | rtems_id ignored_id, |
---|
37 | void *ignored_address |
---|
38 | ) |
---|
39 | { |
---|
40 | /* Do nothing */ |
---|
41 | } |
---|
42 | |
---|
43 | static Watchdog_Interval schedule_time( void ) |
---|
44 | { |
---|
45 | const Watchdog_Control *watchdog = |
---|
46 | &_Timer_server->Interval_watchdogs.System_watchdog; |
---|
47 | |
---|
48 | return watchdog->initial + watchdog->start_time; |
---|
49 | } |
---|
50 | |
---|
51 | rtems_task Task_1( |
---|
52 | rtems_task_argument argument |
---|
53 | ) |
---|
54 | { |
---|
55 | rtems_id tmid; |
---|
56 | rtems_id tmid2; |
---|
57 | rtems_time_of_day time; |
---|
58 | rtems_status_code status; |
---|
59 | rtems_timer_information info; |
---|
60 | |
---|
61 | /* Get id */ |
---|
62 | |
---|
63 | puts( "TA1 - rtems_timer_ident - identing timer 1" ); |
---|
64 | status = rtems_timer_ident( Timer_name[ 1 ], &tmid ); |
---|
65 | directive_failed( status, "rtems_timer_ident" ); |
---|
66 | printf( "TA1 - timer 1 has id (0x%" PRIxrtems_id ")\n", tmid ); |
---|
67 | |
---|
68 | puts( "TA1 - rtems_timer_ident - identing timer 2" ); |
---|
69 | status = rtems_timer_ident( Timer_name[ 2 ], &tmid2 ); |
---|
70 | directive_failed( status, "rtems_timer_ident" ); |
---|
71 | printf( "TA1 - timer 2 has id (0x%" PRIxrtems_id ")\n", tmid2 ); |
---|
72 | |
---|
73 | /* make sure insertion does not unintentionally fire a timer per PR147 */ |
---|
74 | |
---|
75 | TSR_fired = 0; |
---|
76 | |
---|
77 | puts( "TA1 - rtems_timer_server_fire_after - 1 second" ); |
---|
78 | status = rtems_timer_server_fire_after( |
---|
79 | tmid, rtems_clock_get_ticks_per_second(), Should_not_fire_TSR, NULL ); |
---|
80 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
81 | |
---|
82 | puts( "TA1 - rtems_task_wake_after - 1/2 second" ); |
---|
83 | status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() / 2 ); |
---|
84 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
85 | |
---|
86 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
87 | puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 1/2 second" ); |
---|
88 | status = rtems_timer_server_fire_after( |
---|
89 | tmid2, rtems_clock_get_ticks_per_second() / 2, Should_not_fire_TSR, NULL ); |
---|
90 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
91 | |
---|
92 | if ( TSR_fired ) { |
---|
93 | puts( "TA1 - TSR fired and should not have!" ); |
---|
94 | rtems_test_exit(1); |
---|
95 | } |
---|
96 | |
---|
97 | puts( "TA1 - rtems_timer_cancel - timer 1" ); |
---|
98 | status = rtems_timer_cancel( tmid ); |
---|
99 | directive_failed( status, "rtems_timer_cancel" ); |
---|
100 | |
---|
101 | puts( "TA1 - rtems_timer_cancel - timer 2" ); |
---|
102 | status = rtems_timer_cancel( tmid2 ); |
---|
103 | directive_failed( status, "rtems_timer_cancel" ); |
---|
104 | |
---|
105 | |
---|
106 | /* now check that rescheduling an active timer works OK. */ |
---|
107 | puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 30 seconds" ); |
---|
108 | status = rtems_timer_server_fire_after( |
---|
109 | tmid, 30 * rtems_clock_get_ticks_per_second(), Delayed_resume, NULL ); |
---|
110 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
111 | |
---|
112 | puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" ); |
---|
113 | status = rtems_timer_server_fire_after( |
---|
114 | tmid2, 60 * rtems_clock_get_ticks_per_second(), Delayed_resume, NULL ); |
---|
115 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
116 | |
---|
117 | status = rtems_timer_get_information( tmid, &info ); |
---|
118 | printf( |
---|
119 | "Timer 1 scheduled for %" PRIdWatchdog_Interval " ticks since boot\n", |
---|
120 | info.start_time + info.initial |
---|
121 | ); |
---|
122 | printf( |
---|
123 | "Timer Server scheduled for %" PRIdWatchdog_Interval " ticks since boot\n", |
---|
124 | schedule_time() |
---|
125 | ); |
---|
126 | |
---|
127 | puts( "TA1 - rtems_task_wake_after - 1 second" ); |
---|
128 | status = rtems_task_wake_after( 1 * rtems_clock_get_ticks_per_second() ); |
---|
129 | directive_failed( status, "rtems_timer_wake_after" ); |
---|
130 | |
---|
131 | puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" ); |
---|
132 | status = rtems_timer_server_fire_after( |
---|
133 | tmid2, 60 * rtems_clock_get_ticks_per_second(), Delayed_resume, NULL ); |
---|
134 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
135 | |
---|
136 | status = rtems_timer_get_information( tmid, &info ); |
---|
137 | directive_failed( status, "rtems_timer_get_information" ); |
---|
138 | printf( |
---|
139 | "Timer 1 scheduled for %" PRIdWatchdog_Interval " ticks since boot\n", |
---|
140 | info.start_time + info.initial |
---|
141 | ); |
---|
142 | printf( |
---|
143 | "Timer Server scheduled for %" PRIdWatchdog_Interval " ticks since boot\n", |
---|
144 | schedule_time() |
---|
145 | ); |
---|
146 | rtems_test_assert( (info.start_time + info.initial) == schedule_time() ); |
---|
147 | |
---|
148 | puts( "TA1 - rtems_task_wake_after - 1 second" ); |
---|
149 | status = rtems_task_wake_after( 1 * rtems_clock_get_ticks_per_second() ); |
---|
150 | directive_failed( status, "rtems_timer_wake_after" ); |
---|
151 | |
---|
152 | puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" ); |
---|
153 | status = rtems_timer_server_fire_after( |
---|
154 | tmid2, 60 * rtems_clock_get_ticks_per_second(), Delayed_resume, NULL ); |
---|
155 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
156 | |
---|
157 | status = rtems_timer_get_information( tmid, &info ); |
---|
158 | directive_failed( status, "rtems_timer_get_information" ); |
---|
159 | printf( |
---|
160 | "Timer 1 scheduled for %" PRIdWatchdog_Interval " ticks since boot\n", |
---|
161 | info.start_time + info.initial |
---|
162 | ); |
---|
163 | printf( |
---|
164 | "Timer Server scheduled for %" PRIdWatchdog_Interval " ticks since boot\n", |
---|
165 | schedule_time() |
---|
166 | ); |
---|
167 | rtems_test_assert( (info.start_time + info.initial) == schedule_time() ); |
---|
168 | |
---|
169 | puts( "TA1 - rtems_timer_cancel - timer 1" ); |
---|
170 | status = rtems_timer_cancel( tmid ); |
---|
171 | directive_failed( status, "rtems_timer_cancel" ); |
---|
172 | |
---|
173 | puts( "TA1 - rtems_timer_cancel - timer 2" ); |
---|
174 | status = rtems_timer_cancel( tmid2 ); |
---|
175 | directive_failed( status, "rtems_timer_cancel" ); |
---|
176 | |
---|
177 | /* after which is allowed to fire */ |
---|
178 | |
---|
179 | Print_time(); |
---|
180 | |
---|
181 | puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" ); |
---|
182 | status = rtems_timer_server_fire_after( |
---|
183 | tmid, |
---|
184 | 3 * rtems_clock_get_ticks_per_second(), |
---|
185 | Delayed_resume, |
---|
186 | NULL |
---|
187 | ); |
---|
188 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
189 | |
---|
190 | puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" ); |
---|
191 | status = rtems_task_suspend( RTEMS_SELF ); |
---|
192 | directive_failed( status, "rtems_task_suspend" ); |
---|
193 | |
---|
194 | Print_time(); |
---|
195 | |
---|
196 | /* after which is reset and allowed to fire */ |
---|
197 | |
---|
198 | puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" ); |
---|
199 | status = rtems_timer_server_fire_after( |
---|
200 | tmid, |
---|
201 | 3 * rtems_clock_get_ticks_per_second(), |
---|
202 | Delayed_resume, |
---|
203 | NULL |
---|
204 | ); |
---|
205 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
206 | |
---|
207 | puts( "TA1 - rtems_task_wake_after - 1 second" ); |
---|
208 | status = rtems_task_wake_after( 1 * rtems_clock_get_ticks_per_second() ); |
---|
209 | directive_failed( status, "rtems_task_wake_after" ); |
---|
210 | |
---|
211 | Print_time(); |
---|
212 | |
---|
213 | puts( "TA1 - rtems_timer_reset - timer 1" ); |
---|
214 | status = rtems_timer_reset( tmid ); |
---|
215 | directive_failed( status, "rtems_timer_reset" ); |
---|
216 | |
---|
217 | puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" ); |
---|
218 | status = rtems_task_suspend( RTEMS_SELF ); |
---|
219 | directive_failed( status, "rtems_task_suspend" ); |
---|
220 | |
---|
221 | Print_time(); |
---|
222 | |
---|
223 | rtems_test_pause(); |
---|
224 | |
---|
225 | /* |
---|
226 | * Reset the time since we do not know how long the user waited |
---|
227 | * before pressing <cr> at the pause. This insures that the |
---|
228 | * actual output matches the screen. |
---|
229 | */ |
---|
230 | |
---|
231 | build_time( &time, 12, 31, 1988, 9, 0, 7, 0 ); |
---|
232 | |
---|
233 | status = rtems_clock_set( &time ); |
---|
234 | directive_failed( status, "rtems_clock_set" ); |
---|
235 | |
---|
236 | /* after which is canceled */ |
---|
237 | |
---|
238 | puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" ); |
---|
239 | status = rtems_timer_server_fire_after( |
---|
240 | tmid, |
---|
241 | 3 * rtems_clock_get_ticks_per_second(), |
---|
242 | Delayed_resume, |
---|
243 | NULL |
---|
244 | ); |
---|
245 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
246 | |
---|
247 | puts( "TA1 - rtems_timer_cancel - timer 1" ); |
---|
248 | status = rtems_timer_cancel( tmid ); |
---|
249 | directive_failed( status, "rtems_timer_cancel" ); |
---|
250 | |
---|
251 | /* when which is allowed to fire */ |
---|
252 | |
---|
253 | Print_time(); |
---|
254 | |
---|
255 | status = rtems_clock_get_tod( &time ); |
---|
256 | directive_failed( status, "rtems_clock_get_tod" ); |
---|
257 | |
---|
258 | time.second += 3; |
---|
259 | |
---|
260 | puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 3 seconds" ); |
---|
261 | status = rtems_timer_server_fire_when( tmid, &time, Delayed_resume, NULL ); |
---|
262 | directive_failed( status, "rtems_timer_server_fire_when" ); |
---|
263 | |
---|
264 | puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" ); |
---|
265 | status = rtems_task_suspend( RTEMS_SELF ); |
---|
266 | directive_failed( status, "rtems_task_suspend" ); |
---|
267 | |
---|
268 | Print_time(); |
---|
269 | |
---|
270 | /* when which is canceled */ |
---|
271 | |
---|
272 | status = rtems_clock_get_tod( &time ); |
---|
273 | directive_failed( status, "rtems_clock_get_tod" ); |
---|
274 | |
---|
275 | time.second += 3; |
---|
276 | |
---|
277 | puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 3 seconds" ); |
---|
278 | status = rtems_timer_server_fire_when( tmid, &time, Delayed_resume, NULL ); |
---|
279 | directive_failed( status, "rtems_timer_server_fire_when" ); |
---|
280 | |
---|
281 | puts( "TA1 - rtems_task_wake_after - 1 second" ); |
---|
282 | status = rtems_task_wake_after( 1 * rtems_clock_get_ticks_per_second() ); |
---|
283 | directive_failed( status, "rtems_task_wake_after" ); |
---|
284 | |
---|
285 | Print_time(); |
---|
286 | |
---|
287 | puts( "TA1 - rtems_timer_cancel - timer 1" ); |
---|
288 | status = rtems_timer_cancel( tmid ); |
---|
289 | directive_failed( status, "rtems_timer_cancel" ); |
---|
290 | |
---|
291 | /* TOD timer insert with non empty TOD timer chain */ |
---|
292 | |
---|
293 | status = rtems_clock_get_tod( &time ); |
---|
294 | directive_failed( status, "rtems_clock_get_tod" ); |
---|
295 | |
---|
296 | time.second += 3; |
---|
297 | |
---|
298 | puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 3 seconds" ); |
---|
299 | status = rtems_timer_server_fire_when( tmid, &time, Do_nothing, NULL ); |
---|
300 | directive_failed( status, "rtems_timer_server_fire_when" ); |
---|
301 | |
---|
302 | puts( "TA1 - rtems_timer_server_fire_when - timer 2 in 3 seconds" ); |
---|
303 | status = rtems_timer_server_fire_when( tmid2, &time, Do_nothing, NULL ); |
---|
304 | directive_failed( status, "rtems_timer_server_fire_when" ); |
---|
305 | |
---|
306 | puts( "TA1 - rtems_task_wake_after - 1 second" ); |
---|
307 | status = rtems_task_wake_after( 1 * rtems_clock_get_ticks_per_second() ); |
---|
308 | directive_failed( status, "rtems_task_wake_after" ); |
---|
309 | |
---|
310 | puts( "TA1 - rtems_timer_server_fire_when - timer 2 in 3 seconds" ); |
---|
311 | status = rtems_timer_server_fire_when( tmid2, &time, Do_nothing, NULL ); |
---|
312 | directive_failed( status, "rtems_timer_server_fire_when" ); |
---|
313 | |
---|
314 | puts( "TA1 - rtems_timer_cancel - timer 1" ); |
---|
315 | status = rtems_timer_cancel( tmid ); |
---|
316 | directive_failed( status, "rtems_timer_cancel" ); |
---|
317 | |
---|
318 | puts( "TA1 - rtems_timer_cancel - timer 2" ); |
---|
319 | status = rtems_timer_cancel( tmid2 ); |
---|
320 | directive_failed( status, "rtems_timer_cancel" ); |
---|
321 | |
---|
322 | /* TOD chain processing with time wrap */ |
---|
323 | |
---|
324 | time.second = 30; |
---|
325 | |
---|
326 | status = rtems_clock_set( &time ); |
---|
327 | directive_failed( status, "rtems_clock_set" ); |
---|
328 | |
---|
329 | time.second = 31; |
---|
330 | |
---|
331 | puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 1 seconds" ); |
---|
332 | status = rtems_timer_server_fire_when( tmid, &time, Do_nothing, NULL ); |
---|
333 | directive_failed( status, "rtems_timer_server_fire_when" ); |
---|
334 | |
---|
335 | time.second = 29; |
---|
336 | |
---|
337 | status = rtems_clock_set( &time ); |
---|
338 | directive_failed( status, "rtems_clock_set" ); |
---|
339 | |
---|
340 | puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 1 tick" ); |
---|
341 | status = rtems_timer_server_fire_after( tmid2, 1, Do_nothing, NULL ); |
---|
342 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
343 | |
---|
344 | puts( "TA1 - rtems_task_wake_after - 1 tick" ); |
---|
345 | status = rtems_task_wake_after( 1 ); |
---|
346 | directive_failed( status, "rtems_task_wake_after" ); |
---|
347 | |
---|
348 | puts( "TA1 - rtems_timer_cancel - timer 1" ); |
---|
349 | status = rtems_timer_cancel( tmid ); |
---|
350 | directive_failed( status, "rtems_timer_cancel" ); |
---|
351 | |
---|
352 | /* delete */ |
---|
353 | puts( "TA1 - rtems_task_wake_after - YIELD (only task at priority)" ); |
---|
354 | status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
355 | directive_failed( status, "rtems_task_wake_after" ); |
---|
356 | |
---|
357 | puts( "TA1 - timer_deleting - timer 1" ); |
---|
358 | status = rtems_timer_delete( tmid ); |
---|
359 | directive_failed( status, "rtems_timer_delete" ); |
---|
360 | |
---|
361 | TEST_END(); |
---|
362 | rtems_test_exit( 0 ); |
---|
363 | } |
---|