1 |
27 |
unneback |
#ifndef CYGONCE_POWER_POWER_H
|
2 |
|
|
# define CYGONCE_POWER_POWER_H
|
3 |
|
|
//==========================================================================
|
4 |
|
|
//
|
5 |
|
|
// include/power.h
|
6 |
|
|
//
|
7 |
|
|
// Definitions of power management support
|
8 |
|
|
//
|
9 |
|
|
//==========================================================================
|
10 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
14 |
|
|
//
|
15 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
// the terms of the GNU General Public License as published by the Free
|
17 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
18 |
|
|
//
|
19 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
20 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
21 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
22 |
|
|
// for more details.
|
23 |
|
|
//
|
24 |
|
|
// You should have received a copy of the GNU General Public License along
|
25 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
26 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
27 |
|
|
//
|
28 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
29 |
|
|
// or inline functions from this file, or you compile this file and link it
|
30 |
|
|
// with other works to produce a work based on this file, this file does not
|
31 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
32 |
|
|
// License. However the source code for this file must still be made available
|
33 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
36 |
|
|
// this file might be covered by the GNU General Public License.
|
37 |
|
|
//
|
38 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
39 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
40 |
|
|
// -------------------------------------------
|
41 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
42 |
|
|
//==========================================================================
|
43 |
|
|
//#####DESCRIPTIONBEGIN####
|
44 |
|
|
//
|
45 |
|
|
// Author(s): bartv
|
46 |
|
|
// Contributors: bartv
|
47 |
|
|
// Date: 2001-06-12
|
48 |
|
|
//
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//==========================================================================
|
52 |
|
|
|
53 |
|
|
#include <pkgconf/power.h>
|
54 |
|
|
#include <cyg/infra/cyg_type.h>
|
55 |
|
|
#include <cyg/hal/hal_tables.h>
|
56 |
|
|
|
57 |
|
|
#ifdef CYGPKG_POWER_THREAD
|
58 |
|
|
#include <cyg/kernel/kapi.h> // CYGPKG_POWER_THREAD is active_if CYGPKG_KERNEL so
|
59 |
|
|
// the kernel's headers are guaranteed to be available.
|
60 |
|
|
#endif
|
61 |
|
|
|
62 |
|
|
#ifdef __cplusplus
|
63 |
|
|
extern "C" {
|
64 |
|
|
#endif
|
65 |
|
|
|
66 |
|
|
// The four defined modes of power operation.
|
67 |
|
|
#define PowerMode_Min 0
|
68 |
|
|
#define PowerMode_Active 0
|
69 |
|
|
#define PowerMode_Idle 1
|
70 |
|
|
#define PowerMode_Sleep 2
|
71 |
|
|
#define PowerMode_Off 3
|
72 |
|
|
#define PowerMode_Max 3
|
73 |
|
|
typedef cyg_uint8 PowerMode;
|
74 |
|
|
|
75 |
|
|
// Whether a mode change is initiated globally or per-controller
|
76 |
|
|
#define PowerModeChange_Controller 0
|
77 |
|
|
#define PowerModeChange_ControllerNow 1
|
78 |
|
|
#define PowerModeChange_Global 2
|
79 |
|
|
typedef cyg_uint32 PowerModeChange;
|
80 |
|
|
|
81 |
|
|
// Some priorities.
|
82 |
|
|
#define PowerPri_Early 1000
|
83 |
|
|
#define PowerPri_Typical 5000
|
84 |
|
|
#define PowerPri_Late 9000
|
85 |
|
|
|
86 |
|
|
typedef struct PowerController {
|
87 |
|
|
void (*change_mode)(struct PowerController*, PowerMode, PowerModeChange);
|
88 |
|
|
#ifdef CYGIMP_POWER_PROVIDE_STRINGS
|
89 |
|
|
char* id;
|
90 |
|
|
#endif
|
91 |
|
|
#ifdef CYGIMP_POWER_PROVIDE_POLICY_DATA
|
92 |
|
|
CYG_ADDRWORD policy_data;
|
93 |
|
|
#endif
|
94 |
|
|
PowerMode mode;
|
95 |
|
|
PowerMode desired_mode;
|
96 |
|
|
cyg_uint8 change_this;
|
97 |
|
|
cyg_uint8 attached;
|
98 |
|
|
} CYG_HAL_TABLE_TYPE PowerController;
|
99 |
|
|
|
100 |
|
|
// The table of power controllers, allowing application code
|
101 |
|
|
// to access all of them.
|
102 |
|
|
extern PowerController __POWER__[], __POWER_END__;
|
103 |
|
|
|
104 |
|
|
// There should always be a power controller for the cpu which can
|
105 |
|
|
// be accessed by any client.
|
106 |
|
|
extern PowerController power_controller_cpu;
|
107 |
|
|
|
108 |
|
|
// If a separate power management thread is being used, its handle
|
109 |
|
|
// is exported so that other code can e.g. manipulate its priority
|
110 |
|
|
#ifdef CYGPKG_POWER_THREAD
|
111 |
|
|
extern cyg_handle_t power_thread_handle;
|
112 |
|
|
#endif
|
113 |
|
|
|
114 |
|
|
// Inline functions and supporting data.
|
115 |
|
|
extern PowerMode __power_mode;
|
116 |
|
|
extern PowerMode __power_desired_mode;
|
117 |
|
|
typedef void (*__power_policy_callback_t)(PowerController*, PowerMode, PowerMode, PowerMode, PowerMode);
|
118 |
|
|
extern __power_policy_callback_t __power_policy_callback;
|
119 |
|
|
|
120 |
|
|
// This macro is overridden elsewhere in this package when defining linkable
|
121 |
|
|
// extern (i.e. non-inline) versions of these functions.
|
122 |
|
|
#ifndef POWER_INLINE
|
123 |
|
|
# define POWER_INLINE extern inline
|
124 |
|
|
#endif
|
125 |
|
|
|
126 |
|
|
POWER_INLINE PowerMode
|
127 |
|
|
power_get_mode(void)
|
128 |
|
|
{
|
129 |
|
|
return __power_mode;
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
POWER_INLINE PowerMode
|
133 |
|
|
power_get_desired_mode(void)
|
134 |
|
|
{
|
135 |
|
|
return __power_desired_mode;
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
POWER_INLINE PowerMode
|
139 |
|
|
power_get_controller_mode(PowerController* controller)
|
140 |
|
|
{
|
141 |
|
|
return controller->mode;
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
POWER_INLINE PowerMode
|
145 |
|
|
power_get_controller_desired_mode(PowerController* controller)
|
146 |
|
|
{
|
147 |
|
|
return controller->desired_mode;
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
POWER_INLINE void
|
151 |
|
|
power_set_policy_callback(__power_policy_callback_t new_callback)
|
152 |
|
|
{
|
153 |
|
|
__power_policy_callback = new_callback;
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
POWER_INLINE __power_policy_callback_t
|
157 |
|
|
power_get_policy_callback(void)
|
158 |
|
|
{
|
159 |
|
|
return __power_policy_callback;
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
#ifdef CYGIMP_POWER_PROVIDE_STRINGS
|
163 |
|
|
POWER_INLINE const char*
|
164 |
|
|
power_get_controller_id(PowerController* controller)
|
165 |
|
|
{
|
166 |
|
|
return controller->id;
|
167 |
|
|
}
|
168 |
|
|
#endif
|
169 |
|
|
|
170 |
|
|
#ifdef CYGIMP_POWER_PROVIDE_POLICY_DATA
|
171 |
|
|
POWER_INLINE void
|
172 |
|
|
power_set_controller_policy_data(PowerController* controller, CYG_ADDRWORD data)
|
173 |
|
|
{
|
174 |
|
|
controller->policy_data = data;
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
POWER_INLINE CYG_ADDRWORD
|
178 |
|
|
power_get_controller_policy_data(PowerController* controller)
|
179 |
|
|
{
|
180 |
|
|
return controller->policy_data;
|
181 |
|
|
}
|
182 |
|
|
#endif
|
183 |
|
|
|
184 |
|
|
POWER_INLINE cyg_bool
|
185 |
|
|
power_get_controller_attached(PowerController* controller)
|
186 |
|
|
{
|
187 |
|
|
return controller->attached;
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
POWER_INLINE void
|
191 |
|
|
power_set_controller_attached(PowerController* controller, cyg_bool new_value)
|
192 |
|
|
{
|
193 |
|
|
controller->attached = new_value;
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
POWER_INLINE void
|
197 |
|
|
power_set_controller_mode_now(PowerController* controller, PowerMode new_mode)
|
198 |
|
|
{
|
199 |
|
|
controller->desired_mode = new_mode;
|
200 |
|
|
if (controller->mode != controller->desired_mode) {
|
201 |
|
|
(*controller->change_mode)(controller, new_mode, PowerModeChange_ControllerNow);
|
202 |
|
|
}
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
// Now for the non-inline functions.
|
206 |
|
|
extern void power_set_controller_mode(PowerController*, PowerMode);
|
207 |
|
|
extern void power_set_mode(PowerMode);
|
208 |
|
|
|
209 |
|
|
// Implementation support.
|
210 |
|
|
#ifdef CYGIMP_POWER_PROVIDE_STRINGS
|
211 |
|
|
# define POWER_CONTROLLER_ID(_id_) id: _id_,
|
212 |
|
|
#else
|
213 |
|
|
# define POWER_CONTROLLER_ID(_id_)
|
214 |
|
|
#endif
|
215 |
|
|
#ifdef CYGIMP_POWER_PROVIDE_POLICY_DATA
|
216 |
|
|
# define POWER_CONTROLLER_POLICY_DATA policy_data: 0,
|
217 |
|
|
#else
|
218 |
|
|
# define POWER_CONTROLLER_POLICY_DATA
|
219 |
|
|
#endif
|
220 |
|
|
|
221 |
|
|
#define POWER_CONTROLLER(_name_, _pri_, _id_, _fn_) \
|
222 |
|
|
PowerController _name_ \
|
223 |
|
|
CYG_HAL_TABLE_QUALIFIED_ENTRY(power, _pri_) = { \
|
224 |
|
|
change_mode: _fn_, \
|
225 |
|
|
POWER_CONTROLLER_ID(_id_) \
|
226 |
|
|
POWER_CONTROLLER_POLICY_DATA \
|
227 |
|
|
mode: PowerMode_Active, \
|
228 |
|
|
desired_mode: PowerMode_Active, \
|
229 |
|
|
change_this: 0, \
|
230 |
|
|
attached: 1 \
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
#define POWER_CONTROLLER_CPU(_id_, _fn_) \
|
234 |
|
|
PowerController power_controller_cpu \
|
235 |
|
|
CYG_HAL_TABLE_EXTRA(power) = { \
|
236 |
|
|
change_mode: _fn_, \
|
237 |
|
|
POWER_CONTROLLER_ID(_id_) \
|
238 |
|
|
POWER_CONTROLLER_POLICY_DATA \
|
239 |
|
|
mode: PowerMode_Active, \
|
240 |
|
|
desired_mode: PowerMode_Active, \
|
241 |
|
|
change_this: 0, \
|
242 |
|
|
attached: 1, \
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
#ifdef __cplusplus
|
246 |
|
|
} // extern "C" {
|
247 |
|
|
#endif
|
248 |
|
|
|
249 |
|
|
#endif // CYGONCE_POWER_POWER_H
|