source: rtems/cpukit/sapi/src/exinit.c @ 7cd2484

4.115
Last change on this file since 7cd2484 was 7cd2484, checked in by Alexander Krutwig <alexander.krutwig@…>, on 05/12/15 at 12:32:47

timecounter: Use in RTEMS

Replace timestamp implementation with FreeBSD bintime and timecounters.

New test sptests/sptimecounter02.

Update #2271.

  • Property mode set to 100644
File size: 7.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief Initialization Manager
5 *
6 * @ingroup ClassicRTEMS
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2014.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22/*
23 *  SCORE_INIT and SAPI_INIT are defined so all of the super core and
24 *  super API data will be included in this object file.
25 */
26
27#define SAPI_INIT
28#define SCORE_INIT
29
30#include <rtems/system.h>
31#include <rtems/config.h>
32#include <rtems/debug.h>
33#include <rtems/extensionimpl.h>
34#include <rtems/init.h>
35#include <rtems/score/sysstate.h>
36
37#include <rtems/score/apiext.h>
38#include <rtems/score/apimutex.h>
39#include <rtems/score/copyrt.h>
40#include <rtems/score/cpusetimpl.h>
41#include <rtems/score/heap.h>
42#include <rtems/score/interr.h>
43#include <rtems/score/isr.h>
44#include <rtems/score/priority.h>
45#include <rtems/score/schedulerimpl.h>
46#include <rtems/score/smpimpl.h>
47#include <rtems/score/timecounter.h>
48#include <rtems/score/threadimpl.h>
49#include <rtems/score/todimpl.h>
50#include <rtems/score/userextimpl.h>
51#include <rtems/score/watchdogimpl.h>
52#include <rtems/score/wkspace.h>
53
54#include <rtems/sptables.h>
55
56
57#include <rtems/rtems/rtemsapi.h>
58#include <rtems/posix/posixapi.h>
59
60#ifdef RTEMS_DRVMGR_STARTUP
61  #include <drvmgr/drvmgr.h>
62#endif
63
64Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
65
66void rtems_initialize_data_structures(void)
67{
68  /*
69   *  Dispatching and interrupts are disabled until the end of the
70   *  initialization sequence.  This prevents an inadvertent context
71   *  switch before the executive is initialized.
72   *
73   *  WARNING: Interrupts should have been disabled by the BSP and
74   *           are disabled by boot_card().
75   */
76
77  #if defined(RTEMS_MULTIPROCESSING)
78    /*
79     *  Initialize the system state based on whether this is an MP system.
80     *  In an MP configuration, internally we view single processor
81     *  systems as a very restricted multiprocessor system.
82     */
83    _Configuration_MP_table = rtems_configuration_get_user_multiprocessing_table();
84
85    if ( _Configuration_MP_table == NULL ) {
86      _Configuration_MP_table =
87        (void *)&_Initialization_Default_multiprocessing_table;
88      _System_state_Handler_initialization( FALSE );
89    } else {
90      _System_state_Handler_initialization( TRUE );
91    }
92  #else
93    _System_state_Handler_initialization( FALSE );
94  #endif
95
96  /*
97   * Initialize any target architecture specific support as early as possible
98   */
99  _CPU_Initialize();
100
101  #if defined(RTEMS_MULTIPROCESSING)
102    _Objects_MP_Handler_early_initialization();
103  #endif
104
105  /*
106   *  Do this as early as possible to ensure no debugging output
107   *  is even attempted to be printed.
108   */
109  _Debug_Manager_initialization();
110
111  _API_extensions_Initialization();
112
113  _Thread_Dispatch_initialization();
114
115  _User_extensions_Handler_initialization();
116  _ISR_Handler_initialization();
117
118  /*
119   * Initialize the internal support API and allocator Mutex
120   */
121  _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects;
122
123  _API_Mutex_Initialization( 2 );
124  _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex );
125  _API_Mutex_Allocate( &_Once_Mutex );
126
127  _Watchdog_Handler_initialization();
128  _TOD_Handler_initialization();
129
130  _Thread_Handler_initialization();
131
132  _Scheduler_Handler_initialization();
133
134  #if defined(RTEMS_MULTIPROCESSING)
135    _Objects_MP_Handler_initialization();
136    _MPCI_Handler_initialization( RTEMS_TIMEOUT );
137  #endif
138
139  _SMP_Handler_initialize();
140
141  _CPU_set_Handler_initialization();
142
143/* MANAGERS */
144
145  _RTEMS_API_Initialize();
146
147  _Extension_Manager_initialization();
148
149  _POSIX_API_Initialize();
150
151  _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
152
153  /*
154   *  No threads should be created before this point!!!
155   *  _Thread_Executing and _Thread_Heir are not set.
156   *
157   *  At this point all API extensions are in place.  After the call to
158   *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
159   */
160  _Thread_Create_idle();
161
162  /*
163   *  Scheduling can properly occur now as long as we avoid dispatching.
164   */
165}
166
167void rtems_initialize_before_drivers(void)
168{
169  #ifdef RTEMS_DRVMGR_STARTUP
170  _DRV_Manager_initialization();
171  #endif
172
173  #if defined(RTEMS_MULTIPROCESSING)
174    _MPCI_Create_server();
175  #endif
176
177  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
178    /*
179     *  Run the API and BSPs predriver hook.
180     */
181    _API_extensions_Run_predriver();
182  #endif
183}
184
185void rtems_initialize_device_drivers(void)
186{
187  /*
188   *  Initialize all the device drivers and initialize the MPCI layer.
189   *
190   *  NOTE:  The MPCI may be build upon a device driver.
191   */
192
193  #ifdef RTEMS_DRVMGR_STARTUP
194  /* BSPs has already registered their "root bus" driver in the
195   * bsp_predriver hook or so.
196   *
197   * Init Drivers to Level 1, constraints:
198   *   - Interrupts and system clock timer does not work.
199   *   - malloc() work, however other memory services may not
200   *     have been initialized yet.
201   *   - initializes most basic stuff
202   *
203   * Typical setup in Level 1:
204   *   - Find most devices in system, do PCI scan and configuration.
205   *   - Reset hardware if needed.
206   *   - Install IRQ driver
207   *   - Install Timer driver
208   *   - Install console driver and debug printk()
209   *   - Install extra memory.
210   */
211  _DRV_Manager_init_level(1);
212  bsp_driver_level_hook(1);
213  #endif
214
215  /* Initialize I/O drivers.
216   *
217   * Driver Manager note:
218   * All drivers may not be registered yet. Drivers will dynamically
219   * be initialized when registered in level 2,3 and 4.
220   */
221  _IO_Initialize_all_drivers();
222
223  #ifdef RTEMS_DRVMGR_STARTUP
224  /* Init Drivers to Level 2, constraints:
225   *  - Interrupts can be registered and enabled.
226   *  - System Clock is running
227   *  - Console may be used.
228   *
229   * This is typically where drivers are initialized
230   * for the first time.
231   */
232  _DRV_Manager_init_level(2);
233  bsp_driver_level_hook(2);
234
235  /* Init Drivers to Level 3
236   *
237   * This is typically where normal drivers are initialized
238   * for the second time, they may depend on other drivers
239   * API inited in level 2
240   */
241  _DRV_Manager_init_level(3);
242  bsp_driver_level_hook(3);
243
244  /* Init Drivers to Level 4,
245   * Init drivers that depend on services initialized in Level 3
246   */
247  _DRV_Manager_init_level(4);
248  bsp_driver_level_hook(4);
249  #endif
250
251  #if defined(RTEMS_MULTIPROCESSING)
252    if ( _System_state_Is_multiprocessing ) {
253      _MPCI_Initialization();
254      _MPCI_Internal_packets_Send_process_packet(
255        MPCI_PACKETS_SYSTEM_VERIFY
256      );
257    }
258  #endif
259
260  /*
261   *  Run the APIs and BSPs postdriver hooks.
262   *
263   *  The API extensions are supposed to create user initialization tasks.
264   */
265  _API_extensions_Run_postdriver();
266}
267
268void rtems_initialize_start_multitasking(void)
269{
270  _System_state_Set( SYSTEM_STATE_UP );
271
272  _SMP_Request_start_multitasking();
273
274  _Thread_Start_multitasking();
275
276  /*******************************************************************
277   *******************************************************************
278   *******************************************************************
279   ******                 APPLICATION RUNS HERE                 ******
280   ******              THE FUNCTION NEVER RETURNS               ******
281   *******************************************************************
282   *******************************************************************
283   *******************************************************************/
284}
Note: See TracBrowser for help on using the repository browser.