1 | /* Task_1 |
---|
2 | * |
---|
3 | * This routine serves as a test task. It verifies the basic task |
---|
4 | * switching capabilities of the executive. |
---|
5 | * |
---|
6 | * Input parameters: |
---|
7 | * argument - task argument |
---|
8 | * |
---|
9 | * Output parameters: NONE |
---|
10 | * |
---|
11 | * COPYRIGHT (c) 1989-2009. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifdef HAVE_CONFIG_H |
---|
20 | #include "config.h" |
---|
21 | #endif |
---|
22 | |
---|
23 | #include "system.h" |
---|
24 | |
---|
25 | rtems_task Task_1( |
---|
26 | rtems_task_argument argument |
---|
27 | ) |
---|
28 | { |
---|
29 | rtems_id tmid; |
---|
30 | rtems_time_of_day time; |
---|
31 | rtems_status_code status; |
---|
32 | |
---|
33 | /* Get id */ |
---|
34 | |
---|
35 | puts( "TA1 - rtems_timer_ident - identing timer 1" ); |
---|
36 | status = rtems_timer_ident( Timer_name[ 1 ], &tmid ); |
---|
37 | directive_failed( status, "rtems_timer_ident" ); |
---|
38 | printf( "TA1 - timer 1 has id (0x%" PRIxrtems_id ")\n", tmid ); |
---|
39 | |
---|
40 | /* after which is allowed to fire */ |
---|
41 | |
---|
42 | Print_time(); |
---|
43 | |
---|
44 | puts( "TA1 - rtems_timer_fire_after - timer 1 in 3 seconds" ); |
---|
45 | status = rtems_timer_fire_after( |
---|
46 | tmid, |
---|
47 | 3 * rtems_clock_get_ticks_per_second(), |
---|
48 | Delayed_resume, |
---|
49 | NULL |
---|
50 | ); |
---|
51 | directive_failed( status, "rtems_timer_fire_after" ); |
---|
52 | |
---|
53 | puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" ); |
---|
54 | status = rtems_task_suspend( RTEMS_SELF ); |
---|
55 | directive_failed( status, "rtems_task_suspend" ); |
---|
56 | |
---|
57 | Print_time(); |
---|
58 | |
---|
59 | /* after which is reset and allowed to fire */ |
---|
60 | |
---|
61 | puts( "TA1 - rtems_timer_fire_after - timer 1 in 3 seconds" ); |
---|
62 | status = rtems_timer_fire_after( |
---|
63 | tmid, |
---|
64 | 3 * rtems_clock_get_ticks_per_second(), |
---|
65 | Delayed_resume, |
---|
66 | NULL |
---|
67 | ); |
---|
68 | directive_failed( status, "rtems_timer_fire_after" ); |
---|
69 | |
---|
70 | puts( "TA1 - rtems_task_wake_after - 1 second" ); |
---|
71 | status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); |
---|
72 | directive_failed( status, "rtems_task_wake_after" ); |
---|
73 | |
---|
74 | Print_time(); |
---|
75 | |
---|
76 | puts( "TA1 - rtems_timer_reset - timer 1" ); |
---|
77 | status = rtems_timer_reset( tmid ); |
---|
78 | directive_failed( status, "rtems_timer_reset" ); |
---|
79 | |
---|
80 | puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" ); |
---|
81 | status = rtems_task_suspend( RTEMS_SELF ); |
---|
82 | directive_failed( status, "rtems_task_suspend" ); |
---|
83 | |
---|
84 | Print_time(); |
---|
85 | |
---|
86 | rtems_test_pause(); |
---|
87 | |
---|
88 | /* |
---|
89 | * Reset the time since we do not know how long the user waited |
---|
90 | * before pressing <cr> at the pause. This insures that the |
---|
91 | * actual output matches the screen. |
---|
92 | */ |
---|
93 | |
---|
94 | build_time( &time, 12, 31, 1988, 9, 0, 7, 0 ); |
---|
95 | |
---|
96 | status = rtems_clock_set( &time ); |
---|
97 | directive_failed( status, "rtems_clock_set" ); |
---|
98 | |
---|
99 | /* after which is canceled */ |
---|
100 | |
---|
101 | puts( "TA1 - rtems_timer_fire_after - timer 1 in 3 seconds" ); |
---|
102 | status = rtems_timer_fire_after( |
---|
103 | tmid, |
---|
104 | 3 * rtems_clock_get_ticks_per_second(), |
---|
105 | Delayed_resume, |
---|
106 | NULL |
---|
107 | ); |
---|
108 | directive_failed( status, "rtems_timer_fire_after" ); |
---|
109 | |
---|
110 | puts( "TA1 - rtems_timer_cancel - timer 1" ); |
---|
111 | status = rtems_timer_cancel( tmid ); |
---|
112 | directive_failed( status, "rtems_timer_cancel" ); |
---|
113 | |
---|
114 | /* when which is allowed to fire */ |
---|
115 | |
---|
116 | Print_time(); |
---|
117 | |
---|
118 | status = rtems_clock_get_tod( &time ); |
---|
119 | directive_failed( status, "rtems_clock_get_tod" ); |
---|
120 | |
---|
121 | time.second += 3; |
---|
122 | |
---|
123 | puts( "TA1 - rtems_timer_fire_when - timer 1 in 3 seconds" ); |
---|
124 | status = rtems_timer_fire_when( tmid, &time, Delayed_resume, NULL ); |
---|
125 | directive_failed( status, "rtems_timer_fire_when" ); |
---|
126 | |
---|
127 | puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" ); |
---|
128 | status = rtems_task_suspend( RTEMS_SELF ); |
---|
129 | directive_failed( status, "rtems_task_suspend" ); |
---|
130 | |
---|
131 | Print_time(); |
---|
132 | |
---|
133 | /* when which is canceled */ |
---|
134 | |
---|
135 | status = rtems_clock_get_tod( &time ); |
---|
136 | directive_failed( status, "rtems_clock_get_tod" ); |
---|
137 | |
---|
138 | time.second += 3; |
---|
139 | |
---|
140 | puts( "TA1 - rtems_timer_fire_when - timer 1 in 3 seconds" ); |
---|
141 | status = rtems_timer_fire_when( tmid, &time, Delayed_resume, NULL ); |
---|
142 | directive_failed( status, "rtems_timer_fire_when" ); |
---|
143 | |
---|
144 | puts( "TA1 - rtems_task_wake_after - 1 second" ); |
---|
145 | status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); |
---|
146 | directive_failed( status, "rtems_task_wake_after" ); |
---|
147 | |
---|
148 | Print_time(); |
---|
149 | |
---|
150 | puts( "TA1 - rtems_timer_cancel - timer 1" ); |
---|
151 | status = rtems_timer_cancel( tmid ); |
---|
152 | directive_failed( status, "rtems_timer_cancel" ); |
---|
153 | |
---|
154 | /* delete */ |
---|
155 | puts( "TA1 - rtems_task_wake_after - YIELD (only task at priority)" ); |
---|
156 | status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
157 | directive_failed( status, "rtems_task_wake_after" ); |
---|
158 | |
---|
159 | puts( "TA1 - timer_deleting - timer 1" ); |
---|
160 | status = rtems_timer_delete( tmid ); |
---|
161 | directive_failed( status, "rtems_timer_delete" ); |
---|
162 | |
---|
163 | TEST_END(); |
---|
164 | rtems_test_exit( 0 ); |
---|
165 | } |
---|