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/config.h> |
---|
25 | |
---|
26 | static void _Thread_Create_idle_for_cpu( Per_CPU_Control *cpu ) |
---|
27 | { |
---|
28 | Thread_Entry_information entry = { |
---|
29 | .adaptor = _Thread_Entry_adaptor_idle, |
---|
30 | .Kinds = { |
---|
31 | .Idle = { |
---|
32 | .entry = rtems_configuration_get_idle_task() |
---|
33 | } |
---|
34 | } |
---|
35 | }; |
---|
36 | Objects_Name name; |
---|
37 | Thread_Control *idle; |
---|
38 | |
---|
39 | name.name_u32 = _Objects_Build_name( 'I', 'D', 'L', 'E' ); |
---|
40 | |
---|
41 | /* |
---|
42 | * The entire workspace is zeroed during its initialization. Thus, all |
---|
43 | * fields not explicitly assigned were explicitly zeroed by |
---|
44 | * _Workspace_Initialization. |
---|
45 | */ |
---|
46 | idle = _Thread_Internal_allocate(); |
---|
47 | |
---|
48 | _Thread_Initialize( |
---|
49 | &_Thread_Internal_information, |
---|
50 | idle, |
---|
51 | _Scheduler_Get_by_CPU( cpu ), |
---|
52 | NULL, /* allocate the stack */ |
---|
53 | _Stack_Ensure_minimum( rtems_configuration_get_idle_task_stack_size() ), |
---|
54 | CPU_IDLE_TASK_IS_FP, |
---|
55 | PRIORITY_MAXIMUM, |
---|
56 | true, /* preemptable */ |
---|
57 | THREAD_CPU_BUDGET_ALGORITHM_NONE, |
---|
58 | NULL, /* no budget algorithm callout */ |
---|
59 | 0, /* all interrupts enabled */ |
---|
60 | name |
---|
61 | ); |
---|
62 | |
---|
63 | /* |
---|
64 | * WARNING!!! This is necessary to "kick" start the system and |
---|
65 | * MUST be done before _Thread_Start is invoked. |
---|
66 | */ |
---|
67 | cpu->heir = |
---|
68 | cpu->executing = idle; |
---|
69 | |
---|
70 | _Thread_Start( idle, &entry, cpu ); |
---|
71 | } |
---|
72 | |
---|
73 | void _Thread_Create_idle( void ) |
---|
74 | { |
---|
75 | uint32_t cpu_count = _SMP_Get_processor_count(); |
---|
76 | uint32_t cpu_index; |
---|
77 | |
---|
78 | for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) { |
---|
79 | Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index ); |
---|
80 | |
---|
81 | if ( _Per_CPU_Is_processor_started( cpu ) ) { |
---|
82 | _Thread_Create_idle_for_cpu( cpu ); |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|