source: rtems/cpukit/score/src/threadcreateidle.c @ 80cf60e

5
Last change on this file since 80cf60e was 80cf60e, checked in by Sebastian Huber <sebastian.huber@…>, on 04/15/20 at 07:48:32

Canonicalize config.h include

Use the following variant which was already used by most source files:

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Create Idle Thread
5 *  @ingroup RTEMSScoreThread
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#ifdef HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/threadidledata.h>
22#include <rtems/score/threadimpl.h>
23#include <rtems/score/assert.h>
24#include <rtems/score/schedulerimpl.h>
25#include <rtems/score/stackimpl.h>
26#include <rtems/score/sysstate.h>
27#include <rtems/score/userextimpl.h>
28
29#include <string.h>
30
31static void _Thread_Create_idle_for_CPU( Per_CPU_Control *cpu )
32{
33  Thread_Configuration  config;
34  Thread_Control       *idle;
35  bool                  ok;
36
37  memset( &config, 0, sizeof( config ) );
38  config.scheduler = _Scheduler_Get_by_CPU( cpu );
39
40#if defined(RTEMS_SMP)
41  if ( config.scheduler == NULL ) {
42    return;
43  }
44#endif
45
46  config.priority = _Scheduler_Map_priority(
47    config.scheduler,
48    config.scheduler->maximum_priority
49  );
50  config.budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
51  config.name.name_u32 = _Objects_Build_name( 'I', 'D', 'L', 'E' );
52  config.is_fp = CPU_IDLE_TASK_IS_FP;
53  config.is_preemptible = true;
54  config.stack_size = _Thread_Idle_stack_size
55    + CPU_IDLE_TASK_IS_FP * CONTEXT_FP_SIZE;
56  config.stack_area = &_Thread_Idle_stacks[
57    _Per_CPU_Get_index( cpu ) * config.stack_size
58  ];
59
60  /*
61   *  The entire workspace is zeroed during its initialization.  Thus, all
62   *  fields not explicitly assigned were explicitly zeroed by
63   *  _Workspace_Initialization.
64   */
65  idle = _Thread_Internal_allocate();
66  _Assert( idle != NULL );
67
68  ok = _Thread_Initialize( &_Thread_Information, idle, &config );
69  _Assert( ok );
70  (void) ok;
71
72  /*
73   *  WARNING!!! This is necessary to "kick" start the system and
74   *             MUST be done before _Thread_Start is invoked.
75   */
76  cpu->heir      =
77  cpu->executing = idle;
78#if defined(RTEMS_SMP)
79  cpu->ancestor = idle;
80#endif
81
82  idle->is_idle = true;
83  idle->Start.Entry.adaptor = _Thread_Entry_adaptor_idle;
84  idle->Start.Entry.Kinds.Idle.entry = _Thread_Idle_body;
85
86  _Thread_Load_environment( idle );
87
88  idle->current_state = STATES_READY;
89  _Scheduler_Start_idle( config.scheduler, idle, cpu );
90  _User_extensions_Thread_start( idle );
91}
92
93void _Thread_Create_idle( void )
94{
95  uint32_t cpu_max;
96  uint32_t cpu_index;
97
98  _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
99  cpu_max = _SMP_Get_processor_maximum();
100
101  for ( cpu_index = 0 ; cpu_index < cpu_max ; ++cpu_index ) {
102    Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index );
103
104    if ( _Per_CPU_Is_processor_online( cpu ) ) {
105      _Thread_Create_idle_for_CPU( cpu );
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.