source: rtems-docs/c-user/initialization.rst @ 00ffe1f

5
Last change on this file since 00ffe1f was 00ffe1f, checked in by Sebastian Huber <sebastian.huber@…>, on 12/09/16 at 09:55:29

Improve fatal error chapter

Update #2825.

  • Property mode set to 100644
File size: 9.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
80System initialization errors are fatal.  See :ref:`internal_errors`.
81
82Operations
83==========
84
85Initializing RTEMS
86------------------
87
88The Initialization Manager ``rtems_initialize_executive`` directives is called
89by the ``boot_card`` routine.  The ``boot_card`` routine is invoked by the
90Board Support Package once a basic C run-time environment is set up.  This
91consists 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
103The ``rtems_initialize_executive`` directive uses a system initialization
104linker set to initialize only those parts of the overall RTEMS feature set that
105is necessary for a particular application.  See :ref:`Linker Sets`.  Each RTEMS
106feature used the application may optionally register an initialization handler.
107The system initialization API is available via``#included <rtems/sysinit.h>``.
108
109A list of all initialization steps follows.  Some steps are optional depending
110on the requested feature set of the application.  The initialization steps are
111execute 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
154The final action of the ``rtems_initialize_executive`` directive is to start
155multitasking.  RTEMS does not return to the initialization context and the
156initialization stack may be re-used for interrupt processing.
157
158Many of RTEMS actions during initialization are based upon the contents of the
159Configuration Table.  For more information regarding the format and contents of
160this table, please refer to the chapter :ref:`Configuring a System`.
161
162The final action in the initialization sequence is the initiation of
163multitasking.  When the scheduler and dispatcher are enabled, the highest
164priority, ready task will be dispatched to run.  Control will not be returned
165to the Board Support Package after multitasking is enabled.  The initialization
166stack may be re-used for interrupt processing.
167
168Shutting Down RTEMS
169-------------------
170
171The ``rtems_shutdown_executive`` directive is invoked by the application to end
172multitasking and terminate the system.
173
174Directives
175==========
176
177This section details the Initialization Manager's directives.  A subsection is
178dedicated to each of this manager's directives and describes the calling
179sequence, related constants, usage, and status codes.
180
181.. raw:: latex
182
183   \clearpage
184
185.. _rtems_initialize_executive:
186
187INITIALIZE_EXECUTIVE - Initialize RTEMS
188---------------------------------------
189.. index:: initialize RTEMS
190.. index:: start multitasking
191
192.. index:: rtems_initialize_executive
193CALLING SEQUENCE:
194    .. code-block:: c
195
196        void rtems_initialize_executive(void);
197
198DIRECTIVE STATUS CODES:
199    NONE
200
201DESCRIPTION:
202    Iterates through the system initialization linker set and invokes the
203    registered handlers.  The final step is to start multitasking.
204
205NOTES:
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
217SHUTDOWN_EXECUTIVE - Shutdown RTEMS
218-----------------------------------
219.. index:: shutdown RTEMS
220
221.. index:: rtems_shutdown_executive
222CALLING SEQUENCE:
223    .. code-block:: c
224
225        void rtems_shutdown_executive(
226            uint32_t result
227        );
228
229DIRECTIVE STATUS CODES:
230    NONE
231
232DESCRIPTION:
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
237NOTES:
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.
Note: See TracBrowser for help on using the repository browser.