source: rtems-docs/porting/idle_thread.rst @ 969e60e

5
Last change on this file since 969e60e was 7497f5e, checked in by Joel Sherrill <joel@…>, on 10/28/16 at 20:57:11

porting: Review and tidy up multiple formatting issues.

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