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_executive} - Initialize RTEMS |
---|
20 | @item @code{@value{DIRPREFIX}shutdown_executive} - Shutdown RTEMS |
---|
21 | @end itemize |
---|
22 | |
---|
23 | @section Background |
---|
24 | |
---|
25 | @subsection Initialization Tasks |
---|
26 | |
---|
27 | @cindex initialization tasks |
---|
28 | |
---|
29 | Initialization task(s) are the mechanism by which |
---|
30 | RTEMS transfers initial control to the user's application. |
---|
31 | Initialization tasks differ from other application tasks in that |
---|
32 | they are defined in the User Initialization Tasks Table and |
---|
33 | automatically created and started by RTEMS as part of its |
---|
34 | initialization sequence. Since the initialization tasks are |
---|
35 | scheduled using the same algorithm as all other RTEMS tasks, |
---|
36 | they must be configured at a priority and mode which will ensure |
---|
37 | that they will complete execution before other application tasks |
---|
38 | execute. Although there is no upper limit on the number of |
---|
39 | initialization tasks, an application is required to define at |
---|
40 | least one. |
---|
41 | |
---|
42 | A typical initialization task will create and start |
---|
43 | the static set of application tasks. It may also create any |
---|
44 | other objects used by the application. Initialization tasks |
---|
45 | which only perform initialization should delete themselves upon |
---|
46 | completion to free resources for other tasks. Initialization |
---|
47 | tasks may transform themselves into a "normal" application task. |
---|
48 | This transformation typically involves changing priority and |
---|
49 | execution mode. RTEMS does not automatically delete the |
---|
50 | initialization tasks. |
---|
51 | |
---|
52 | @subsection System Initialization |
---|
53 | |
---|
54 | System Initialization begins with board reset and continues |
---|
55 | through RTEMS initialization, initialization of all device |
---|
56 | drivers, and eventually a context switch to the first user |
---|
57 | task. Remember, that interrupts are disabled during |
---|
58 | initialization and the @i{initialization context} is not |
---|
59 | a task in any sense and the user should be very careful |
---|
60 | during initialization. |
---|
61 | |
---|
62 | The BSP must ensure that the there is enough stack |
---|
63 | space reserved for the initialization context to |
---|
64 | successfully execute the initialization routines for |
---|
65 | all device drivers and, in multiprocessor configurations, the |
---|
66 | Multiprocessor Communications Interface Layer initialization |
---|
67 | routine. |
---|
68 | |
---|
69 | @subsection The Idle Task |
---|
70 | |
---|
71 | The Idle Task is the lowest priority task in a system |
---|
72 | and executes only when no other task is ready to execute. This |
---|
73 | default implementation of this task consists of an infinite |
---|
74 | loop. RTEMS allows the Idle Task body to be replaced by a CPU |
---|
75 | specific implementation, a BSP specific implementation or an |
---|
76 | application specific implementation. |
---|
77 | |
---|
78 | The Idle Task is preemptible and @b{WILL} be preempted when |
---|
79 | any other task is made ready to execute. This characteristic is |
---|
80 | critical to the overall behavior of any application. |
---|
81 | |
---|
82 | @subsection Initialization Manager Failure |
---|
83 | |
---|
84 | The @code{@value{DIRPREFIX}fatal_error_occurred} directive will |
---|
85 | be invoked from @code{@value{DIRPREFIX}initialize_executive} |
---|
86 | for any of the following reasons: |
---|
87 | |
---|
88 | @itemize @bullet |
---|
89 | @item If either the Configuration Table or the CPU Dependent |
---|
90 | Information Table is not provided. |
---|
91 | |
---|
92 | @item If the starting address of the RTEMS RAM Workspace, |
---|
93 | supplied by the application in the Configuration Table, is NULL |
---|
94 | or is not aligned on a four-byte boundary. |
---|
95 | |
---|
96 | @item If the size of the RTEMS RAM Workspace is not large |
---|
97 | enough to initialize and configure the system. |
---|
98 | |
---|
99 | @item If the interrupt stack size specified is too small. |
---|
100 | |
---|
101 | @item If multiprocessing is configured and the node entry in |
---|
102 | the Multiprocessor Configuration Table is not between one and |
---|
103 | the maximum_nodes entry. |
---|
104 | |
---|
105 | @item If a multiprocessor system is being configured and no |
---|
106 | Multiprocessor Communications Interface is specified. |
---|
107 | |
---|
108 | @item If no user initialization tasks are configured. At |
---|
109 | least one initialization task must be configured to allow RTEMS |
---|
110 | to pass control to the application at the end of the executive |
---|
111 | initialization sequence. |
---|
112 | |
---|
113 | @item If any of the user initialization tasks cannot be |
---|
114 | created or started successfully. |
---|
115 | @end itemize |
---|
116 | |
---|
117 | A discussion of RTEMS actions when a fatal error occurs |
---|
118 | may be found @ref{Fatal Error Manager Announcing a Fatal Error}. |
---|
119 | |
---|
120 | |
---|
121 | @section Operations |
---|
122 | |
---|
123 | @subsection Initializing RTEMS |
---|
124 | |
---|
125 | The Initialization Manager @code{@value{DIRPREFIX}initialize_executive} |
---|
126 | directives is called by the @code{boot_card} routine. The @code{boot_card} |
---|
127 | routine is invoked by the Board Support Package once a basic C run-time |
---|
128 | environment is set up. This consists of |
---|
129 | |
---|
130 | @itemize @bullet |
---|
131 | @item a valid and accessible text section, read-only data, read-write data and |
---|
132 | zero-initialized data, |
---|
133 | @item an initialization stack large enough to initialize the rest of the Board |
---|
134 | Support Package, RTEMS and the device drivers, |
---|
135 | @item all registers and components mandated by Application Binary Interface, and |
---|
136 | @item disabled interrupts. |
---|
137 | @end itemize |
---|
138 | |
---|
139 | The @code{@value{DIRPREFIX}initialize_executive} directive uses a system |
---|
140 | initialization linker set to initialize only those parts of the overall RTEMS |
---|
141 | feature set that is necessary for a particular application. @xref{Linker |
---|
142 | Sets}. Each RTEMS feature used the application may optionally register an |
---|
143 | initialization handler. The system initialization API is available via |
---|
144 | @code{#included <rtems/sysinit.h>}. |
---|
145 | |
---|
146 | A list of all initialization steps follows. Some steps are optional depending |
---|
147 | on the requested feature set of the application. The initialization steps are |
---|
148 | execute in the order presented here. |
---|
149 | |
---|
150 | @table @dfn |
---|
151 | |
---|
152 | @item RTEMS_SYSINIT_BSP_WORK_AREAS |
---|
153 | The work areas consisting of C Program Heap and the RTEMS Workspace are |
---|
154 | initialized by the Board Support Package. This step is mandatory. |
---|
155 | |
---|
156 | @item RTEMS_SYSINIT_BSP_START |
---|
157 | Basic initialization step provided by the Board Support Package. This step is |
---|
158 | mandatory. |
---|
159 | |
---|
160 | @item RTEMS_SYSINIT_INITIAL_EXTENSIONS |
---|
161 | Initializes the initial extensions if at least one is configured by the Board |
---|
162 | Support Package or application. |
---|
163 | |
---|
164 | @item RTEMS_SYSINIT_DATA_STRUCTURES |
---|
165 | This directive is called when the Board Support Package has completed its basic |
---|
166 | initialization and allows RTEMS to initialize the application environment based |
---|
167 | upon the information in the Configuration Table, User Initialization Tasks |
---|
168 | Table, Device Driver Table, Multiprocessor Configuration Table, and the |
---|
169 | Multiprocessor Communications Interface (MPCI) Table. |
---|
170 | |
---|
171 | @item RTEMS_SYSINIT_USER_EXTENSIONS |
---|
172 | Initializes the @ref{User Extensions Manager} in case it is used by the |
---|
173 | application. |
---|
174 | |
---|
175 | @item RTEMS_SYSINIT_CPU_SET |
---|
176 | Initializes the global CPU set on SMP configurations in case the application |
---|
177 | uses this information. |
---|
178 | |
---|
179 | @item RTEMS_SYSINIT_BSP_LIBC |
---|
180 | Depending on the application configuration the IO library and root filesystem |
---|
181 | is initialized. This step is mandatory. |
---|
182 | |
---|
183 | @item RTEMS_SYSINIT_BEFORE_DRIVERS |
---|
184 | This directive performs initialization that must occur between basis RTEMS data |
---|
185 | structure initialization and device driver initialization. In particular, in a |
---|
186 | multiprocessor configuration, this directive will create the MPCI Server Task. |
---|
187 | |
---|
188 | @item RTEMS_SYSINIT_BSP_PRE_DRIVERS |
---|
189 | Initialization step performed right before device drivers are initialized |
---|
190 | provided by the Board Support Package. This step is mandatory. |
---|
191 | |
---|
192 | @item RTEMS_SYSINIT_DEVICE_DRIVERS |
---|
193 | This step initializes all statically configured device drivers and performs all |
---|
194 | RTEMS initialization which requires device drivers to be initialized. This |
---|
195 | step is mandatory. |
---|
196 | |
---|
197 | In a multiprocessor configuration, this service will initialize the |
---|
198 | Multiprocessor Communications Interface (MPCI) and synchronize with the other |
---|
199 | nodes in the system. |
---|
200 | |
---|
201 | @item RTEMS_SYSINIT_BSP_POST_DRIVERS |
---|
202 | Initialization step performed right after device drivers are initialized |
---|
203 | provided by the Board Support Package. This step is mandatory. |
---|
204 | |
---|
205 | @end table |
---|
206 | |
---|
207 | The final action of the @code{@value{DIRPREFIX}initialize_executive} directive |
---|
208 | is to start multitasking. RTEMS does not return to the initialization context |
---|
209 | and the initialization stack may be re-used for interrupt processing. |
---|
210 | |
---|
211 | Many of RTEMS actions during initialization are based upon |
---|
212 | the contents of the Configuration Table. For more information |
---|
213 | regarding the format and contents of this table, please refer |
---|
214 | to the chapter @ref{Configuring a System}. |
---|
215 | |
---|
216 | The final action in the initialization sequence is the |
---|
217 | initiation of multitasking. When the scheduler and dispatcher |
---|
218 | are enabled, the highest priority, ready task will be dispatched |
---|
219 | to run. Control will not be returned to the Board Support |
---|
220 | Package after multitasking is enabled. The initialization stack may be re-used |
---|
221 | for interrupt processing. |
---|
222 | |
---|
223 | @subsection Shutting Down RTEMS |
---|
224 | |
---|
225 | The @code{@value{DIRPREFIX}shutdown_executive} directive is invoked by the |
---|
226 | application to end multitasking and terminate the system. |
---|
227 | |
---|
228 | @section Directives |
---|
229 | |
---|
230 | This section details the Initialization Manager's |
---|
231 | directives. A subsection is dedicated to each of this manager's |
---|
232 | directives and describes the calling sequence, related |
---|
233 | constants, usage, and status codes. |
---|
234 | |
---|
235 | @page |
---|
236 | @subsection INITIALIZE_EXECUTIVE - Initialize RTEMS |
---|
237 | |
---|
238 | @cindex initialize RTEMS |
---|
239 | @cindex start multitasking |
---|
240 | |
---|
241 | @subheading CALLING SEQUENCE: |
---|
242 | |
---|
243 | @ifset is-C |
---|
244 | @findex rtems_initialize_executive |
---|
245 | @example |
---|
246 | void rtems_initialize_executive(void); |
---|
247 | @end example |
---|
248 | @end ifset |
---|
249 | |
---|
250 | @ifset is-Ada |
---|
251 | @example |
---|
252 | NOT SUPPORTED FROM Ada BINDING |
---|
253 | @end example |
---|
254 | @end ifset |
---|
255 | |
---|
256 | @subheading DIRECTIVE STATUS CODES: |
---|
257 | |
---|
258 | NONE |
---|
259 | |
---|
260 | @subheading DESCRIPTION: |
---|
261 | |
---|
262 | Iterates through the system initialization linker set and invokes the |
---|
263 | registered handlers. The final step is to start multitasking. |
---|
264 | |
---|
265 | @subheading NOTES: |
---|
266 | |
---|
267 | This directive should be called by @code{boot_card} only. |
---|
268 | |
---|
269 | This directive @b{does not return} to the caller. Errors in the initialization |
---|
270 | sequence are usually fatal and lead to a system termination. |
---|
271 | |
---|
272 | @page |
---|
273 | @subsection SHUTDOWN_EXECUTIVE - Shutdown RTEMS |
---|
274 | |
---|
275 | @cindex shutdown RTEMS |
---|
276 | |
---|
277 | @subheading CALLING SEQUENCE: |
---|
278 | |
---|
279 | @ifset is-C |
---|
280 | @findex rtems_shutdown_executive |
---|
281 | @example |
---|
282 | void rtems_shutdown_executive( |
---|
283 | uint32_t result |
---|
284 | ); |
---|
285 | @end example |
---|
286 | @end ifset |
---|
287 | |
---|
288 | @ifset is-Ada |
---|
289 | @example |
---|
290 | procedure Shutdown_Executive( |
---|
291 | Status : in RTEMS.Unsigned32 |
---|
292 | ); |
---|
293 | @end example |
---|
294 | @end ifset |
---|
295 | |
---|
296 | @subheading DIRECTIVE STATUS CODES: |
---|
297 | |
---|
298 | NONE |
---|
299 | |
---|
300 | @subheading DESCRIPTION: |
---|
301 | |
---|
302 | This directive is called when the application wishes to shutdown RTEMS. The |
---|
303 | system is terminated with a fatal source of @code{RTEMS_FATAL_SOURCE_EXIT} and |
---|
304 | the specified @code{result} code. |
---|
305 | |
---|
306 | @subheading NOTES: |
---|
307 | |
---|
308 | This directive @b{must} be the last RTEMS directive |
---|
309 | invoked by an application and it @b{does not return} to the caller. |
---|
310 | |
---|
311 | This directive may be called any time. |
---|