source: rtems-docs/porting/idle_thread.rst @ b0f2977

4.115
Last change on this file since b0f2977 was b0f2977, checked in by Joel Sherrill <joel@…>, on 10/28/16 at 01:01:47

porting: Fix code-block markup

  • Property mode set to 100644
File size: 4.0 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3IDLE Thread
4###########
5
6Does Idle Thread Have a Floating Point Context?
7===============================================
8
9The setting of the macro CPU_IDLE_TASK_IS_FP is based on the answer to the
10question:  Should the IDLE task have a floating point context?  If the
11answer to this question is TRUE, then the IDLE task has a floating point
12context associated.  This is equivalent to creating a task in the Classic
13API (using rtems_task_create) as a RTEMS_FLOATING_POINT task.  If
14CPU_IDLE_TASK_IS_FP is set to TRUE, then a floating point context switch
15occurs when the IDLE task is switched in and out.  This adds to the
16execution overhead of the system but is necessary on some ports.
17
18If FALSE, then the IDLE task does not have a floating point context.
19
20NOTE: Setting CPU_IDLE_TASK_IS_FP to TRUE negatively impacts the time
21required to preempt the IDLE task from an interrupt because the floating
22point context must be saved as part of the preemption.
23
24The following illustrates how to set this macro:
25.. code-block:: c
26
27    #define CPU_IDLE_TASK_IS_FP      FALSE
28
29CPU Dependent Idle Thread Body
30==============================
31
32CPU_PROVIDES_IDLE_THREAD_BODY Macro Setting
33-------------------------------------------
34
35The CPU_PROVIDES_IDLE_THREAD_BODY macro setting is based upon the answer
36to the question:  Does this port provide a CPU dependent IDLE task
37implementation?  If the answer to this question is yes, then the
38CPU_PROVIDES_IDLE_THREAD_BODY macro should be set to TRUE, and the routine
39_CPU_Thread_Idle_body must be provided.  This routine overrides the
40default IDLE thread body of _Thread_Idle_body.  If the
41CPU_PROVIDES_IDLE_THREAD_BODY macro is set to FALSE, then the generic
42_Thread_Idle_body is the default IDLE thread body for this port.
43Regardless of whether or not a CPU dependent IDLE thread implementation is
44provided, the BSP can still override it.
45
46This is intended to allow for supporting processors which have a low power
47or idle mode.  When the IDLE thread is executed, then the CPU can be
48powered down when the processor is idle.
49
50The order of precedence for selecting the IDLE thread body is:
51
52# BSP provided
53
54# CPU dependent (if provided)
55
56# generic (if no BSP and no CPU dependent)
57
58The following illustrates setting the CPU_PROVIDES_IDLE_THREAD_BODY macro:
59.. code-block:: c
60
61    #define CPU_PROVIDES_IDLE_THREAD_BODY    TRUE
62
63Implementation details of a CPU model specific IDLE thread body are in the
64next section.
65
66Idle Thread Body
67----------------
68
69The _CPU_Thread_Idle_body routine only needs to be provided if the porter
70wishes to include a CPU dependent IDLE thread body.  If the port includes
71a CPU dependent implementation of the IDLE thread body, then the
72CPU_PROVIDES_IDLE_THREAD_BODY macro should be defined to TRUE.  This
73routine is prototyped as follows:
74.. code-block:: c
75
76    void *_CPU_Thread_Idle_body( uintptr_t );
77
78As mentioned above, RTEMS does not require that a CPU dependent IDLE
79thread body be provided as part of the port.  If
80CPU_PROVIDES_IDLE_THREAD_BODY is defined to FALSE, then the CPU
81independent algorithm is used.  This algorithm consists of a "branch to
82self" which is implemented in a routine as follows.
83.. code-block:: c
84
85    void *_Thread_Idle_body( uintptr_t ignored )
86    {
87      while( 1 ) ;
88    }
89
90If the CPU dependent IDLE thread body is implementation centers upon using
91a "halt", "idle", or "shutdown" instruction, then don't forget to put it
92in an infinite loop as the CPU will have to reexecute this instruction
93each time the IDLE thread is dispatched.
94.. code-block:: c
95
96    void *_CPU_Thread_Idle_body( uintptr_t ignored )
97    {
98      for( ; ; )
99        /* insert your "halt" instruction here */ ;
100    }
101
102Be warned. Some processors with onboard DMA have been known to stop the
103DMA if the CPU were put in IDLE mode.  This might also be a problem with
104other on-chip peripherals.  So use this hook with caution.
105
106.. COMMENT: COPYRIGHT (c) 1988-2002.
107
108.. COMMENT: On-Line Applications Research Corporation (OAR).
109
110.. COMMENT: All rights reserved.
111
Note: See TracBrowser for help on using the repository browser.