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 | System initialization errors are fatal. See :ref:`internal_errors`. |
---|
81 | |
---|
82 | Operations |
---|
83 | ========== |
---|
84 | |
---|
85 | Initializing RTEMS |
---|
86 | ------------------ |
---|
87 | |
---|
88 | The Initialization Manager ``rtems_initialize_executive`` directives is called |
---|
89 | by the ``boot_card`` routine. The ``boot_card`` routine is invoked by the |
---|
90 | Board Support Package once a basic C run-time environment is set up. This |
---|
91 | consists of |
---|
92 | |
---|
93 | - a valid and accessible text section, read-only data, read-write data and |
---|
94 | zero-initialized data, |
---|
95 | |
---|
96 | - an initialization stack large enough to initialize the rest of the Board |
---|
97 | Support Package, RTEMS and the device drivers, |
---|
98 | |
---|
99 | - all registers and components mandated by Application Binary Interface, and |
---|
100 | |
---|
101 | - disabled interrupts. |
---|
102 | |
---|
103 | The ``rtems_initialize_executive`` directive uses a system initialization |
---|
104 | linker set to initialize only those parts of the overall RTEMS feature set that |
---|
105 | is necessary for a particular application. See :ref:`Linker Sets`. Each RTEMS |
---|
106 | feature used the application may optionally register an initialization handler. |
---|
107 | The system initialization API is available via``#included <rtems/sysinit.h>``. |
---|
108 | |
---|
109 | A list of all initialization steps follows. Some steps are optional depending |
---|
110 | on the requested feature set of the application. The initialization steps are |
---|
111 | execute in the order presented here. |
---|
112 | |
---|
113 | ``RTEMS_SYSINIT_BSP_WORK_AREAS`` |
---|
114 | The work areas consisting of C Program Heap and the RTEMS Workspace are |
---|
115 | initialized by the Board Support Package. This step is mandatory. |
---|
116 | |
---|
117 | ``RTEMS_SYSINIT_BSP_START`` |
---|
118 | Basic initialization step provided by the Board Support Package. This step |
---|
119 | is mandatory. |
---|
120 | |
---|
121 | ``RTEMS_SYSINIT_DATA_STRUCTURES`` |
---|
122 | This directive is called when the Board Support Package has completed its |
---|
123 | basic initialization and allows RTEMS to initialize the application |
---|
124 | environment based upon the information in the Configuration Table, User |
---|
125 | Initialization Tasks Table, Device Driver Table, User Extension Table, |
---|
126 | Multiprocessor Configuration Table, and the Multiprocessor Communications |
---|
127 | Interface (MPCI) Table. |
---|
128 | |
---|
129 | ``RTEMS_SYSINIT_BSP_LIBC`` |
---|
130 | Depending on the application configuration the IO library and root |
---|
131 | filesystem is initialized. This step is mandatory. |
---|
132 | |
---|
133 | ``RTEMS_SYSINIT_BEFORE_DRIVERS`` |
---|
134 | This directive performs initialization that must occur between basis RTEMS |
---|
135 | data structure initialization and device driver initialization. In |
---|
136 | particular, in a multiprocessor configuration, this directive will create |
---|
137 | the MPCI Server Task. |
---|
138 | |
---|
139 | ``RTEMS_SYSINIT_BSP_PRE_DRIVERS`` |
---|
140 | Initialization step performed right before device drivers are initialized |
---|
141 | provided by the Board Support Package. This step is mandatory. |
---|
142 | |
---|
143 | ``RTEMS_SYSINIT_DEVICE_DRIVERS`` |
---|
144 | This step initializes all statically configured device drivers and performs |
---|
145 | all RTEMS initialization which requires device drivers to be initialized. |
---|
146 | This step is mandatory. In a multiprocessor configuration, this service |
---|
147 | will initialize the Multiprocessor Communications Interface (MPCI) and |
---|
148 | synchronize with the other nodes in the system. |
---|
149 | |
---|
150 | ``RTEMS_SYSINIT_BSP_POST_DRIVERS`` |
---|
151 | Initialization step performed right after device drivers are initialized |
---|
152 | provided by the Board Support Package. This step is mandatory. |
---|
153 | |
---|
154 | The final action of the ``rtems_initialize_executive`` directive is to start |
---|
155 | multitasking. RTEMS does not return to the initialization context and the |
---|
156 | initialization stack may be re-used for interrupt processing. |
---|
157 | |
---|
158 | Many of RTEMS actions during initialization are based upon the contents of the |
---|
159 | Configuration Table. For more information regarding the format and contents of |
---|
160 | this table, please refer to the chapter :ref:`Configuring a System`. |
---|
161 | |
---|
162 | The final action in the initialization sequence is the initiation of |
---|
163 | multitasking. When the scheduler and dispatcher are enabled, the highest |
---|
164 | priority, ready task will be dispatched to run. Control will not be returned |
---|
165 | to the Board Support Package after multitasking is enabled. The initialization |
---|
166 | stack may be re-used for interrupt processing. |
---|
167 | |
---|
168 | Shutting Down RTEMS |
---|
169 | ------------------- |
---|
170 | |
---|
171 | The ``rtems_shutdown_executive`` directive is invoked by the application to end |
---|
172 | multitasking and terminate the system. |
---|
173 | |
---|
174 | Directives |
---|
175 | ========== |
---|
176 | |
---|
177 | This section details the Initialization Manager's directives. A subsection is |
---|
178 | dedicated to each of this manager's directives and describes the calling |
---|
179 | sequence, related constants, usage, and status codes. |
---|
180 | |
---|
181 | .. raw:: latex |
---|
182 | |
---|
183 | \clearpage |
---|
184 | |
---|
185 | .. _rtems_initialize_executive: |
---|
186 | |
---|
187 | INITIALIZE_EXECUTIVE - Initialize RTEMS |
---|
188 | --------------------------------------- |
---|
189 | .. index:: initialize RTEMS |
---|
190 | .. index:: start multitasking |
---|
191 | |
---|
192 | .. index:: rtems_initialize_executive |
---|
193 | CALLING SEQUENCE: |
---|
194 | .. code-block:: c |
---|
195 | |
---|
196 | void rtems_initialize_executive(void); |
---|
197 | |
---|
198 | DIRECTIVE STATUS CODES: |
---|
199 | NONE |
---|
200 | |
---|
201 | DESCRIPTION: |
---|
202 | Iterates through the system initialization linker set and invokes the |
---|
203 | registered handlers. The final step is to start multitasking. |
---|
204 | |
---|
205 | NOTES: |
---|
206 | This directive should be called by ``boot_card`` only. |
---|
207 | |
---|
208 | This directive *does not return* to the caller. Errors in the |
---|
209 | initialization sequence are usually fatal and lead to a system termination. |
---|
210 | |
---|
211 | .. raw:: latex |
---|
212 | |
---|
213 | \clearpage |
---|
214 | |
---|
215 | .. _rtems_shutdown_executive: |
---|
216 | |
---|
217 | SHUTDOWN_EXECUTIVE - Shutdown RTEMS |
---|
218 | ----------------------------------- |
---|
219 | .. index:: shutdown RTEMS |
---|
220 | |
---|
221 | .. index:: rtems_shutdown_executive |
---|
222 | CALLING SEQUENCE: |
---|
223 | .. code-block:: c |
---|
224 | |
---|
225 | void rtems_shutdown_executive( |
---|
226 | uint32_t result |
---|
227 | ); |
---|
228 | |
---|
229 | DIRECTIVE STATUS CODES: |
---|
230 | NONE |
---|
231 | |
---|
232 | DESCRIPTION: |
---|
233 | This directive is called when the application wishes to shutdown RTEMS. |
---|
234 | The system is terminated with a fatal source of ``RTEMS_FATAL_SOURCE_EXIT`` |
---|
235 | and the specified ``result`` code. |
---|
236 | |
---|
237 | NOTES: |
---|
238 | This directive *must* be the last RTEMS directive invoked by an application |
---|
239 | and it *does not return* to the caller. |
---|
240 | |
---|
241 | This directive may be called any time. |
---|