1 | /* |
---|
2 | * COPYRIGHT (c) 2011. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <tmacros.h> |
---|
17 | |
---|
18 | /* |
---|
19 | * Keep the names and IDs in global variables so another task can use them. |
---|
20 | */ |
---|
21 | rtems_id Task_id[ 3 ]; /* array of task ids */ |
---|
22 | rtems_name Task_name[ 3 ]; /* array of task names */ |
---|
23 | rtems_name Semaphore_name[ 2 ]; |
---|
24 | rtems_id Semaphore_id[ 2 ]; |
---|
25 | |
---|
26 | rtems_task Test_task( |
---|
27 | rtems_task_argument unused |
---|
28 | ) |
---|
29 | { |
---|
30 | rtems_id tid; |
---|
31 | uint32_t task_index; |
---|
32 | rtems_status_code status; |
---|
33 | |
---|
34 | status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid ); |
---|
35 | task_index = task_number( tid ); |
---|
36 | |
---|
37 | for ( ; ; ) { |
---|
38 | rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | void ObtainRelease( bool suspendIdle ) |
---|
43 | { |
---|
44 | rtems_status_code status; |
---|
45 | |
---|
46 | if (suspendIdle) { |
---|
47 | puts( "INIT - Suspend Idle Task"); |
---|
48 | status = rtems_task_suspend( _Thread_Idle->Object.id ); |
---|
49 | directive_failed( status, "rtems_task_suspend idle" ); |
---|
50 | } |
---|
51 | |
---|
52 | puts( "INIT - Obtain priority ceiling semaphore - priority increases" ); |
---|
53 | status= rtems_semaphore_obtain( Semaphore_id[1], RTEMS_DEFAULT_OPTIONS, 0 ); |
---|
54 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
55 | |
---|
56 | puts( "INIT - Obtain priority ceiling semaphore - priority decreases" ); |
---|
57 | status = rtems_semaphore_release( Semaphore_id[1] ); |
---|
58 | directive_failed( status, "rtems_semaphore_release" ); |
---|
59 | |
---|
60 | if (suspendIdle) { |
---|
61 | puts( "INIT - Resume Idle Task"); |
---|
62 | status = rtems_task_resume( _Thread_Idle->Object.id ); |
---|
63 | directive_failed( status, "rtems_task_resume idle" ); |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | rtems_task Init( |
---|
68 | rtems_task_argument argument |
---|
69 | ) |
---|
70 | { |
---|
71 | rtems_status_code status; |
---|
72 | |
---|
73 | puts( "\n\n*** SIMPLE SCHEDULER 02 TEST ***" ); |
---|
74 | |
---|
75 | /* |
---|
76 | * Create the semaphore. Then obtain and release the |
---|
77 | * semaphore with no other tasks running. |
---|
78 | */ |
---|
79 | puts( "INIT - Create priority ceiling semaphore" ); |
---|
80 | Semaphore_name[ 1 ] = rtems_build_name( 'S', 'M', '1', ' ' ); |
---|
81 | status = rtems_semaphore_create( |
---|
82 | Semaphore_name[ 1 ], |
---|
83 | 1, |
---|
84 | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY_CEILING | RTEMS_PRIORITY, |
---|
85 | 2, |
---|
86 | &Semaphore_id[ 1 ] |
---|
87 | ); |
---|
88 | directive_failed( status, "rtems_semaphore_create of SM1" ); |
---|
89 | ObtainRelease( false ); |
---|
90 | |
---|
91 | /* |
---|
92 | * Create test task and obtain release the semaphore with |
---|
93 | * one other task running. |
---|
94 | */ |
---|
95 | puts( "INIT - create task 1" ); |
---|
96 | Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' ); |
---|
97 | status = rtems_task_create( |
---|
98 | Task_name[ 1 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, |
---|
99 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 1 ] |
---|
100 | ); |
---|
101 | status = rtems_task_start( Task_id[ 1 ], Test_task, 1 ); |
---|
102 | ObtainRelease( false ); |
---|
103 | |
---|
104 | /* |
---|
105 | * Create a a second test task and obtain release the semaphore |
---|
106 | * with both tasks running. |
---|
107 | */ |
---|
108 | puts( "INIT - create task 2" ); |
---|
109 | Task_name[ 1 ] = rtems_build_name( 'T', 'A', '2', ' ' ); |
---|
110 | status = rtems_task_create( |
---|
111 | Task_name[ 2 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, |
---|
112 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 2 ] |
---|
113 | ); |
---|
114 | status = rtems_task_start( Task_id[ 2 ], Test_task, 1 ); |
---|
115 | ObtainRelease( false ); |
---|
116 | |
---|
117 | /* |
---|
118 | * Obtain and release the semaphore with the idle task suspended. |
---|
119 | */ |
---|
120 | ObtainRelease( true ); |
---|
121 | |
---|
122 | /* End the Test */ |
---|
123 | puts( "*** END OF SIMPLE SCHEDULER 02 TEST ***" ); |
---|
124 | rtems_test_exit(0); |
---|
125 | } |
---|
126 | |
---|
127 | /* configuration information */ |
---|
128 | |
---|
129 | #define CONFIGURE_SCHEDULER_SIMPLE |
---|
130 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
131 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
132 | |
---|
133 | #define CONFIGURE_MAXIMUM_TASKS 3 |
---|
134 | #define CONFIGURE_MAXIMUM_SEMAPHORES 2 |
---|
135 | |
---|
136 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
137 | |
---|
138 | #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) |
---|
139 | #define CONFIGURE_INIT_TASK_PRIORITY 4 |
---|
140 | |
---|
141 | #define CONFIGURE_INIT |
---|
142 | #include <rtems/confdefs.h> |
---|
143 | /* end of include file */ |
---|