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