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