1 | /* |
---|
2 | * RTEMS Task Manager |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1998. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * Copyright assigned to U.S. Government, 1994. |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.OARcorp.com/rtems/license.html. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/rtems/status.h> |
---|
18 | #include <rtems/rtems/support.h> |
---|
19 | #include <rtems/rtems/modes.h> |
---|
20 | #include <rtems/score/object.h> |
---|
21 | #include <rtems/score/stack.h> |
---|
22 | #include <rtems/score/states.h> |
---|
23 | #include <rtems/rtems/tasks.h> |
---|
24 | #include <rtems/score/thread.h> |
---|
25 | #include <rtems/score/threadq.h> |
---|
26 | #include <rtems/score/tod.h> |
---|
27 | #include <rtems/score/userext.h> |
---|
28 | #include <rtems/score/wkspace.h> |
---|
29 | #include <rtems/score/apiext.h> |
---|
30 | #include <rtems/score/sysstate.h> |
---|
31 | |
---|
32 | /*PAGE |
---|
33 | * |
---|
34 | * _RTEMS_tasks_Create_extension |
---|
35 | * |
---|
36 | * XXX |
---|
37 | */ |
---|
38 | |
---|
39 | boolean _RTEMS_tasks_Create_extension( |
---|
40 | Thread_Control *executing, |
---|
41 | Thread_Control *created |
---|
42 | ) |
---|
43 | { |
---|
44 | RTEMS_API_Control *api; |
---|
45 | |
---|
46 | api = _Workspace_Allocate( sizeof( RTEMS_API_Control ) ); |
---|
47 | |
---|
48 | if ( !api ) |
---|
49 | return FALSE; |
---|
50 | |
---|
51 | created->API_Extensions[ THREAD_API_RTEMS ] = api; |
---|
52 | |
---|
53 | api->pending_events = EVENT_SETS_NONE_PENDING; |
---|
54 | _ASR_Initialize( &api->Signal ); |
---|
55 | return TRUE; |
---|
56 | } |
---|
57 | |
---|
58 | /*PAGE |
---|
59 | * |
---|
60 | * _RTEMS_tasks_Start_extension |
---|
61 | * |
---|
62 | * XXX |
---|
63 | */ |
---|
64 | |
---|
65 | User_extensions_routine _RTEMS_tasks_Start_extension( |
---|
66 | Thread_Control *executing, |
---|
67 | Thread_Control *started |
---|
68 | ) |
---|
69 | { |
---|
70 | RTEMS_API_Control *api; |
---|
71 | |
---|
72 | api = started->API_Extensions[ THREAD_API_RTEMS ]; |
---|
73 | |
---|
74 | api->pending_events = EVENT_SETS_NONE_PENDING; |
---|
75 | |
---|
76 | _ASR_Initialize( &api->Signal ); |
---|
77 | } |
---|
78 | |
---|
79 | /*PAGE |
---|
80 | * |
---|
81 | * _RTEMS_tasks_Delete_extension |
---|
82 | * |
---|
83 | * XXX |
---|
84 | */ |
---|
85 | |
---|
86 | User_extensions_routine _RTEMS_tasks_Delete_extension( |
---|
87 | Thread_Control *executing, |
---|
88 | Thread_Control *deleted |
---|
89 | ) |
---|
90 | { |
---|
91 | (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] ); |
---|
92 | |
---|
93 | deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL; |
---|
94 | } |
---|
95 | |
---|
96 | /*PAGE |
---|
97 | * |
---|
98 | * _RTEMS_tasks_Switch_extension |
---|
99 | * |
---|
100 | * XXX |
---|
101 | */ |
---|
102 | |
---|
103 | void _RTEMS_tasks_Switch_extension( |
---|
104 | Thread_Control *executing |
---|
105 | ) |
---|
106 | { |
---|
107 | ISR_Level level; |
---|
108 | RTEMS_API_Control *api; |
---|
109 | ASR_Information *asr; |
---|
110 | rtems_signal_set signal_set; |
---|
111 | Modes_Control prev_mode; |
---|
112 | |
---|
113 | api = executing->API_Extensions[ THREAD_API_RTEMS ]; |
---|
114 | asr = &api->Signal; |
---|
115 | |
---|
116 | _ISR_Disable( level ); |
---|
117 | signal_set = asr->signals_posted; |
---|
118 | asr->signals_posted = 0; |
---|
119 | _ISR_Enable( level ); |
---|
120 | |
---|
121 | |
---|
122 | if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */ |
---|
123 | return; |
---|
124 | |
---|
125 | asr->nest_level += 1; |
---|
126 | rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode ); |
---|
127 | |
---|
128 | (*asr->handler)( signal_set ); |
---|
129 | |
---|
130 | asr->nest_level -= 1; |
---|
131 | rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode ); |
---|
132 | |
---|
133 | } |
---|
134 | |
---|
135 | API_extensions_Control _RTEMS_tasks_API_extensions = { |
---|
136 | { NULL, NULL }, |
---|
137 | NULL, /* predriver */ |
---|
138 | _RTEMS_tasks_Initialize_user_tasks, /* postdriver */ |
---|
139 | _RTEMS_tasks_Switch_extension /* post switch */ |
---|
140 | }; |
---|
141 | |
---|
142 | User_extensions_Control _RTEMS_tasks_User_extensions = { |
---|
143 | { NULL, NULL }, |
---|
144 | { _RTEMS_tasks_Create_extension, /* create */ |
---|
145 | _RTEMS_tasks_Start_extension, /* start */ |
---|
146 | _RTEMS_tasks_Start_extension, /* restart */ |
---|
147 | _RTEMS_tasks_Delete_extension, /* delete */ |
---|
148 | NULL, /* switch */ |
---|
149 | NULL, /* begin */ |
---|
150 | NULL, /* exitted */ |
---|
151 | NULL /* fatal */ |
---|
152 | } |
---|
153 | }; |
---|
154 | |
---|
155 | /*PAGE |
---|
156 | * |
---|
157 | * _RTEMS_tasks_Manager_initialization |
---|
158 | * |
---|
159 | * This routine initializes all Task Manager related data structures. |
---|
160 | * |
---|
161 | * Input parameters: |
---|
162 | * maximum_tasks - number of tasks to initialize |
---|
163 | * |
---|
164 | * Output parameters: NONE |
---|
165 | */ |
---|
166 | |
---|
167 | void _RTEMS_tasks_Manager_initialization( |
---|
168 | unsigned32 maximum_tasks, |
---|
169 | unsigned32 number_of_initialization_tasks, |
---|
170 | rtems_initialization_tasks_table *user_tasks |
---|
171 | ) |
---|
172 | { |
---|
173 | |
---|
174 | _RTEMS_tasks_Number_of_initialization_tasks = number_of_initialization_tasks; |
---|
175 | _RTEMS_tasks_User_initialization_tasks = user_tasks; |
---|
176 | |
---|
177 | /* |
---|
178 | * There may not be any RTEMS initialization tasks configured. |
---|
179 | */ |
---|
180 | |
---|
181 | #if 0 |
---|
182 | if ( user_tasks == NULL || number_of_initialization_tasks == 0 ) |
---|
183 | _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, TRUE, RTEMS_TOO_MANY ); |
---|
184 | #endif |
---|
185 | |
---|
186 | _Objects_Initialize_information( |
---|
187 | &_RTEMS_tasks_Information, |
---|
188 | OBJECTS_RTEMS_TASKS, |
---|
189 | TRUE, |
---|
190 | maximum_tasks, |
---|
191 | sizeof( Thread_Control ), |
---|
192 | FALSE, |
---|
193 | RTEMS_MAXIMUM_NAME_LENGTH, |
---|
194 | TRUE |
---|
195 | ); |
---|
196 | |
---|
197 | /* |
---|
198 | * Add all the extensions for this API |
---|
199 | */ |
---|
200 | |
---|
201 | _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions ); |
---|
202 | |
---|
203 | _API_extensions_Add( &_RTEMS_tasks_API_extensions ); |
---|
204 | |
---|
205 | /* |
---|
206 | * Register the MP Process Packet routine. |
---|
207 | */ |
---|
208 | |
---|
209 | #if defined(RTEMS_MULTIPROCESSING) |
---|
210 | _MPCI_Register_packet_processor( |
---|
211 | MP_PACKET_TASKS, |
---|
212 | _RTEMS_tasks_MP_Process_packet |
---|
213 | ); |
---|
214 | #endif |
---|
215 | |
---|
216 | } |
---|
217 | |
---|