1 | /* |
---|
2 | * Test program to demonstrate reordering of threads on thread queues |
---|
3 | * when their priority changes. |
---|
4 | * |
---|
5 | * $Id$ |
---|
6 | */ |
---|
7 | |
---|
8 | #include <bsp.h> |
---|
9 | #include <stdio.h> |
---|
10 | |
---|
11 | /********************************************************************/ |
---|
12 | /* define this to use the RTEMS 4.5 scheme for object names */ |
---|
13 | #define TEST_ON_RTEMS_45 |
---|
14 | |
---|
15 | /* define this to print the Id of the calling task */ |
---|
16 | /* #define TEST_ON_TASK_ID */ |
---|
17 | |
---|
18 | /********************************************************************/ |
---|
19 | |
---|
20 | #include <bsp.h> |
---|
21 | #include <stdio.h> |
---|
22 | #include "tmacros.h" |
---|
23 | |
---|
24 | rtems_task BlockingTasks(rtems_task_argument arg); |
---|
25 | |
---|
26 | /* |
---|
27 | * CallerName -- print the calling tasks name or id as configured |
---|
28 | */ |
---|
29 | const char *CallerName() |
---|
30 | { |
---|
31 | static char buffer[32]; |
---|
32 | #if defined(TEST_PRINT_TASK_ID) |
---|
33 | sprintf( buffer, "0x%08x -- %d", |
---|
34 | _Thread_Executing->Object.id, _Thread_Executing->current_priority ); |
---|
35 | #else |
---|
36 | union { |
---|
37 | uint32_t u; |
---|
38 | unsigned char c[4]; |
---|
39 | } TempName; |
---|
40 | |
---|
41 | #if defined(TEST_ON_RTEMS_45) |
---|
42 | TempName.u = *(uint32_t *)_Thread_Executing->Object.name; |
---|
43 | #else |
---|
44 | TempName.u = _Thread_Executing->Object.name; |
---|
45 | #endif |
---|
46 | sprintf( buffer, "%c%c%c%c -- %d", |
---|
47 | TempName.c[0], TempName.c[1], TempName.c[2], TempName.c[3], |
---|
48 | _Thread_Executing->current_priority |
---|
49 | ); |
---|
50 | #endif |
---|
51 | return buffer; |
---|
52 | } |
---|
53 | |
---|
54 | #define NUMBER_OF_BLOCKING_TASKS 5 |
---|
55 | |
---|
56 | /* RTEMS ids of blocking threads */ |
---|
57 | rtems_id Blockers[NUMBER_OF_BLOCKING_TASKS]; |
---|
58 | |
---|
59 | /* Semaphore they are all blocked on */ |
---|
60 | rtems_id Semaphore; |
---|
61 | |
---|
62 | rtems_task BlockingTasks(rtems_task_argument arg) |
---|
63 | { |
---|
64 | rtems_status_code status; |
---|
65 | rtems_task_priority opri; |
---|
66 | rtems_task_priority npri; |
---|
67 | |
---|
68 | status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &opri); |
---|
69 | directive_failed( status, "rtems_task_set_priority" ); |
---|
70 | |
---|
71 | printf("semaphore_obtain -- BlockingTask %d @ pri=%d) blocks\n", arg, opri); |
---|
72 | status = rtems_semaphore_obtain(Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
73 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
74 | |
---|
75 | /* priority should have changed while blocked */ |
---|
76 | status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &npri); |
---|
77 | directive_failed( status, "rtems_task_set_priority" ); |
---|
78 | |
---|
79 | printf("semaphore_obtain -- BlockingTask %d @ pri=%d) returns\n", arg, npri); |
---|
80 | |
---|
81 | (void) rtems_task_delete( RTEMS_SELF ); |
---|
82 | } |
---|
83 | |
---|
84 | /*************************************************************************/ |
---|
85 | /********************** INITIALIZATION *********************/ |
---|
86 | /*************************************************************************/ |
---|
87 | |
---|
88 | rtems_task Init(rtems_task_argument ignored) |
---|
89 | { |
---|
90 | rtems_status_code status; |
---|
91 | int i; |
---|
92 | |
---|
93 | puts( "\n\n*** TEST 34 ***" ); |
---|
94 | |
---|
95 | /* Create synchronisation semaphore for LocalHwIsr -> Test Tasks */ |
---|
96 | status = rtems_semaphore_create( |
---|
97 | rtems_build_name ('S', 'E', 'M', '1'), /* name */ |
---|
98 | 0, /* initial count = 0 */ |
---|
99 | RTEMS_LOCAL | |
---|
100 | RTEMS_COUNTING_SEMAPHORE | |
---|
101 | RTEMS_PRIORITY, |
---|
102 | 0, |
---|
103 | &Semaphore); /* *id */ |
---|
104 | directive_failed( status, "rtems_semaphore_create" ); |
---|
105 | |
---|
106 | /* Create and start all tasks in the test */ |
---|
107 | |
---|
108 | for (i = 0; i < NUMBER_OF_BLOCKING_TASKS; i++) { |
---|
109 | status = rtems_task_create( |
---|
110 | rtems_build_name('B','L','K','0'+i), /* Name */ |
---|
111 | 2+i, /* Priority */ |
---|
112 | RTEMS_MINIMUM_STACK_SIZE*2, /* Stack size (8KB) */ |
---|
113 | RTEMS_DEFAULT_MODES | RTEMS_NO_ASR, /* Mode */ |
---|
114 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, /* Attributes */ |
---|
115 | &Blockers[i]); /* Assigned ID */ |
---|
116 | directive_failed( status, "rtems_task_create (BLKn)" ); |
---|
117 | |
---|
118 | printf( "Blockers[%d] Id = 0x%08x\n", i, Blockers[i] ); |
---|
119 | status = rtems_task_start(Blockers[i], BlockingTasks, i); |
---|
120 | directive_failed( status, "rtems_task_start (BLKn)" ); |
---|
121 | } |
---|
122 | |
---|
123 | status = rtems_task_wake_after( 100 ); |
---|
124 | directive_failed( status, "rtems_task_wake_after" ); |
---|
125 | |
---|
126 | puts( "rtems_task_set_priority -- invert priorities of tasks" ); |
---|
127 | for (i = 0; i < NUMBER_OF_BLOCKING_TASKS; i++) { |
---|
128 | rtems_task_priority opri; |
---|
129 | rtems_task_priority npri= 2 + NUMBER_OF_BLOCKING_TASKS - i - 1; |
---|
130 | |
---|
131 | status = rtems_task_set_priority(Blockers[i], npri, &opri); |
---|
132 | directive_failed( status, "rtems_task_set_priority" ); |
---|
133 | } |
---|
134 | |
---|
135 | for (i = 0; i < NUMBER_OF_BLOCKING_TASKS; i++) { |
---|
136 | puts( "rtems_semaphore_release -- OK" ); |
---|
137 | status = rtems_semaphore_release(Semaphore); |
---|
138 | directive_failed( status, "rtems_semaphore_release" ); |
---|
139 | |
---|
140 | status = rtems_task_wake_after( 100 ); |
---|
141 | directive_failed( status, "rtems_task_wake_after" ); |
---|
142 | } |
---|
143 | |
---|
144 | /* exit the test */ |
---|
145 | puts( "*** END OF TEST 34 ***" ); |
---|
146 | exit(0); |
---|
147 | } |
---|
148 | |
---|
149 | /* configuration information */ |
---|
150 | |
---|
151 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
152 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
153 | |
---|
154 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
155 | |
---|
156 | #define CONFIGURE_EXTRA_TASK_STACKS \ |
---|
157 | (RTEMS_MINIMUM_STACK_SIZE * NUMBER_OF_BLOCKING_TASKS) |
---|
158 | |
---|
159 | #define CONFIGURE_MAXIMUM_TASKS 6 |
---|
160 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
161 | |
---|
162 | #define CONFIGURE_INIT |
---|
163 | |
---|
164 | #include <rtems/confdefs.h> |
---|
165 | |
---|
166 | /* end of file */ |
---|