1 | /* Priority_task |
---|
2 | * |
---|
3 | * This routine serves as a test task. It verifies the semaphore manager. |
---|
4 | * |
---|
5 | * Input parameters: |
---|
6 | * its_index - priority index |
---|
7 | * |
---|
8 | * Output parameters: NONE |
---|
9 | * |
---|
10 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * All rights assigned to U.S. Government, 1994. |
---|
13 | * |
---|
14 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
15 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
16 | * notice must appear in all copies of this file and its derivatives. |
---|
17 | * |
---|
18 | * $Id$ |
---|
19 | */ |
---|
20 | |
---|
21 | #include "system.h" |
---|
22 | |
---|
23 | rtems_task Priority_task( |
---|
24 | rtems_task_argument its_index |
---|
25 | ) |
---|
26 | { |
---|
27 | rtems_interval timeout; |
---|
28 | rtems_task_priority its_priority; |
---|
29 | rtems_task_priority current_priority; |
---|
30 | rtems_status_code status; |
---|
31 | rtems_unsigned32 index; |
---|
32 | |
---|
33 | its_priority = Task_priority[ its_index ]; |
---|
34 | |
---|
35 | if ( its_priority < 3 ) |
---|
36 | timeout = 5 * TICKS_PER_SECOND; |
---|
37 | else |
---|
38 | timeout = RTEMS_NO_TIMEOUT; |
---|
39 | |
---|
40 | put_name( Priority_task_name[ its_index ], FALSE ); |
---|
41 | puts( " - rtems_semaphore_obtain - wait forever on SM2" ); |
---|
42 | |
---|
43 | status = rtems_semaphore_obtain( |
---|
44 | Semaphore_id[ 2 ], |
---|
45 | RTEMS_DEFAULT_OPTIONS, |
---|
46 | timeout |
---|
47 | ); |
---|
48 | directive_failed( status, "rtems_semaphore_obtain of SM2" ); |
---|
49 | |
---|
50 | if ( its_priority < 64 ) { |
---|
51 | printf( "PRI%d - WHY AM I HERE? (pri=%d)", its_index, its_priority ); |
---|
52 | exit( 0 ); |
---|
53 | } |
---|
54 | |
---|
55 | if ( its_index == 5 ) |
---|
56 | puts( "PRI5 - rtems_task_suspend - until all priority tasks blocked" ); |
---|
57 | status = rtems_task_suspend( RTEMS_SELF ); |
---|
58 | directive_failed( status, "rtems_task_suspend" ); |
---|
59 | |
---|
60 | puts( "PRI5 - rtems_task_delete - all tasks waiting on SM2" ); |
---|
61 | for ( index = 1 ; index < 5 ; index++ ) { |
---|
62 | status = rtems_task_delete( Priority_task_id[ index ] ); |
---|
63 | directive_failed( status, "rtems_task_delete loop" ); |
---|
64 | } |
---|
65 | |
---|
66 | puts( "PRI5 - rtems_semaphore_obtain - nested" ); |
---|
67 | status = rtems_semaphore_obtain( |
---|
68 | Semaphore_id[ 2 ], |
---|
69 | RTEMS_DEFAULT_OPTIONS, |
---|
70 | timeout |
---|
71 | ); |
---|
72 | directive_failed( status, "rtems_semaphore_obtain nested" ); |
---|
73 | |
---|
74 | puts( "PRI5 - rtems_semaphore_release - nested" ); |
---|
75 | status = rtems_semaphore_release( Semaphore_id[ 2 ] ); |
---|
76 | directive_failed( status, "rtems_semaphore_release nested " ); |
---|
77 | |
---|
78 | puts( "PRI5 - rtems_semaphore_release - restore priority" ); |
---|
79 | status = rtems_semaphore_release( Semaphore_id[ 2 ] ); |
---|
80 | directive_failed( status, "rtems_semaphore_release" ); |
---|
81 | |
---|
82 | status = rtems_task_set_priority( |
---|
83 | RTEMS_SELF, |
---|
84 | RTEMS_CURRENT_PRIORITY, |
---|
85 | ¤t_priority |
---|
86 | ); |
---|
87 | directive_failed( status, "PRI5 rtems_task_set_priority CURRENT" ); |
---|
88 | printf( "PRI5 - priority of PRI5 is %d\n", current_priority ); |
---|
89 | |
---|
90 | (void) rtems_task_suspend( RTEMS_SELF ); |
---|
91 | } |
---|