1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Device Driver Initialization Functions |
---|
5 | * |
---|
6 | * @ingroup ClassicRTEMS |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Initialization Manager |
---|
11 | * |
---|
12 | * COPYRIGHT (c) 1989-2011. |
---|
13 | * On-Line Applications Research Corporation (OAR). |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.com/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #if HAVE_CONFIG_H |
---|
21 | #include "config.h" |
---|
22 | #endif |
---|
23 | |
---|
24 | /* |
---|
25 | * SCORE_INIT and SAPI_INIT are defined so all of the super core and |
---|
26 | * super API data will be included in this object file. |
---|
27 | */ |
---|
28 | |
---|
29 | #define SAPI_INIT |
---|
30 | #define SCORE_INIT |
---|
31 | |
---|
32 | #include <rtems/system.h> |
---|
33 | #include <rtems/config.h> |
---|
34 | #include <rtems/debug.h> |
---|
35 | #include <rtems/extensionimpl.h> |
---|
36 | #include <rtems/fatal.h> |
---|
37 | #include <rtems/init.h> |
---|
38 | #include <rtems/io.h> |
---|
39 | #include <rtems/score/sysstate.h> |
---|
40 | |
---|
41 | #include <rtems/score/apiext.h> |
---|
42 | #include <rtems/score/apimutex.h> |
---|
43 | #include <rtems/score/copyrt.h> |
---|
44 | #include <rtems/score/heap.h> |
---|
45 | #include <rtems/score/interr.h> |
---|
46 | #include <rtems/score/isr.h> |
---|
47 | #include <rtems/score/priority.h> |
---|
48 | #include <rtems/score/schedulerimpl.h> |
---|
49 | #include <rtems/score/threadimpl.h> |
---|
50 | #include <rtems/score/todimpl.h> |
---|
51 | #include <rtems/score/userextimpl.h> |
---|
52 | #include <rtems/score/watchdogimpl.h> |
---|
53 | #include <rtems/score/wkspace.h> |
---|
54 | |
---|
55 | #include <rtems/sptables.h> |
---|
56 | |
---|
57 | |
---|
58 | #include <rtems/rtems/rtemsapi.h> |
---|
59 | #ifdef RTEMS_POSIX_API |
---|
60 | #include <rtems/posix/posixapi.h> |
---|
61 | #endif |
---|
62 | |
---|
63 | #if defined(RTEMS_SMP) |
---|
64 | #include <rtems/score/smp.h> |
---|
65 | #include <rtems/score/percpu.h> |
---|
66 | #endif |
---|
67 | |
---|
68 | Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ]; |
---|
69 | |
---|
70 | void rtems_initialize_data_structures(void) |
---|
71 | { |
---|
72 | /* |
---|
73 | * Dispatching and interrupts are disabled until the end of the |
---|
74 | * initialization sequence. This prevents an inadvertent context |
---|
75 | * switch before the executive is initialized. |
---|
76 | * |
---|
77 | * WARNING: Interrupts should have been disabled by the BSP and |
---|
78 | * are disabled by boot_card(). |
---|
79 | */ |
---|
80 | |
---|
81 | #if defined(RTEMS_MULTIPROCESSING) |
---|
82 | /* |
---|
83 | * Initialize the system state based on whether this is an MP system. |
---|
84 | * In an MP configuration, internally we view single processor |
---|
85 | * systems as a very restricted multiprocessor system. |
---|
86 | */ |
---|
87 | _Configuration_MP_table = rtems_configuration_get_user_multiprocessing_table(); |
---|
88 | |
---|
89 | if ( _Configuration_MP_table == NULL ) { |
---|
90 | _Configuration_MP_table = |
---|
91 | (void *)&_Initialization_Default_multiprocessing_table; |
---|
92 | _System_state_Handler_initialization( FALSE ); |
---|
93 | } else { |
---|
94 | _System_state_Handler_initialization( TRUE ); |
---|
95 | } |
---|
96 | #else |
---|
97 | _System_state_Handler_initialization( FALSE ); |
---|
98 | #endif |
---|
99 | |
---|
100 | /* |
---|
101 | * Initialize any target architecture specific support as early as possible |
---|
102 | */ |
---|
103 | _CPU_Initialize(); |
---|
104 | |
---|
105 | #if defined(RTEMS_MULTIPROCESSING) |
---|
106 | _Objects_MP_Handler_early_initialization(); |
---|
107 | #endif |
---|
108 | |
---|
109 | /* |
---|
110 | * Do this as early as possible to ensure no debugging output |
---|
111 | * is even attempted to be printed. |
---|
112 | */ |
---|
113 | _Debug_Manager_initialization(); |
---|
114 | |
---|
115 | _API_extensions_Initialization(); |
---|
116 | |
---|
117 | _Thread_Dispatch_initialization(); |
---|
118 | |
---|
119 | _User_extensions_Handler_initialization(); |
---|
120 | _ISR_Handler_initialization(); |
---|
121 | |
---|
122 | /* |
---|
123 | * Initialize the internal support API and allocator Mutex |
---|
124 | */ |
---|
125 | _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects; |
---|
126 | |
---|
127 | _API_Mutex_Initialization( 1 ); |
---|
128 | _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex ); |
---|
129 | |
---|
130 | _Watchdog_Handler_initialization(); |
---|
131 | _TOD_Handler_initialization(); |
---|
132 | |
---|
133 | _Thread_Handler_initialization(); |
---|
134 | |
---|
135 | _Scheduler_Handler_initialization(); |
---|
136 | |
---|
137 | #if defined(RTEMS_MULTIPROCESSING) |
---|
138 | _Objects_MP_Handler_initialization(); |
---|
139 | _MPCI_Handler_initialization( RTEMS_TIMEOUT ); |
---|
140 | #endif |
---|
141 | |
---|
142 | /* MANAGERS */ |
---|
143 | |
---|
144 | _RTEMS_API_Initialize(); |
---|
145 | |
---|
146 | _Extension_Manager_initialization(); |
---|
147 | |
---|
148 | _IO_Manager_initialization(); |
---|
149 | |
---|
150 | #ifdef RTEMS_POSIX_API |
---|
151 | _POSIX_API_Initialize(); |
---|
152 | #endif |
---|
153 | |
---|
154 | #if defined(RTEMS_SMP) |
---|
155 | _SMP_Handler_initialize(); |
---|
156 | #endif |
---|
157 | |
---|
158 | _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING ); |
---|
159 | |
---|
160 | /* |
---|
161 | * No threads should be created before this point!!! |
---|
162 | * _Thread_Executing and _Thread_Heir are not set. |
---|
163 | * |
---|
164 | * At this point all API extensions are in place. After the call to |
---|
165 | * _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set. |
---|
166 | */ |
---|
167 | _Thread_Create_idle(); |
---|
168 | |
---|
169 | /* |
---|
170 | * Scheduling can properly occur now as long as we avoid dispatching. |
---|
171 | */ |
---|
172 | } |
---|
173 | |
---|
174 | void rtems_initialize_before_drivers(void) |
---|
175 | { |
---|
176 | |
---|
177 | #if defined(RTEMS_MULTIPROCESSING) |
---|
178 | _MPCI_Create_server(); |
---|
179 | #endif |
---|
180 | |
---|
181 | #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API) |
---|
182 | /* |
---|
183 | * Run the API and BSPs predriver hook. |
---|
184 | */ |
---|
185 | _API_extensions_Run_predriver(); |
---|
186 | #endif |
---|
187 | } |
---|
188 | |
---|
189 | void rtems_initialize_device_drivers(void) |
---|
190 | { |
---|
191 | /* |
---|
192 | * Initialize all the device drivers and initialize the MPCI layer. |
---|
193 | * |
---|
194 | * NOTE: The MPCI may be build upon a device driver. |
---|
195 | */ |
---|
196 | |
---|
197 | _IO_Initialize_all_drivers(); |
---|
198 | |
---|
199 | #if defined(RTEMS_MULTIPROCESSING) |
---|
200 | if ( _System_state_Is_multiprocessing ) { |
---|
201 | _MPCI_Initialization(); |
---|
202 | _MPCI_Internal_packets_Send_process_packet( |
---|
203 | MPCI_PACKETS_SYSTEM_VERIFY |
---|
204 | ); |
---|
205 | } |
---|
206 | #endif |
---|
207 | |
---|
208 | /* |
---|
209 | * Run the APIs and BSPs postdriver hooks. |
---|
210 | * |
---|
211 | * The API extensions are supposed to create user initialization tasks. |
---|
212 | */ |
---|
213 | _API_extensions_Run_postdriver(); |
---|
214 | } |
---|
215 | |
---|
216 | void rtems_initialize_start_multitasking(void) |
---|
217 | { |
---|
218 | uint32_t status; |
---|
219 | |
---|
220 | _System_state_Set( SYSTEM_STATE_UP ); |
---|
221 | |
---|
222 | #if defined(RTEMS_SMP) |
---|
223 | _SMP_Request_other_cores_to_perform_first_context_switch(); |
---|
224 | #endif |
---|
225 | |
---|
226 | _Thread_Start_multitasking( &_Thread_BSP_context ); |
---|
227 | |
---|
228 | /******************************************************************* |
---|
229 | ******************************************************************* |
---|
230 | ******************************************************************* |
---|
231 | ****** APPLICATION RUNS HERE ****** |
---|
232 | ****** RETURNS WHEN SYSTEM IS SHUT DOWN ****** |
---|
233 | ******************************************************************* |
---|
234 | ******************************************************************* |
---|
235 | *******************************************************************/ |
---|
236 | |
---|
237 | status = _Thread_Get_global_exit_status(); |
---|
238 | rtems_fatal( RTEMS_FATAL_SOURCE_EXIT, status ); |
---|
239 | } |
---|