1 | @c |
---|
2 | @c COPYRIGHT (c) 1988-2008. |
---|
3 | @c On-Line Applications Research Corporation (OAR). |
---|
4 | @c All rights reserved. |
---|
5 | @c |
---|
6 | @c $Id$ |
---|
7 | @c |
---|
8 | |
---|
9 | @chapter Initialization Manager |
---|
10 | |
---|
11 | @section Introduction |
---|
12 | |
---|
13 | The Initialization Manager is responsible for |
---|
14 | initiating and shutting down RTEMS. Initiating RTEMS involves |
---|
15 | creating and starting all configured initialization tasks, and |
---|
16 | for invoking the initialization routine for each user-supplied |
---|
17 | device driver. In a multiprocessor configuration, this manager |
---|
18 | also initializes the interprocessor communications layer. The |
---|
19 | directives provided by the Initialization Manager are: |
---|
20 | |
---|
21 | @itemize @bullet |
---|
22 | @item @code{@value{DIRPREFIX}initialize_data_structures} - Initialize RTEMS Data Structures |
---|
23 | @item @code{@value{DIRPREFIX}initialize_before_drivers} - Perform Initialization Before Device Drivers |
---|
24 | @item @code{@value{DIRPREFIX}initialize_device_drivers} - Initialize Device Drivers |
---|
25 | @item @code{@value{DIRPREFIX}initialize_start_multitasking} - Complete Initialization and Start Multitasking |
---|
26 | @item @code{@value{DIRPREFIX}shutdown_executive} - Shutdown RTEMS |
---|
27 | @end itemize |
---|
28 | |
---|
29 | @section Background |
---|
30 | |
---|
31 | @subsection Initialization Tasks |
---|
32 | |
---|
33 | @cindex initialization tasks |
---|
34 | |
---|
35 | Initialization task(s) are the mechanism by which |
---|
36 | RTEMS transfers initial control to the user's application. |
---|
37 | Initialization tasks differ from other application tasks in that |
---|
38 | they are defined in the User Initialization Tasks Table and |
---|
39 | automatically created and started by RTEMS as part of its |
---|
40 | initialization sequence. Since the initialization tasks are |
---|
41 | scheduled using the same algorithm as all other RTEMS tasks, |
---|
42 | they must be configured at a priority and mode which will ensure |
---|
43 | that they will complete execution before other application tasks |
---|
44 | execute. Although there is no upper limit on the number of |
---|
45 | initialization tasks, an application is required to define at |
---|
46 | least one. |
---|
47 | |
---|
48 | A typical initialization task will create and start |
---|
49 | the static set of application tasks. It may also create any |
---|
50 | other objects used by the application. Initialization tasks |
---|
51 | which only perform initialization should delete themselves upon |
---|
52 | completion to free resources for other tasks. Initialization |
---|
53 | tasks may transform themselves into a "normal" application task. |
---|
54 | This transformation typically involves changing priority and |
---|
55 | execution mode. RTEMS does not automatically delete the |
---|
56 | initialization tasks. |
---|
57 | |
---|
58 | @subsection System Initialization |
---|
59 | |
---|
60 | System Initialization begins with board reset and continues |
---|
61 | through RTEMS initialization, initialization of all device |
---|
62 | drivers, and eventually a context switch to the first user |
---|
63 | task. Remember, that interrupts are disabled during |
---|
64 | initialization and the @i{initialization thread} is not |
---|
65 | a task in any sense and the user should be very careful |
---|
66 | during initialzation. |
---|
67 | |
---|
68 | The BSP must ensure that the there is enough stack |
---|
69 | space reserved for the initialization "thread" to |
---|
70 | successfully execute the initialization routines for |
---|
71 | all device drivers and, in multiprocessor configurations, the |
---|
72 | Multiprocessor Communications Interface Layer initialization |
---|
73 | routine. |
---|
74 | |
---|
75 | @subsection The Idle Task |
---|
76 | |
---|
77 | The Idle Task is the lowest priority task in a system |
---|
78 | and executes only when no other task is ready to execute. This |
---|
79 | default implementation of this task consists of an infinite |
---|
80 | loop. RTEMS allows the Idle Task body to be replaced by a CPU |
---|
81 | specific implementation, a BSP specific implementation or an |
---|
82 | application specific implementation. |
---|
83 | |
---|
84 | The Idle Task is preemptible and @b{WILL} be preempted when |
---|
85 | any other task is made ready to execute. This characteristic is |
---|
86 | critical to the overall behavior of any application. |
---|
87 | |
---|
88 | @subsection Initialization Manager Failure |
---|
89 | |
---|
90 | The @code{@value{DIRPREFIX}fatal_error_occurred} directive will |
---|
91 | be invoked from @code{@value{DIRPREFIX}initialize_executive} |
---|
92 | for any of the following reasons: |
---|
93 | |
---|
94 | @itemize @bullet |
---|
95 | @item If either the Configuration Table or the CPU Dependent |
---|
96 | Information Table is not provided. |
---|
97 | |
---|
98 | @item If the starting address of the RTEMS RAM Workspace, |
---|
99 | supplied by the application in the Configuration Table, is NULL |
---|
100 | or is not aligned on a four-byte boundary. |
---|
101 | |
---|
102 | @item If the size of the RTEMS RAM Workspace is not large |
---|
103 | enough to initialize and configure the system. |
---|
104 | |
---|
105 | @item If the interrupt stack size specified is too small. |
---|
106 | |
---|
107 | @item If multiprocessing is configured and the node entry in |
---|
108 | the Multiprocessor Configuration Table is not between one and |
---|
109 | the maximum_nodes entry. |
---|
110 | |
---|
111 | @item If a multiprocessor system is being configured and no |
---|
112 | Multiprocessor Communications Interface is specified. |
---|
113 | |
---|
114 | @item If no user initialization tasks are configured. At |
---|
115 | least one initialization task must be configured to allow RTEMS |
---|
116 | to pass control to the application at the end of the executive |
---|
117 | initialization sequence. |
---|
118 | |
---|
119 | @item If any of the user initialization tasks cannot be |
---|
120 | created or started successfully. |
---|
121 | @end itemize |
---|
122 | |
---|
123 | A discussion of RTEMS actions when a fatal error occurs |
---|
124 | may be found @ref{Fatal Error Manager Announcing a Fatal Error}. |
---|
125 | |
---|
126 | |
---|
127 | @section Operations |
---|
128 | |
---|
129 | @subsection Initializing RTEMS |
---|
130 | |
---|
131 | The Initialization Manager directives are called by the |
---|
132 | Board Support Package framework as part of its initialization |
---|
133 | sequence. RTEMS assumes that the Board Support Package |
---|
134 | successfully completed its initialization activities. These |
---|
135 | directives initialize RTEMS by performing the following actions: |
---|
136 | |
---|
137 | @itemize @bullet |
---|
138 | @item Initializing internal RTEMS variables; |
---|
139 | @item Allocating system resources; |
---|
140 | @item Creating and starting the Idle Task; |
---|
141 | @item Initialize all device drivers; |
---|
142 | @item Creating and starting the user initialization task(s); and |
---|
143 | @item Initiating multitasking. |
---|
144 | @end itemize |
---|
145 | |
---|
146 | The initialization directives MUST be called in the proper |
---|
147 | sequence before any blocking directives may be used. The services |
---|
148 | in this manager should be invoked just once per application |
---|
149 | and in precisely the following order: |
---|
150 | |
---|
151 | @itemize @bullet |
---|
152 | @item @code{@value{DIRPREFIX}initialize_data_structures} |
---|
153 | @item @code{@value{DIRPREFIX}initialize_before_drivers} |
---|
154 | @item @code{@value{DIRPREFIX}initialize_device_drivers} |
---|
155 | @item @code{@value{DIRPREFIX}initialize_start_multitasking} |
---|
156 | @end itemize |
---|
157 | |
---|
158 | It is recommended that the Board Support Package use the |
---|
159 | provided framework which will invoke these services as |
---|
160 | part of the executing the function @code{boot_card} in the |
---|
161 | file @code{c/src/lib/libbsp/shared/bootcard.c}. This |
---|
162 | framework will also assist in allocating memory to the |
---|
163 | RTEMS Workspace and C Program Heap and initializing the |
---|
164 | C Library. |
---|
165 | |
---|
166 | The effect of calling any blocking RTEMS directives before |
---|
167 | @code{@value{DIRPREFIX}initialize_start_multitasking} |
---|
168 | is unpredictable but guaranteed to be bad. Afer the |
---|
169 | directive @code{@value{DIRPREFIX}initialize_data_structures} |
---|
170 | is invoked, it is permissible to allocate RTEMS objects and |
---|
171 | perform non-blocking operations. But the user should be |
---|
172 | distinctly aware that multitasking is not available yet |
---|
173 | and they are @b{NOT} executing in a task context. |
---|
174 | |
---|
175 | Many of RTEMS actions during initialization are based upon |
---|
176 | the contents of the Configuration Table. For more information |
---|
177 | regarding the format and contents of this table, please refer |
---|
178 | to the chapter @ref{Configuring a System}. |
---|
179 | |
---|
180 | The final step in the initialization sequence is the |
---|
181 | initiation of multitasking. When the scheduler and dispatcher |
---|
182 | are enabled, the highest priority, ready task will be dispatched |
---|
183 | to run. Control will not be returned to the Board Support |
---|
184 | Package after multitasking is enabled until the |
---|
185 | @code{@value{DIRPREFIX}shutdown_executive} directive is called. |
---|
186 | This directive is called as a side-effect of POSIX calls |
---|
187 | including @code{exit}. |
---|
188 | |
---|
189 | @subsection Shutting Down RTEMS |
---|
190 | |
---|
191 | The @code{@value{DIRPREFIX}shutdown_executive} directive is invoked by the |
---|
192 | application to end multitasking and return control to the board |
---|
193 | support package. The board support package resumes execution at |
---|
194 | the code immediately following the invocation of the |
---|
195 | @code{@value{DIRPREFIX}initialize_start_multitasking} directive. |
---|
196 | |
---|
197 | @section Directives |
---|
198 | |
---|
199 | This section details the Initialization Manager's |
---|
200 | directives. A subsection is dedicated to each of this manager's |
---|
201 | directives and describes the calling sequence, related |
---|
202 | constants, usage, and status codes. |
---|
203 | |
---|
204 | @page |
---|
205 | @subsection INITIALIZE_DATA_STRUCTURES - Initialize RTEMS Data Structures |
---|
206 | |
---|
207 | @cindex initialize RTEMS data structures |
---|
208 | |
---|
209 | @subheading CALLING SEQUENCE: |
---|
210 | |
---|
211 | @ifset is-C |
---|
212 | @findex rtems_initialize_data_structures |
---|
213 | @example |
---|
214 | void rtems_initialize_data_structures( |
---|
215 | rtems_configuration_table *configuration_table |
---|
216 | ); |
---|
217 | @end example |
---|
218 | @end ifset |
---|
219 | |
---|
220 | @ifset is-Ada |
---|
221 | @example |
---|
222 | NOT SUPPORTED FROM Ada BINDING |
---|
223 | @end example |
---|
224 | @end ifset |
---|
225 | |
---|
226 | @subheading DIRECTIVE STATUS CODES: |
---|
227 | |
---|
228 | NONE |
---|
229 | |
---|
230 | @subheading DESCRIPTION: |
---|
231 | |
---|
232 | This directive is called when the Board Support |
---|
233 | Package has completed its basic initialization and |
---|
234 | allows RTEMS to initialize the application environment based upon the |
---|
235 | information in the Configuration Table, User Initialization |
---|
236 | Tasks Table, Device Driver Table, User Extension Table, |
---|
237 | Multiprocessor Configuration Table, and the Multiprocessor |
---|
238 | Communications Interface (MPCI) Table. This directive returns |
---|
239 | to the caller after completing the basic RTEMS initialization. |
---|
240 | |
---|
241 | @subheading NOTES: |
---|
242 | |
---|
243 | The Initialization Manager directives must be used in the |
---|
244 | proper sequence and invokved only once in the life of an application. |
---|
245 | |
---|
246 | This directive must be invoked with interrupts disabled. |
---|
247 | Interrupts should be disabled as early as possible in |
---|
248 | the initialization sequence and remain disabled until |
---|
249 | the first context switch. |
---|
250 | |
---|
251 | @page |
---|
252 | @subsection INITIALIZE_BEFORE_DRIVERS - Perform Initialization Before Device Drivers |
---|
253 | |
---|
254 | @cindex initialize RTEMS before device drivers |
---|
255 | |
---|
256 | @subheading CALLING SEQUENCE: |
---|
257 | |
---|
258 | @ifset is-C |
---|
259 | @findex rtems_initialize_before_drivers |
---|
260 | @example |
---|
261 | void rtems_initialize_before_drivers(void); |
---|
262 | @end example |
---|
263 | @end ifset |
---|
264 | |
---|
265 | @ifset is-Ada |
---|
266 | @example |
---|
267 | NOT SUPPORTED FROM Ada BINDING |
---|
268 | @end example |
---|
269 | @end ifset |
---|
270 | |
---|
271 | @subheading DIRECTIVE STATUS CODES: |
---|
272 | |
---|
273 | NONE |
---|
274 | |
---|
275 | @subheading DESCRIPTION: |
---|
276 | |
---|
277 | This directive is called by the Board Support Package as the |
---|
278 | second step in initializing RTEMS. This directive performs |
---|
279 | initialization that must occur between basis RTEMS data structure |
---|
280 | initialization and device driver initialization. In particular, |
---|
281 | in a multiprocessor configuration, this directive will create the |
---|
282 | MPCI Server Task. This directive returns to the caller after |
---|
283 | completing the basic RTEMS initialization. |
---|
284 | |
---|
285 | @subheading NOTES: |
---|
286 | |
---|
287 | The Initialization Manager directives must be used in the |
---|
288 | proper sequence and invokved only once in the life of an application. |
---|
289 | |
---|
290 | This directive must be invoked with interrupts disabled. |
---|
291 | Interrupts should be disabled as early as possible in |
---|
292 | the initialization sequence and remain disabled until |
---|
293 | the first context switch. |
---|
294 | |
---|
295 | @page |
---|
296 | @subsection INITIALIZE_DEVICE_DRIVERS - Initialize Device Drivers |
---|
297 | |
---|
298 | @cindex initialize device drivers |
---|
299 | |
---|
300 | @subheading CALLING SEQUENCE: |
---|
301 | |
---|
302 | @ifset is-C |
---|
303 | @findex rtems_initialize_device_drivers |
---|
304 | @example |
---|
305 | void rtems_initialize_device_drivers(void); |
---|
306 | @end example |
---|
307 | @end ifset |
---|
308 | |
---|
309 | @ifset is-Ada |
---|
310 | @example |
---|
311 | NOT SUPPORTED FROM Ada BINDING |
---|
312 | @end example |
---|
313 | @end ifset |
---|
314 | |
---|
315 | @subheading DIRECTIVE STATUS CODES: |
---|
316 | |
---|
317 | NONE |
---|
318 | |
---|
319 | @subheading DESCRIPTION: |
---|
320 | |
---|
321 | This directive is called by the Board Support Package as the |
---|
322 | third step in initializing RTEMS. This directive initializes |
---|
323 | all statically configured device drivers and performs all RTEMS |
---|
324 | initialization which requires device drivers to be initialized. |
---|
325 | |
---|
326 | In a multiprocessor configuration, this service will initialize |
---|
327 | the Multiprocessor Communications Interface (MPCI) and synchronize |
---|
328 | with the other nodes in the system. |
---|
329 | |
---|
330 | After this directive is executed, control will be returned to |
---|
331 | the Board Support Package framework. |
---|
332 | |
---|
333 | @subheading NOTES: |
---|
334 | |
---|
335 | The Initialization Manager directives must be used in the |
---|
336 | proper sequence and invokved only once in the life of an application. |
---|
337 | |
---|
338 | This directive must be invoked with interrupts disabled. |
---|
339 | Interrupts should be disabled as early as possible in |
---|
340 | the initialization sequence and remain disabled until |
---|
341 | the first context switch. |
---|
342 | |
---|
343 | @page |
---|
344 | @subsection INITIALIZE_START_MULTITASKING - Complete Initialization and Start Multitasking |
---|
345 | |
---|
346 | @cindex initialize RTEMS |
---|
347 | @cindex start multitasking |
---|
348 | |
---|
349 | @subheading CALLING SEQUENCE: |
---|
350 | |
---|
351 | @ifset is-C |
---|
352 | @findex rtems_initialize_start_multitasking |
---|
353 | @example |
---|
354 | void rtems_initialize_start_multitasking(void); |
---|
355 | @end example |
---|
356 | @end ifset |
---|
357 | |
---|
358 | @ifset is-Ada |
---|
359 | @example |
---|
360 | NOT SUPPORTED FROM Ada BINDING |
---|
361 | @end example |
---|
362 | @end ifset |
---|
363 | |
---|
364 | @subheading DIRECTIVE STATUS CODES: |
---|
365 | |
---|
366 | NONE |
---|
367 | |
---|
368 | @subheading DESCRIPTION: |
---|
369 | |
---|
370 | This directive is called after the other Initialization Manager |
---|
371 | directives have successfully completed. This directive |
---|
372 | initiates multitasking and performs a context switch to |
---|
373 | the first user application task and enables interrupts as |
---|
374 | a side-effect of that context switch. |
---|
375 | |
---|
376 | @subheading NOTES: |
---|
377 | |
---|
378 | This directive @b{DOES NOT RETURN} to the caller until the |
---|
379 | @code{@value{DIRPREFIX}shutdown_executive} is invoked. |
---|
380 | |
---|
381 | This directive causes all nodes in the system to |
---|
382 | verify that certain configuration parameters are the same as |
---|
383 | those of the local node. If an inconsistency is detected, then |
---|
384 | a fatal error is generated. |
---|
385 | |
---|
386 | @page |
---|
387 | @subsection SHUTDOWN_EXECUTIVE - Shutdown RTEMS |
---|
388 | |
---|
389 | @cindex shutdown RTEMS |
---|
390 | |
---|
391 | @subheading CALLING SEQUENCE: |
---|
392 | |
---|
393 | @ifset is-C |
---|
394 | @findex rtems_shutdown_executive |
---|
395 | @example |
---|
396 | void rtems_shutdown_executive( |
---|
397 | uint32_t result |
---|
398 | ); |
---|
399 | @end example |
---|
400 | @end ifset |
---|
401 | |
---|
402 | @ifset is-Ada |
---|
403 | @example |
---|
404 | procedure Shutdown_Executive( |
---|
405 | Status : in RTEMS.Unsigned32 |
---|
406 | ); |
---|
407 | @end example |
---|
408 | @end ifset |
---|
409 | |
---|
410 | @subheading DIRECTIVE STATUS CODES: |
---|
411 | |
---|
412 | NONE |
---|
413 | |
---|
414 | @subheading DESCRIPTION: |
---|
415 | |
---|
416 | This directive is called when the application wishes |
---|
417 | to shutdown RTEMS and return control to the board support |
---|
418 | package. The board support package resumes execution at the |
---|
419 | code immediately following the invocation of the |
---|
420 | @code{@value{DIRPREFIX}initialize_executive} directive. |
---|
421 | |
---|
422 | @subheading NOTES: |
---|
423 | |
---|
424 | This directive MUST be the last RTEMS directive |
---|
425 | invoked by an application and it DOES NOT RETURN to the caller. |
---|
426 | |
---|
427 | This directive should not be invoked until the |
---|
428 | executive has successfully completed initialization. |
---|