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