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.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/threadimpl.h> |
---|
22 | #include <rtems/score/schedulerimpl.h> |
---|
23 | #include <rtems/score/stackimpl.h> |
---|
24 | #include <rtems/score/userextimpl.h> |
---|
25 | #include <rtems/config.h> |
---|
26 | |
---|
27 | static void _Thread_Create_idle_for_cpu( Per_CPU_Control *cpu ) |
---|
28 | { |
---|
29 | Objects_Name name; |
---|
30 | Thread_Control *idle; |
---|
31 | const Scheduler_Control *scheduler; |
---|
32 | |
---|
33 | name.name_u32 = _Objects_Build_name( 'I', 'D', 'L', 'E' ); |
---|
34 | |
---|
35 | /* |
---|
36 | * The entire workspace is zeroed during its initialization. Thus, all |
---|
37 | * fields not explicitly assigned were explicitly zeroed by |
---|
38 | * _Workspace_Initialization. |
---|
39 | */ |
---|
40 | idle = _Thread_Internal_allocate(); |
---|
41 | |
---|
42 | _Thread_Initialize( |
---|
43 | &_Thread_Internal_information, |
---|
44 | idle, |
---|
45 | _Scheduler_Get_by_CPU( cpu ), |
---|
46 | NULL, /* allocate the stack */ |
---|
47 | _Stack_Ensure_minimum( rtems_configuration_get_idle_task_stack_size() ), |
---|
48 | CPU_IDLE_TASK_IS_FP, |
---|
49 | PRIORITY_MAXIMUM, |
---|
50 | true, /* preemptable */ |
---|
51 | THREAD_CPU_BUDGET_ALGORITHM_NONE, |
---|
52 | NULL, /* no budget algorithm callout */ |
---|
53 | 0, /* all interrupts enabled */ |
---|
54 | name |
---|
55 | ); |
---|
56 | |
---|
57 | /* |
---|
58 | * WARNING!!! This is necessary to "kick" start the system and |
---|
59 | * MUST be done before _Thread_Start is invoked. |
---|
60 | */ |
---|
61 | cpu->heir = |
---|
62 | cpu->executing = idle; |
---|
63 | |
---|
64 | idle->Start.Entry.adaptor = _Thread_Entry_adaptor_idle; |
---|
65 | idle->Start.Entry.Kinds.Idle.entry = rtems_configuration_get_idle_task(); |
---|
66 | |
---|
67 | _Thread_Load_environment( idle ); |
---|
68 | |
---|
69 | scheduler = _Scheduler_Get_by_CPU( cpu ); |
---|
70 | |
---|
71 | #if defined(RTEMS_SMP) |
---|
72 | if (scheduler == NULL) { |
---|
73 | return; |
---|
74 | } |
---|
75 | #endif |
---|
76 | |
---|
77 | idle->current_state = STATES_READY; |
---|
78 | _Scheduler_Start_idle( scheduler, idle, cpu ); |
---|
79 | _User_extensions_Thread_start( idle ); |
---|
80 | } |
---|
81 | |
---|
82 | void _Thread_Create_idle( void ) |
---|
83 | { |
---|
84 | uint32_t cpu_count = _SMP_Get_processor_count(); |
---|
85 | uint32_t cpu_index; |
---|
86 | |
---|
87 | for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) { |
---|
88 | Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index ); |
---|
89 | |
---|
90 | if ( _Per_CPU_Is_processor_started( cpu ) ) { |
---|
91 | _Thread_Create_idle_for_cpu( cpu ); |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|