source: rtems/c/src/tests/sptests/sp31/task1.c @ d2b93bfd

4.104.114.84.95
Last change on this file since d2b93bfd was d2b93bfd, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:53:48

2003-09-04 Joel Sherrill <joel@…>

  • sp01/init.c, sp01/sp01.doc, sp01/system.h, sp01/task1.c, sp02/init.c, sp02/preempt.c, sp02/sp02.doc, sp02/system.h, sp02/task1.c, sp02/task2.c, sp02/task3.c, sp03/init.c, sp03/sp03.doc, sp03/system.h, sp03/task1.c, sp03/task2.c, sp04/init.c, sp04/sp04.doc, sp04/system.h, sp04/task1.c, sp04/task2.c, sp04/task3.c, sp04/tswitch.c, sp05/init.c, sp05/sp05.doc, sp05/system.h, sp05/task1.c, sp05/task2.c, sp05/task3.c, sp06/init.c, sp06/sp06.doc, sp06/system.h, sp06/task1.c, sp06/task2.c, sp06/task3.c, sp07/init.c, sp07/sp07.doc, sp07/system.h, sp07/task1.c, sp07/task2.c, sp07/task3.c, sp07/task4.c, sp07/taskexit.c, sp07/tcreate.c, sp07/tdelete.c, sp07/trestart.c, sp07/tstart.c, sp08/init.c, sp08/sp08.doc, sp08/system.h, sp08/task1.c, sp09/delay.c, sp09/init.c, sp09/isr.c, sp09/screen01.c, sp09/screen02.c, sp09/screen03.c, sp09/screen04.c, sp09/screen05.c, sp09/screen06.c, sp09/screen07.c, sp09/screen08.c, sp09/screen09.c, sp09/screen10.c, sp09/screen11.c, sp09/screen12.c, sp09/screen13.c, sp09/screen14.c, sp09/sp09.doc, sp09/system.h, sp09/task1.c, sp09/task2.c, sp09/task3.c, sp09/task4.c, sp11/init.c, sp11/sp11.doc, sp11/system.h, sp11/task1.c, sp11/task2.c, sp11/timer.c, sp12/init.c, sp12/pridrv.c, sp12/pritask.c, sp12/sp12.doc, sp12/system.h, sp12/task1.c, sp12/task2.c, sp12/task3.c, sp12/task4.c, sp12/task5.c, sp13/fillbuff.c, sp13/init.c, sp13/putbuff.c, sp13/sp13.doc, sp13/system.h, sp13/task1.c, sp13/task2.c, sp13/task3.c, sp14/asr.c, sp14/init.c, sp14/sp14.doc, sp14/system.h, sp14/task1.c, sp14/task2.c, sp15/init.c, sp15/sp15.doc, sp15/system.h, sp15/task1.c, sp16/init.c, sp16/sp16.doc, sp16/system.h, sp16/task1.c, sp16/task2.c, sp16/task3.c, sp16/task4.c, sp16/task5.c, sp17/asr.c, sp17/init.c, sp17/sp17.doc, sp17/system.h, sp17/task1.c, sp17/task2.c, sp19/first.c, sp19/fptask.c, sp19/fptest.h, sp19/init.c, sp19/inttest.h, sp19/sp19.doc, sp19/system.h, sp19/task1.c, sp20/getall.c, sp20/init.c, sp20/sp20.doc, sp20/system.h, sp20/task1.c, sp21/init.c, sp21/sp21.doc, sp21/system.h, sp21/task1.c, sp22/delay.c, sp22/init.c, sp22/prtime.c, sp22/sp22.doc, sp22/system.h, sp22/task1.c, sp23/init.c, sp23/sp23.doc, sp23/system.h, sp23/task1.c, sp24/init.c, sp24/resume.c, sp24/sp24.doc, sp24/system.h, sp24/task1.c, sp25/init.c, sp25/sp25.doc, sp25/system.h, sp25/task1.c, sp26/init.c, sp26/sp26.doc, sp26/system.h, sp26/task1.c, sp30/init.c, sp30/resume.c, sp30/sp30.doc, sp30/system.h, sp30/task1.c, sp31/delay.c, sp31/init.c, sp31/prtime.c, sp31/sp31.doc, sp31/system.h, sp31/task1.c, sp32/init.c, spfatal/fatal.c, spfatal/init.c, spfatal/puterr.c, spfatal/spfatal.doc, spfatal/system.h, spfatal/task1.c, spsize/getint.c, spsize/init.c, spsize/size.c, spsize/system.h: URL for license changed.
  • Property mode set to 100644
File size: 8.8 KB
Line 
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-2002.
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.com/license/LICENSE.
17 *
18 *  $Id$
19 */
20
21#include "system.h"
22
23volatile int TSR_fired;
24
25rtems_timer_service_routine Should_not_fire_TSR(
26  rtems_id  ignored_id,
27  void     *ignored_address
28)
29{
30  TSR_fired = 1;
31}
32
33rtems_task Task_1(
34  rtems_task_argument argument
35)
36{
37  rtems_id                 tmid;
38  rtems_id                 tmid2;
39  rtems_time_of_day        time;
40  rtems_status_code        status;
41  rtems_timer_information  info;
42
43/* Get id */
44
45  puts( "TA1 - rtems_timer_ident - identing timer 1" );
46  status = rtems_timer_ident( Timer_name[ 1 ], &tmid );
47  directive_failed( status, "rtems_timer_ident" );
48  printf( "TA1 - timer 1 has id (0x%x)\n", tmid );
49
50  puts( "TA1 - rtems_timer_ident - identing timer 2" );
51  status = rtems_timer_ident( Timer_name[ 2 ], &tmid2 );
52  directive_failed( status, "rtems_timer_ident" );
53  printf( "TA1 - timer 2 has id (0x%x)\n", tmid2 );
54
55/* make sure insertion does not unintentionally fire a timer per PR147 */
56
57  TSR_fired = 0;
58
59  puts( "TA1 - rtems_timer_server_fire_after - 1 second" );
60  status = rtems_timer_server_fire_after(
61    tmid, TICKS_PER_SECOND, Should_not_fire_TSR, NULL );
62  directive_failed( status, "rtems_timer_server_fire_after" );
63
64  puts( "TA1 - rtems_task_wake_after - 1/2 second" );
65  status = rtems_task_wake_after( TICKS_PER_SECOND / 2 );
66  directive_failed( status, "rtems_timer_server_fire_after" );
67
68  directive_failed( status, "rtems_timer_server_fire_after" );
69  puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 1/2 second" );
70  status = rtems_timer_server_fire_after(
71    tmid2, TICKS_PER_SECOND / 2, Should_not_fire_TSR, NULL );
72  directive_failed( status, "rtems_timer_server_fire_after" );
73
74  if ( TSR_fired ) {
75    puts( "TA1 - TSR fired and should not have!" );
76    rtems_test_exit(1);
77  }
78
79  puts( "TA1 - rtems_timer_cancel - timer 1" );
80  status = rtems_timer_cancel( tmid );
81  directive_failed( status, "rtems_timer_cancel" );
82
83  puts( "TA1 - rtems_timer_cancel - timer 2" );
84  status = rtems_timer_cancel( tmid2 );
85  directive_failed( status, "rtems_timer_cancel" );
86
87 
88/* now check that rescheduling an active timer works OK. */
89  puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 30 seconds" );
90  status = rtems_timer_server_fire_after(
91    tmid, 30 * TICKS_PER_SECOND, Delayed_resume, NULL );
92  directive_failed( status, "rtems_timer_server_fire_after" );
93
94  puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" );
95  status = rtems_timer_server_fire_after(
96    tmid2, 60 * TICKS_PER_SECOND, Delayed_resume, NULL );
97  directive_failed( status, "rtems_timer_server_fire_after" );
98
99  status = rtems_timer_get_information( tmid, &info );
100  printf( "Timer 1 scheduled for %d ticks since boot\n",
101    info.start_time + info.initial );
102  printf( "Timer Server scheduled for %d ticks since boot\n",
103    _Timer_Server->Timer.initial + _Timer_Server->Timer.start_time );
104
105  puts( "TA1 - rtems_task_wake_after - 1 second" );
106  status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
107  directive_failed( status, "rtems_timer_wake_after" );
108
109  puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" );
110  status = rtems_timer_server_fire_after(
111    tmid2, 60 * TICKS_PER_SECOND, Delayed_resume, NULL );
112  directive_failed( status, "rtems_timer_server_fire_after" );
113
114  status = rtems_timer_get_information( tmid, &info );
115  directive_failed( status, "rtems_timer_get_information" );
116  printf( "Timer 1 scheduled for %d ticks since boot\n",
117    info.start_time + info.initial );
118  printf( "Timer Server scheduled for %d ticks since boot\n",
119    _Timer_Server->Timer.initial + _Timer_Server->Timer.start_time );
120  assert(  (info.start_time + info.initial) ==
121    (_Timer_Server->Timer.initial + _Timer_Server->Timer.start_time) );
122
123  puts( "TA1 - rtems_task_wake_after - 1 second" );
124  status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
125  directive_failed( status, "rtems_timer_wake_after" );
126
127  puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" );
128  status = rtems_timer_server_fire_after(
129    tmid2, 60 * TICKS_PER_SECOND, Delayed_resume, NULL );
130  directive_failed( status, "rtems_timer_server_fire_after" );
131
132  status = rtems_timer_get_information( tmid, &info );
133  directive_failed( status, "rtems_timer_get_information" );
134  printf( "Timer 1 scheduled for %d ticks since boot\n",
135    info.start_time + info.initial );
136  printf( "Timer Server scheduled for %d ticks since boot\n",
137    _Timer_Server->Timer.initial + _Timer_Server->Timer.start_time );
138  assert(  (info.start_time + info.initial) ==
139    (_Timer_Server->Timer.initial + _Timer_Server->Timer.start_time) );
140
141  puts( "TA1 - rtems_timer_cancel - timer 1" );
142  status = rtems_timer_cancel( tmid );
143  directive_failed( status, "rtems_timer_cancel" );
144
145  puts( "TA1 - rtems_timer_cancel - timer 2" );
146  status = rtems_timer_cancel( tmid2 );
147  directive_failed( status, "rtems_timer_cancel" );
148
149/* after which is allowed to fire */
150
151  Print_time();
152
153  puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" );
154  status = rtems_timer_server_fire_after(
155    tmid,
156    3 * TICKS_PER_SECOND,
157    Delayed_resume,
158    NULL
159  );
160  directive_failed( status, "rtems_timer_server_fire_after" );
161
162  puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" );
163  status = rtems_task_suspend( RTEMS_SELF );
164  directive_failed( status, "rtems_task_suspend" );
165
166  Print_time();
167
168/* after which is reset and allowed to fire */
169
170  puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" );
171  status = rtems_timer_server_fire_after(
172    tmid,
173    3 * TICKS_PER_SECOND,
174    Delayed_resume,
175    NULL
176  );
177  directive_failed( status, "rtems_timer_server_fire_after" );
178
179  puts( "TA1 - rtems_task_wake_after - 1 second" );
180  status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
181  directive_failed( status, "rtems_task_wake_after" );
182
183  Print_time();
184
185  puts( "TA1 - rtems_timer_reset - timer 1" );
186  status = rtems_timer_reset( tmid );
187  directive_failed( status, "rtems_timer_reset" );
188
189  puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" );
190  status = rtems_task_suspend( RTEMS_SELF );
191  directive_failed( status, "rtems_task_suspend" );
192
193  Print_time();
194
195  rtems_test_pause();
196
197  /*
198   *  Reset the time since we do not know how long the user waited
199   *  before pressing <cr> at the pause.  This insures that the
200   *  actual output matches the screen.
201   */
202
203  build_time( &time, 12, 31, 1988, 9, 0, 7, 0 );
204
205  status = rtems_clock_set( &time );
206  directive_failed( status, "rtems_clock_set" );
207
208/* after which is canceled */
209
210  puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" );
211  status = rtems_timer_server_fire_after(
212    tmid,
213    3 * TICKS_PER_SECOND,
214    Delayed_resume,
215    NULL
216  );
217  directive_failed( status, "rtems_timer_server_fire_after" );
218
219  puts( "TA1 - rtems_timer_cancel - timer 1" );
220  status = rtems_timer_cancel( tmid );
221  directive_failed( status, "rtems_timer_cancel" );
222
223/* when which is allowed to fire */
224
225  Print_time();
226
227  status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time );
228  directive_failed( status, "rtems_clock_get" );
229
230  time.second += 3;
231
232  puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 3 seconds" );
233  status = rtems_timer_server_fire_when( tmid, &time, Delayed_resume, NULL );
234  directive_failed( status, "rtems_timer_server_fire_when" );
235
236  puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" );
237  status = rtems_task_suspend( RTEMS_SELF );
238  directive_failed( status, "rtems_task_suspend" );
239
240  Print_time();
241
242/* when which is canceled */
243
244  status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time );
245  directive_failed( status, "rtems_clock_get" );
246
247  time.second += 3;
248
249  puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 3 seconds" );
250  status = rtems_timer_server_fire_when( tmid, &time, Delayed_resume, NULL );
251  directive_failed( status, "rtems_timer_server_fire_when" );
252
253  puts( "TA1 - rtems_task_wake_after - 1 second" );
254  status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
255  directive_failed( status, "rtems_task_wake_after" );
256
257  Print_time();
258
259  puts( "TA1 - rtems_timer_cancel - timer 1" );
260  status = rtems_timer_cancel( tmid );
261  directive_failed( status, "rtems_timer_cancel" );
262
263/* delete */
264  puts( "TA1 - rtems_task_wake_after - YIELD (only task at priority)" );
265  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
266  directive_failed( status, "rtems_task_wake_after" );
267
268  puts( "TA1 - timer_deleting - timer 1" );
269  status = rtems_timer_delete( tmid );
270  directive_failed( status, "rtems_timer_delete" );
271
272  puts( "*** END OF TEST 31 *** " );
273  rtems_test_exit( 0 );
274}
Note: See TracBrowser for help on using the repository browser.