OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [tests/] [tmtests/] [tm04/] [task1.c] - Blame information for rev 562

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *
3
 *  COPYRIGHT (c) 1989-1999.
4
 *  On-Line Applications Research Corporation (OAR).
5
 *
6
 *  The license and distribution terms for this file may be
7
 *  found in the file LICENSE in this distribution or at
8
 *  http://www.OARcorp.com/rtems/license.html.
9
 *
10
 *  $Id: task1.c,v 1.2 2001-09-27 12:02:41 chris Exp $
11
 */
12
 
13
#define TEST_INIT
14
#include "system.h"
15
 
16
rtems_id         Semaphore_id;
17
rtems_id         Task_id[OPERATION_COUNT+1];
18
rtems_unsigned32 task_count;
19
rtems_id         Highest_id;
20
 
21
rtems_task Low_tasks(
22
  rtems_task_argument argument
23
);
24
 
25
rtems_task High_task(
26
  rtems_task_argument argument
27
);
28
 
29
rtems_task Restart_task(
30
  rtems_task_argument argument
31
);
32
 
33
void test_init();
34
 
35
rtems_task Init(
36
  rtems_task_argument argument
37
)
38
{
39
  rtems_status_code status;
40
 
41
  Print_Warning();
42
 
43
  puts( "\n\n*** TIME TEST 4 ***" );
44
 
45
  test_init();
46
 
47
  status = rtems_task_delete( RTEMS_SELF );
48
  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
49
}
50
 
51
void test_init()
52
{
53
  rtems_status_code status;
54
  rtems_unsigned32  index;
55
 
56
  task_count = OPERATION_COUNT;
57
 
58
  for ( index = 1 ; index <= OPERATION_COUNT ; index++ ) {
59
 
60
    status = rtems_task_create(
61
      rtems_build_name( 'T', 'I', 'M', 'E' ),
62
      10,
63
      RTEMS_MINIMUM_STACK_SIZE,
64
      RTEMS_NO_PREEMPT,
65
      RTEMS_DEFAULT_ATTRIBUTES,
66
      &Task_id[ index ]
67
    );
68
    directive_failed( status, "rtems_task_create loop" );
69
 
70
    status = rtems_task_start( Task_id[ index ], Low_tasks, 0 );
71
    directive_failed( status, "rtems_task_start loop" );
72
  }
73
 
74
  status = rtems_semaphore_create(
75
    rtems_build_name( 'S', 'M', '1', ' ' ),
76
    0,
77
    RTEMS_DEFAULT_ATTRIBUTES,
78
    RTEMS_NO_PRIORITY,
79
    &Semaphore_id
80
  );
81
  directive_failed( status, "rtems_semaphore_create of SM1" );
82
}
83
 
84
rtems_task Highest_task(
85
  rtems_task_argument argument
86
)
87
{
88
  rtems_task_priority old_priority;
89
  rtems_status_code   status;
90
 
91
  if ( argument == 1 ) {
92
 
93
    end_time = Read_timer();
94
 
95
    put_time(
96
      "rtems_task_restart: blocked task -- preempts caller",
97
      end_time,
98
      1,
99
      0,
100
      CALLING_OVERHEAD_TASK_RESTART
101
    );
102
 
103
    status = rtems_task_set_priority(
104
      RTEMS_CURRENT_PRIORITY,
105
      254,
106
      &old_priority
107
    );
108
    directive_failed( status, "rtems_task_set_priority" );
109
 
110
 } else if ( argument == 2 ) {
111
 
112
  end_time = Read_timer();
113
 
114
    put_time(
115
      "rtems_task_restart: ready task -- preempts caller",
116
      end_time,
117
      1,
118
      0,
119
      CALLING_OVERHEAD_TASK_RESTART
120
    );
121
 
122
    status = rtems_task_delete( RTEMS_SELF );
123
    directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
124
 
125
  } else
126
    (void) rtems_semaphore_obtain(
127
      Semaphore_id,
128
      RTEMS_DEFAULT_OPTIONS,
129
      RTEMS_NO_TIMEOUT
130
    );
131
 
132
}
133
 
134
rtems_task High_task(
135
  rtems_task_argument argument
136
)
137
{
138
  rtems_status_code   status;
139
  rtems_unsigned32    index;
140
  rtems_name          name;
141
  rtems_task_priority old_priority;
142
 
143
  Timer_initialize();
144
    (void) rtems_task_restart( Highest_id, 1 );
145
  /* preempted by Higher_task */
146
 
147
  Timer_initialize();
148
    (void) rtems_task_restart( Highest_id, 2 );
149
  /* preempted by Higher_task */
150
 
151
  Timer_initialize();
152
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
153
      (void) Empty_function();
154
  overhead = Read_timer();
155
 
156
  Timer_initialize();
157
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
158
      rtems_semaphore_release( Semaphore_id );
159
  end_time = Read_timer();
160
 
161
  put_time(
162
    "rtems_semaphore_release: task readied -- returns to caller",
163
    end_time,
164
    OPERATION_COUNT,
165
    0,
166
    CALLING_OVERHEAD_SEMAPHORE_RELEASE
167
  );
168
 
169
  name = rtems_build_name( 'T', 'I', 'M', 'E' );
170
 
171
  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
172
    status = rtems_task_delete( Task_id[index] );
173
    directive_failed( status, "rtems_task_delete" );
174
  }
175
 
176
  Timer_initialize();
177
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
178
     rtems_task_create(
179
        name,
180
        10,
181
        RTEMS_MINIMUM_STACK_SIZE,
182
        RTEMS_NO_PREEMPT,
183
        RTEMS_DEFAULT_ATTRIBUTES,
184
        &Task_id[ index ]
185
      );
186
  end_time = Read_timer();
187
 
188
  put_time(
189
    "rtems_task_create",
190
    end_time,
191
    OPERATION_COUNT,
192
    overhead,
193
    CALLING_OVERHEAD_TASK_CREATE
194
  );
195
 
196
  Timer_initialize();
197
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
198
      rtems_task_start( Task_id[ index ], Low_tasks, 0 );
199
 
200
  end_time = Read_timer();
201
 
202
  put_time(
203
    "rtems_task_start",
204
    end_time,
205
    OPERATION_COUNT,
206
    overhead,
207
    CALLING_OVERHEAD_TASK_START
208
  );
209
 
210
  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
211
    status = rtems_task_delete( Task_id[ index ] );
212
    directive_failed( status, "rtems_task_delete" );
213
  }
214
 
215
  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
216
    status = rtems_task_create(
217
      name,
218
      250,
219
      RTEMS_MINIMUM_STACK_SIZE,
220
      RTEMS_NO_PREEMPT,
221
      RTEMS_DEFAULT_ATTRIBUTES,
222
      &Task_id[ index ]
223
    );
224
    directive_failed( status, "rtems_task_create LOOP" );
225
 
226
    status = rtems_task_start( Task_id[ index ], Restart_task, 0 );
227
    directive_failed( status, "rtems_task_start LOOP" );
228
 
229
    status = rtems_task_suspend( Task_id[ index ] );
230
    directive_failed( status, "rtems_task_suspend LOOP" );
231
  }
232
 
233
  Timer_initialize();
234
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
235
      (void) rtems_task_restart( Task_id[ index ], 0 );
236
  end_time = Read_timer();
237
 
238
  put_time(
239
    "rtems_task_restart: suspended task -- returns to caller",
240
    end_time,
241
    OPERATION_COUNT,
242
    overhead,
243
    CALLING_OVERHEAD_TASK_RESTART
244
  );
245
 
246
  for ( index=1 ; index <= OPERATION_COUNT ; index++ )
247
    (void) rtems_task_suspend( Task_id[ index ] );
248
 
249
  Timer_initialize();
250
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
251
      (void) rtems_task_delete( Task_id[ index ] );
252
  end_time = Read_timer();
253
 
254
  put_time(
255
    "rtems_task_delete: suspended task",
256
    end_time,
257
    OPERATION_COUNT,
258
    overhead,
259
    CALLING_OVERHEAD_TASK_DELETE
260
  );
261
 
262
  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
263
    status = rtems_task_create(
264
      name,
265
      250,
266
      RTEMS_MINIMUM_STACK_SIZE,
267
      RTEMS_DEFAULT_MODES,
268
      RTEMS_DEFAULT_ATTRIBUTES,
269
      &Task_id[ index ]
270
    );
271
    directive_failed( status, "rtems_task_create LOOP" );
272
 
273
    status = rtems_task_start( Task_id[ index ], Restart_task, 0 );
274
    directive_failed( status, "rtems_task_start LOOP" );
275
  }
276
 
277
  Timer_initialize();
278
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
279
      (void) rtems_task_restart( Task_id[ index ], 1 );
280
  end_time = Read_timer();
281
 
282
  put_time(
283
    "rtems_task_restart: ready task -- returns to caller",
284
    end_time,
285
    OPERATION_COUNT,
286
    overhead,
287
    CALLING_OVERHEAD_TASK_RESTART
288
  );
289
 
290
  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
291
    status = rtems_task_set_priority( Task_id[ index ], 5, &old_priority );
292
    directive_failed( status, "rtems_task_set_priority loop" );
293
  }
294
 
295
  /* yield processor -- tasks block */
296
  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
297
  directive_failed( status, "rtems_task_wake_after" );
298
 
299
  Timer_initialize();
300
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
301
      (void) rtems_task_restart( Task_id[ index ], 1 );
302
  end_time = Read_timer();
303
 
304
  put_time(
305
    "rtems_task_restart: blocked task -- returns to caller",
306
    end_time,
307
    OPERATION_COUNT,
308
    overhead,
309
    CALLING_OVERHEAD_TASK_RESTART
310
  );
311
 
312
  /* yield processor -- tasks block */
313
  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
314
  directive_failed( status, "rtems_task_wake_after" );
315
 
316
  Timer_initialize();
317
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
318
      (void) rtems_task_delete( Task_id[ index ] );
319
  end_time = Read_timer();
320
 
321
  put_time(
322
    "rtems_task_delete: blocked task",
323
    end_time,
324
    OPERATION_COUNT,
325
    overhead,
326
    CALLING_OVERHEAD_TASK_DELETE
327
  );
328
 
329
  puts( "*** END OF TEST 4 ***" );
330
  exit( 0 );
331
}
332
 
333
rtems_task Low_tasks(
334
  rtems_task_argument argument
335
)
336
{
337
  rtems_id          id;
338
  rtems_status_code status;
339
 
340
  task_count--;
341
 
342
  if ( task_count == 0 ) {
343
    status = rtems_task_create(
344
      rtems_build_name( 'H', 'I', ' ', ' ' ),
345
      5,
346
      RTEMS_MINIMUM_STACK_SIZE,
347
      RTEMS_DEFAULT_MODES,
348
      RTEMS_DEFAULT_ATTRIBUTES,
349
      &id
350
    );
351
    directive_failed( status, "rtems_task_create HI" );
352
 
353
    status = rtems_task_start( id, High_task, 0 );
354
    directive_failed( status, "rtems_task_start HI" );
355
 
356
    status = rtems_task_create(
357
      rtems_build_name( 'H', 'I', 'G', 'H' ),
358
      3,
359
      RTEMS_MINIMUM_STACK_SIZE,
360
      RTEMS_DEFAULT_MODES,
361
      RTEMS_DEFAULT_ATTRIBUTES,
362
      &Highest_id
363
    );
364
    directive_failed( status, "rtems_task_create HIGH" );
365
 
366
    status = rtems_task_start( Highest_id, Highest_task, 0 );
367
    directive_failed( status, "rtems_task_start HIGH" );
368
 
369
  }
370
  (void) rtems_semaphore_obtain(
371
    Semaphore_id,
372
    RTEMS_DEFAULT_OPTIONS,
373
    RTEMS_NO_TIMEOUT
374
  );
375
}
376
 
377
rtems_task Restart_task(
378
  rtems_task_argument argument
379
)
380
{
381
  if ( argument == 1 )
382
    (void) rtems_semaphore_obtain(
383
      Semaphore_id,
384
      RTEMS_DEFAULT_OPTIONS,
385
      RTEMS_NO_TIMEOUT
386
    );
387
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.