1 | /* |
---|
2 | * Based upon test code posted on the RTEMS User's Mailing List |
---|
3 | * by Sergio Faustino <sergio.faustino@edisoft.pt>: |
---|
4 | * |
---|
5 | * http://www.rtems.org/pipermail/rtems-users/2009-June/005540.html |
---|
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.com/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | |
---|
13 | #ifdef HAVE_CONFIG_H |
---|
14 | #include "config.h" |
---|
15 | #endif |
---|
16 | |
---|
17 | #include <tmacros.h> |
---|
18 | |
---|
19 | /* |
---|
20 | * We have to extern this rather than use __RTEMS_VIOLATE_KERNEL_VISIBILITY__ |
---|
21 | * because this variable isn't actually in any .h. |
---|
22 | */ |
---|
23 | extern Watchdog_Interval _Timer_Server_ticks_last_time; |
---|
24 | |
---|
25 | volatile bool _timer_passage_1 = FALSE; |
---|
26 | volatile bool _timer_passage_2 = FALSE; |
---|
27 | |
---|
28 | /*timer Routine*/ |
---|
29 | rtems_timer_service_routine TIMER_service_routine( |
---|
30 | rtems_id ignored_id, |
---|
31 | void *user_data |
---|
32 | ) |
---|
33 | { |
---|
34 | bool *passed = (bool *)user_data; |
---|
35 | *passed = TRUE; |
---|
36 | } |
---|
37 | |
---|
38 | rtems_task Init( |
---|
39 | rtems_task_argument argument |
---|
40 | ) |
---|
41 | { |
---|
42 | rtems_status_code status; |
---|
43 | rtems_id timer1; |
---|
44 | rtems_id timer2; |
---|
45 | |
---|
46 | puts( "\n\n*** TEST 67 ***" ); |
---|
47 | |
---|
48 | /* build timer name*/ |
---|
49 | |
---|
50 | /* create Timer */ |
---|
51 | puts( "Init - create timer 1" ); |
---|
52 | status = rtems_timer_create( rtems_build_name('T', 'M', '1', ' '), &timer1 ); |
---|
53 | directive_failed( status, "rtems_timer_create #1" ); |
---|
54 | |
---|
55 | puts( "Init - create timer 2" ); |
---|
56 | status = rtems_timer_create( rtems_build_name('T', 'M', '2', ' '), &timer2 ); |
---|
57 | directive_failed( status, "rtems_timer_create #1" ); |
---|
58 | |
---|
59 | /* Manipulate the time */ |
---|
60 | _Watchdog_Ticks_since_boot = (Watchdog_Interval) -15; |
---|
61 | |
---|
62 | /* initiate timer server */ |
---|
63 | puts( "Init - Initiate the timer server" ); |
---|
64 | status = rtems_timer_initiate_server( |
---|
65 | RTEMS_MINIMUM_PRIORITY, |
---|
66 | RTEMS_MINIMUM_STACK_SIZE, |
---|
67 | RTEMS_DEFAULT_ATTRIBUTES |
---|
68 | ); |
---|
69 | directive_failed( status, "rtems_timer_initiate_server" ); |
---|
70 | |
---|
71 | /* Give the timer server some time to initialize */ |
---|
72 | status = rtems_task_wake_after( 10 ); |
---|
73 | directive_failed( status, "task wake_after" ); |
---|
74 | |
---|
75 | status = rtems_timer_server_fire_after( |
---|
76 | timer1, |
---|
77 | 10, |
---|
78 | TIMER_service_routine, |
---|
79 | (void*) &_timer_passage_1 |
---|
80 | ); |
---|
81 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
82 | |
---|
83 | status = rtems_timer_server_fire_after( |
---|
84 | timer2, |
---|
85 | 20, |
---|
86 | TIMER_service_routine, |
---|
87 | (void*) &_timer_passage_2 |
---|
88 | ); |
---|
89 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
90 | |
---|
91 | status = rtems_task_wake_after( 15 ); |
---|
92 | directive_failed( status, "task wake_after" ); |
---|
93 | |
---|
94 | if (!_timer_passage_1) { |
---|
95 | puts( "Timer 1 FAILED to fire after wrapping time"); |
---|
96 | rtems_test_exit(0); |
---|
97 | } |
---|
98 | puts( "Server Timer 1 fired after wrapping ticks since boot-- OK"); |
---|
99 | |
---|
100 | if (_timer_passage_2) { |
---|
101 | puts( "Timer 2 fired and should not have after wrapping time"); |
---|
102 | rtems_test_exit(0); |
---|
103 | } |
---|
104 | |
---|
105 | puts( "*** END OF TEST 67 ***" ); |
---|
106 | rtems_test_exit(0); |
---|
107 | } |
---|
108 | |
---|
109 | /* configuration stuff */ |
---|
110 | |
---|
111 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
112 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
113 | |
---|
114 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
115 | #define CONFIGURE_MAXIMUM_TIMERS 2 |
---|
116 | |
---|
117 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
118 | |
---|
119 | #define CONFIGURE_INIT |
---|
120 | #include <rtems/confdefs.h> |
---|