1 | /* Test_task |
---|
2 | * |
---|
3 | * This task is used for three test tasks. It obtains its task id and |
---|
4 | * based upon that id, performs certain actions. |
---|
5 | * |
---|
6 | * Task_1 delays 5 seconds and deletes itself. |
---|
7 | * Task_2 delays 10 seconds and then loops until |
---|
8 | * deleted by the third task. |
---|
9 | * Task 3 delays 15 seconds, then deletes task 2 and itself. |
---|
10 | * |
---|
11 | * Input parameters: |
---|
12 | * argument - task argument |
---|
13 | * |
---|
14 | * Output parameters: NONE |
---|
15 | * |
---|
16 | * COPYRIGHT (c) 1989-2009. |
---|
17 | * On-Line Applications Research Corporation (OAR). |
---|
18 | * |
---|
19 | * The license and distribution terms for this file may be |
---|
20 | * found in the file LICENSE in this distribution or at |
---|
21 | * http://www.rtems.org/license/LICENSE. |
---|
22 | */ |
---|
23 | |
---|
24 | #ifdef HAVE_CONFIG_H |
---|
25 | #include "config.h" |
---|
26 | #endif |
---|
27 | |
---|
28 | #include "system.h" |
---|
29 | |
---|
30 | rtems_task Test_task( |
---|
31 | rtems_task_argument argument |
---|
32 | ) |
---|
33 | { |
---|
34 | rtems_status_code status; |
---|
35 | rtems_id tid; |
---|
36 | rtems_time_of_day time; |
---|
37 | |
---|
38 | status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid ); |
---|
39 | directive_failed( status, "rtems_task_ident" ); |
---|
40 | |
---|
41 | status = rtems_clock_get_tod( &time ); |
---|
42 | directive_failed( status, "rtems_clock_get_tod" ); |
---|
43 | |
---|
44 | put_name( Task_name[ task_number( tid ) ], FALSE ); |
---|
45 | print_time( " - rtems_clock_get_tod - ", &time, "\n" ); |
---|
46 | |
---|
47 | status = rtems_task_wake_after( task_number( tid ) * 1 * rtems_clock_get_ticks_per_second() ); |
---|
48 | directive_failed( status, "rtems_task_wake_after" ); |
---|
49 | |
---|
50 | status = rtems_clock_get_tod( &time ); |
---|
51 | directive_failed( status, "rtems_clock_get_tod" ); |
---|
52 | put_name( Task_name[ task_number( tid ) ], FALSE ); |
---|
53 | print_time( " - rtems_clock_get_tod - ", &time, "\n" ); |
---|
54 | |
---|
55 | if ( task_number(tid) == 1 ) { /* TASK 1 */ |
---|
56 | put_name( Task_name[ 1 ], FALSE ); |
---|
57 | printf( " - deleting self\n" ); |
---|
58 | rtems_task_exit(); |
---|
59 | } |
---|
60 | else if ( task_number(tid) == 2 ) { /* TASK 2 */ |
---|
61 | put_name( Task_name[ 2 ], FALSE ); |
---|
62 | printf( " - waiting to be deleted by " ); |
---|
63 | put_name( Task_name[ 3 ], TRUE ); |
---|
64 | while ( FOREVER ); |
---|
65 | } |
---|
66 | else { /* TASK 3 */ |
---|
67 | put_name( Task_name[ 3 ], FALSE ); |
---|
68 | printf( " - getting TID of " ); |
---|
69 | put_name( Task_name[ 2 ], TRUE ); |
---|
70 | do { |
---|
71 | status = rtems_task_ident( Task_name[ 2 ], RTEMS_SEARCH_ALL_NODES, &tid ); |
---|
72 | } while ( status != RTEMS_SUCCESSFUL ); |
---|
73 | directive_failed( status, "rtems_task_ident" ); |
---|
74 | |
---|
75 | put_name( Task_name[ 3 ], FALSE ); |
---|
76 | printf( " - deleting " ); |
---|
77 | put_name( Task_name[ 2 ], TRUE ); |
---|
78 | status = rtems_task_delete( tid ); |
---|
79 | directive_failed( status, "rtems_task_delete of Task 2" ); |
---|
80 | |
---|
81 | puts( "*** END OF TEST 1 ***" ); |
---|
82 | rtems_test_exit(0); |
---|
83 | } |
---|
84 | } |
---|