1 | /* |
---|
2 | * Thread Handler |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-2011. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.com/license/LICENSE. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems/system.h> |
---|
20 | #include <rtems/score/apiext.h> |
---|
21 | #include <rtems/score/context.h> |
---|
22 | #include <rtems/score/interr.h> |
---|
23 | #include <rtems/score/isr.h> |
---|
24 | #include <rtems/score/object.h> |
---|
25 | #include <rtems/score/priority.h> |
---|
26 | #include <rtems/score/states.h> |
---|
27 | #include <rtems/score/sysstate.h> |
---|
28 | #include <rtems/score/thread.h> |
---|
29 | #include <rtems/score/threadq.h> |
---|
30 | #include <rtems/score/userext.h> |
---|
31 | #include <rtems/score/wkspace.h> |
---|
32 | #include <rtems/config.h> |
---|
33 | #if defined(RTEMS_SMP) |
---|
34 | #include <rtems/score/smp.h> |
---|
35 | #endif |
---|
36 | |
---|
37 | static inline void _Thread_Create_idle_helper( |
---|
38 | uint32_t name_u32, |
---|
39 | int cpu |
---|
40 | ) |
---|
41 | { |
---|
42 | Objects_Name name; |
---|
43 | Thread_Control *idle; |
---|
44 | |
---|
45 | name.name_u32 = name_u32; |
---|
46 | |
---|
47 | /* |
---|
48 | * The entire workspace is zeroed during its initialization. Thus, all |
---|
49 | * fields not explicitly assigned were explicitly zeroed by |
---|
50 | * _Workspace_Initialization. |
---|
51 | */ |
---|
52 | idle = _Thread_Internal_allocate(); |
---|
53 | |
---|
54 | /* |
---|
55 | * This is only called during initialization and we better be sure |
---|
56 | * that when _Thread_Initialize unnests dispatch that we do not |
---|
57 | * do anything stupid. |
---|
58 | */ |
---|
59 | _Thread_Disable_dispatch(); |
---|
60 | |
---|
61 | _Thread_Initialize( |
---|
62 | &_Thread_Internal_information, |
---|
63 | idle, |
---|
64 | NULL, /* allocate the stack */ |
---|
65 | _Stack_Ensure_minimum( Configuration.idle_task_stack_size ), |
---|
66 | CPU_IDLE_TASK_IS_FP, |
---|
67 | PRIORITY_MAXIMUM, |
---|
68 | true, /* preemptable */ |
---|
69 | THREAD_CPU_BUDGET_ALGORITHM_NONE, |
---|
70 | NULL, /* no budget algorithm callout */ |
---|
71 | 0, /* all interrupts enabled */ |
---|
72 | name |
---|
73 | ); |
---|
74 | |
---|
75 | _Thread_Unnest_dispatch(); |
---|
76 | |
---|
77 | /* |
---|
78 | * WARNING!!! This is necessary to "kick" start the system and |
---|
79 | * MUST be done before _Thread_Start is invoked. |
---|
80 | */ |
---|
81 | _Per_CPU_Information[ cpu ].idle = |
---|
82 | _Per_CPU_Information[ cpu ].heir = |
---|
83 | _Per_CPU_Information[ cpu ].executing = idle; |
---|
84 | |
---|
85 | _Thread_Start( |
---|
86 | idle, |
---|
87 | THREAD_START_NUMERIC, |
---|
88 | Configuration.idle_task, |
---|
89 | NULL, |
---|
90 | 0 |
---|
91 | ); |
---|
92 | } |
---|
93 | |
---|
94 | void _Thread_Create_idle( void ) |
---|
95 | { |
---|
96 | #if defined(RTEMS_SMP) |
---|
97 | int cpu; |
---|
98 | |
---|
99 | for ( cpu=0 ; cpu < _SMP_Processor_count ; cpu++ ) { |
---|
100 | _Thread_Create_idle_helper( |
---|
101 | _Objects_Build_name( 'I', 'D', 'L', 'E' ), |
---|
102 | cpu |
---|
103 | ); |
---|
104 | } |
---|
105 | #else |
---|
106 | _Thread_Create_idle_helper(_Objects_Build_name( 'I', 'D', 'L', 'E' ), 0); |
---|
107 | #endif |
---|
108 | } |
---|