source: rtems-docs/c-user/initialization.rst @ 72a62ad

4.115
Last change on this file since 72a62ad was 72a62ad, checked in by Chris Johns <chrisj@…>, on 11/03/16 at 05:58:08

Rename all manuals with an _ to have a -. It helps released naming of files.

  • Property mode set to 100644
File size: 10.0 KB
Line 
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
7Initialization Manager
8######################
9
10Introduction
11============
12
13The Initialization Manager is responsible for initiating and shutting down
14RTEMS.  Initiating RTEMS involves creating and starting all configured
15initialization tasks, and for invoking the initialization routine for each
16user-supplied device driver.  In a multiprocessor configuration, this manager
17also initializes the interprocessor communications layer.  The directives
18provided by the Initialization Manager are:
19
20- rtems_initialize_executive_ - Initialize RTEMS
21
22- rtems_shutdown_executive_ - Shutdown RTEMS
23
24Background
25==========
26
27Initialization Tasks
28--------------------
29.. index:: initialization tasks
30
31Initialization task(s) are the mechanism by which RTEMS transfers initial
32control to the user's application.  Initialization tasks differ from other
33application tasks in that they are defined in the User Initialization Tasks
34Table and automatically created and started by RTEMS as part of its
35initialization sequence.  Since the initialization tasks are scheduled using
36the same algorithm as all other RTEMS tasks, they must be configured at a
37priority and mode which will ensure that they will complete execution before
38other application tasks execute.  Although there is no upper limit on the
39number of initialization tasks, an application is required to define at least
40one.
41
42A typical initialization task will create and start the static set of
43application tasks.  It may also create any other objects used by the
44application.  Initialization tasks which only perform initialization should
45delete themselves upon completion to free resources for other tasks.
46Initialization tasks may transform themselves into a "normal" application task.
47This transformation typically involves changing priority and execution mode.
48RTEMS does not automatically delete the initialization tasks.
49
50System Initialization
51---------------------
52
53System Initialization begins with board reset and continues through RTEMS
54initialization, initialization of all device drivers, and eventually a context
55switch to the first user task.  Remember, that interrupts are disabled during
56initialization and the *initialization context* is not a task in any sense and
57the user should be very careful during initialization.
58
59The BSP must ensure that the there is enough stack space reserved for the
60initialization context to successfully execute the initialization routines for
61all device drivers and, in multiprocessor configurations, the Multiprocessor
62Communications Interface Layer initialization routine.
63
64The Idle Task
65-------------
66
67The Idle Task is the lowest priority task in a system and executes only when no
68other task is ready to execute.  This default implementation of this task
69consists of an infinite loop. RTEMS allows the Idle Task body to be replaced by
70a CPU specific implementation, a BSP specific implementation or an application
71specific implementation.
72
73The Idle Task is preemptible and *WILL* be preempted when any other task is
74made ready to execute.  This characteristic is critical to the overall behavior
75of any application.
76
77Initialization Manager Failure
78------------------------------
79
80The ``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
108A discussion of RTEMS actions when a fatal error occurs may be found
109:ref:`Announcing a Fatal Error`.
110
111Operations
112==========
113
114Initializing RTEMS
115------------------
116
117The Initialization Manager ``rtems_initialize_executive`` directives is called
118by the ``boot_card`` routine.  The ``boot_card`` routine is invoked by the
119Board Support Package once a basic C run-time environment is set up.  This
120consists 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
132The ``rtems_initialize_executive`` directive uses a system initialization
133linker set to initialize only those parts of the overall RTEMS feature set that
134is necessary for a particular application.  See :ref:`Linker Sets`.  Each RTEMS
135feature used the application may optionally register an initialization handler.
136The system initialization API is available via``#included <rtems/sysinit.h>``.
137
138A list of all initialization steps follows.  Some steps are optional depending
139on the requested feature set of the application.  The initialization steps are
140execute 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
183The final action of the ``rtems_initialize_executive`` directive is to start
184multitasking.  RTEMS does not return to the initialization context and the
185initialization stack may be re-used for interrupt processing.
186
187Many of RTEMS actions during initialization are based upon the contents of the
188Configuration Table.  For more information regarding the format and contents of
189this table, please refer to the chapter :ref:`Configuring a System`.
190
191The final action in the initialization sequence is the initiation of
192multitasking.  When the scheduler and dispatcher are enabled, the highest
193priority, ready task will be dispatched to run.  Control will not be returned
194to the Board Support Package after multitasking is enabled.  The initialization
195stack may be re-used for interrupt processing.
196
197Shutting Down RTEMS
198-------------------
199
200The ``rtems_shutdown_executive`` directive is invoked by the application to end
201multitasking and terminate the system.
202
203Directives
204==========
205
206This section details the Initialization Manager's directives.  A subsection is
207dedicated to each of this manager's directives and describes the calling
208sequence, related constants, usage, and status codes.
209
210.. _rtems_initialize_executive:
211
212INITIALIZE_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
227NONE
228
229**DESCRIPTION:**
230
231Iterates through the system initialization linker set and invokes the
232registered handlers.  The final step is to start multitasking.
233
234**NOTES:**
235
236This directive should be called by ``boot_card`` only.
237
238This directive *does not return* to the caller.  Errors in the initialization
239sequence are usually fatal and lead to a system termination.
240
241.. _rtems_shutdown_executive:
242
243SHUTDOWN_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
259NONE
260
261**DESCRIPTION:**
262
263This directive is called when the application wishes to shutdown RTEMS.  The
264system is terminated with a fatal source of ``RTEMS_FATAL_SOURCE_EXIT`` and the
265specified ``result`` code.
266
267**NOTES:**
268
269This directive *must* be the last RTEMS directive invoked by an application and
270it *does not return* to the caller.
271
272This directive may be called any time.
Note: See TracBrowser for help on using the repository browser.