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 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #if defined(USE_TIMER_SERVER) |
---|
15 | #define TEST_NUMBER "53" |
---|
16 | #define TSR_MODE "Server" |
---|
17 | #define FIRE_WHEN rtems_timer_server_fire_when |
---|
18 | #define FIRE_WHEN_STRING "rtems_timer_server_fire_when" |
---|
19 | #else |
---|
20 | #define TEST_NUMBER "52" |
---|
21 | #define TSR_MODE "Interrupt" |
---|
22 | #define FIRE_WHEN rtems_timer_fire_when |
---|
23 | #define FIRE_WHEN_STRING "rtems_timer_fire_when" |
---|
24 | #endif |
---|
25 | |
---|
26 | #include <tmacros.h> |
---|
27 | |
---|
28 | #define INITIAL_SECOND 10 |
---|
29 | volatile bool _timer_passage = FALSE; |
---|
30 | |
---|
31 | /*timer Routine*/ |
---|
32 | rtems_timer_service_routine TIMER_service_routine( |
---|
33 | rtems_id ignored_id, |
---|
34 | void *user_data |
---|
35 | ) |
---|
36 | { |
---|
37 | _timer_passage = TRUE; |
---|
38 | } |
---|
39 | |
---|
40 | rtems_task Init( |
---|
41 | rtems_task_argument argument |
---|
42 | ) |
---|
43 | { |
---|
44 | rtems_status_code status; |
---|
45 | rtems_id timer_id; |
---|
46 | rtems_name timer_name; |
---|
47 | |
---|
48 | rtems_time_of_day global_time; |
---|
49 | rtems_time_of_day time_to_fire; |
---|
50 | |
---|
51 | puts( "\n\n*** TEST " TEST_NUMBER " ***" ); |
---|
52 | |
---|
53 | /* build timer name*/ |
---|
54 | timer_name = rtems_build_name('T', 'M', '1', ' '); |
---|
55 | |
---|
56 | /* create Timer */ |
---|
57 | status = rtems_timer_create(timer_name, &timer_id); |
---|
58 | directive_failed( status, "rtems_timer_create" ); |
---|
59 | |
---|
60 | #if defined(USE_TIMER_SERVER) |
---|
61 | /* initiate timer server */ |
---|
62 | status = rtems_timer_initiate_server( |
---|
63 | RTEMS_MINIMUM_PRIORITY, |
---|
64 | RTEMS_MINIMUM_STACK_SIZE, |
---|
65 | RTEMS_DEFAULT_ATTRIBUTES |
---|
66 | ); |
---|
67 | directive_failed( status, "rtems_timer_initiate_server" ); |
---|
68 | #endif |
---|
69 | |
---|
70 | /* Set system clock */ |
---|
71 | build_time(&global_time, 6, 8, 2009, 16, 5, INITIAL_SECOND, 0); |
---|
72 | status = rtems_clock_set(&global_time); |
---|
73 | directive_failed( status, "rtems_clock_set" ); |
---|
74 | |
---|
75 | /* Set Timer to Fire */ |
---|
76 | /* build fire times */ |
---|
77 | time_to_fire = global_time; |
---|
78 | |
---|
79 | /* only diferent second */ |
---|
80 | time_to_fire.second = INITIAL_SECOND + 5; |
---|
81 | |
---|
82 | status = FIRE_WHEN( |
---|
83 | timer_id, |
---|
84 | &time_to_fire, |
---|
85 | TIMER_service_routine, |
---|
86 | (void*) NULL |
---|
87 | ); |
---|
88 | directive_failed( status, FIRE_WHEN_STRING ); |
---|
89 | |
---|
90 | /* Set system clock FORWARD */ |
---|
91 | global_time.second = INITIAL_SECOND + 10; |
---|
92 | status = rtems_clock_set(&global_time); |
---|
93 | |
---|
94 | if (!_timer_passage) { |
---|
95 | puts( TSR_MODE " Timer FAILED to fire after setting time forward"); |
---|
96 | rtems_test_exit(0); |
---|
97 | } |
---|
98 | |
---|
99 | puts( TSR_MODE " Timer fired after setting time forward -- OK"); |
---|
100 | |
---|
101 | puts( "*** END OF TEST " TEST_NUMBER " ***" ); |
---|
102 | rtems_test_exit(0); |
---|
103 | } |
---|
104 | |
---|
105 | /* configuration stuff */ |
---|
106 | |
---|
107 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
108 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
109 | |
---|
110 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
111 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
112 | |
---|
113 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
114 | |
---|
115 | #define CONFIGURE_INIT |
---|
116 | #include <rtems/confdefs.h> |
---|