[e655f7e] | 1 | /** |
---|
| 2 | * @file |
---|
[05df0a8] | 3 | * |
---|
[e655f7e] | 4 | * @brief Create Idle Thread |
---|
| 5 | * @ingroup ScoreThread |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[06dcaf0] | 9 | * COPYRIGHT (c) 1989-2011. |
---|
[05df0a8] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
| 12 | * The license and distribution terms for this file may be |
---|
[dcf3687] | 13 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[05df0a8] | 15 | */ |
---|
| 16 | |
---|
[a8eed23] | 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
[5618c37a] | 21 | #include <rtems/score/threadimpl.h> |
---|
[c5831a3f] | 22 | #include <rtems/score/schedulerimpl.h> |
---|
[218286bc] | 23 | #include <rtems/score/stackimpl.h> |
---|
[976162a6] | 24 | #include <rtems/config.h> |
---|
[05df0a8] | 25 | |
---|
[3380ee8] | 26 | static void _Thread_Create_idle_for_cpu( Per_CPU_Control *cpu ) |
---|
[05df0a8] | 27 | { |
---|
[ccd5434] | 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 | }; |
---|
[477259c] | 36 | Objects_Name name; |
---|
| 37 | Thread_Control *idle; |
---|
[6c71b25] | 38 | |
---|
[477259c] | 39 | name.name_u32 = _Objects_Build_name( 'I', 'D', 'L', 'E' ); |
---|
[05df0a8] | 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 | */ |
---|
[06dcaf0] | 46 | idle = _Thread_Internal_allocate(); |
---|
[05279b84] | 47 | |
---|
[05df0a8] | 48 | _Thread_Initialize( |
---|
| 49 | &_Thread_Internal_information, |
---|
[06dcaf0] | 50 | idle, |
---|
[3380ee8] | 51 | _Scheduler_Get_by_CPU( cpu ), |
---|
[05df0a8] | 52 | NULL, /* allocate the stack */ |
---|
[8a331a5e] | 53 | _Stack_Ensure_minimum( rtems_configuration_get_idle_task_stack_size() ), |
---|
[05df0a8] | 54 | CPU_IDLE_TASK_IS_FP, |
---|
| 55 | PRIORITY_MAXIMUM, |
---|
[aae7f1a1] | 56 | true, /* preemptable */ |
---|
[05df0a8] | 57 | THREAD_CPU_BUDGET_ALGORITHM_NONE, |
---|
| 58 | NULL, /* no budget algorithm callout */ |
---|
| 59 | 0, /* all interrupts enabled */ |
---|
[6c71b25] | 60 | name |
---|
[05df0a8] | 61 | ); |
---|
[05279b84] | 62 | |
---|
[05df0a8] | 63 | /* |
---|
| 64 | * WARNING!!! This is necessary to "kick" start the system and |
---|
| 65 | * MUST be done before _Thread_Start is invoked. |
---|
| 66 | */ |
---|
[3380ee8] | 67 | cpu->heir = |
---|
| 68 | cpu->executing = idle; |
---|
[05279b84] | 69 | |
---|
[ccd5434] | 70 | _Thread_Start( idle, &entry, cpu ); |
---|
[06dcaf0] | 71 | } |
---|
| 72 | |
---|
| 73 | void _Thread_Create_idle( void ) |
---|
| 74 | { |
---|
[3380ee8] | 75 | uint32_t cpu_count = _SMP_Get_processor_count(); |
---|
| 76 | uint32_t cpu_index; |
---|
[477259c] | 77 | |
---|
[3380ee8] | 78 | for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) { |
---|
| 79 | Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index ); |
---|
[05279b84] | 80 | |
---|
[3380ee8] | 81 | if ( _Per_CPU_Is_processor_started( cpu ) ) { |
---|
| 82 | _Thread_Create_idle_for_cpu( cpu ); |
---|
[c5831a3f] | 83 | } |
---|
[477259c] | 84 | } |
---|
[05df0a8] | 85 | } |
---|