sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32\include\kernel\kpower.h
|
sl@0
|
15 |
// Public header for power management
|
sl@0
|
16 |
//
|
sl@0
|
17 |
// WARNING: This file contains some APIs which are internal and are subject
|
sl@0
|
18 |
// to change without notice. Such APIs should therefore not be used
|
sl@0
|
19 |
// outside the Kernel and Hardware Services package.
|
sl@0
|
20 |
//
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
#ifndef __K32POWER_H__
|
sl@0
|
24 |
#define __K32POWER_H__
|
sl@0
|
25 |
|
sl@0
|
26 |
#include <e32power.h>
|
sl@0
|
27 |
#include <kernel/kernel.h>
|
sl@0
|
28 |
|
sl@0
|
29 |
/**
|
sl@0
|
30 |
@internalTechnology
|
sl@0
|
31 |
*/
|
sl@0
|
32 |
#define __PM_ASSERT(aCond) \
|
sl@0
|
33 |
__ASSERT_DEBUG( (aCond), \
|
sl@0
|
34 |
( \
|
sl@0
|
35 |
Kern::Printf("Assertion '" #aCond "' failed;\nFile: '" __FILE__ "' Line: %d\n", __LINE__), \
|
sl@0
|
36 |
Kern::Fault("Power Management", 0) \
|
sl@0
|
37 |
) )
|
sl@0
|
38 |
|
sl@0
|
39 |
/**
|
sl@0
|
40 |
@internalTechnology
|
sl@0
|
41 |
*/
|
sl@0
|
42 |
#define __PM_PANIC(aMsg) \
|
sl@0
|
43 |
(\
|
sl@0
|
44 |
Kern::Printf("PANIC:'" aMsg "';\nFile: '" __FILE__ "' Line: %d\n", __LINE__), \
|
sl@0
|
45 |
Kern::Fault("Power Management", 0) \
|
sl@0
|
46 |
)
|
sl@0
|
47 |
|
sl@0
|
48 |
|
sl@0
|
49 |
|
sl@0
|
50 |
|
sl@0
|
51 |
/**
|
sl@0
|
52 |
@publishedPartner
|
sl@0
|
53 |
@released
|
sl@0
|
54 |
|
sl@0
|
55 |
Interface and support functions for a power controller implementation.
|
sl@0
|
56 |
|
sl@0
|
57 |
A power controller implementation depends on the specific power management
|
sl@0
|
58 |
hardware and is typically variant-dependent.
|
sl@0
|
59 |
|
sl@0
|
60 |
The class defines the interface that any power controller implementation
|
sl@0
|
61 |
must provide to the generic kernel-side power manager.
|
sl@0
|
62 |
It also provides the power controller with an API to the power manager.
|
sl@0
|
63 |
*/
|
sl@0
|
64 |
class DPowerController : public DBase
|
sl@0
|
65 |
{
|
sl@0
|
66 |
public:
|
sl@0
|
67 |
IMPORT_C DPowerController();
|
sl@0
|
68 |
IMPORT_C void Register();
|
sl@0
|
69 |
IMPORT_C void WakeupEvent();
|
sl@0
|
70 |
#ifndef __X86__
|
sl@0
|
71 |
IMPORT_C TInt RegisterResourceController(DBase* aController, TInt aClientId);
|
sl@0
|
72 |
protected:
|
sl@0
|
73 |
struct SResourceControllerData
|
sl@0
|
74 |
{
|
sl@0
|
75 |
DBase* iResourceController;
|
sl@0
|
76 |
TInt iClientId;
|
sl@0
|
77 |
}iResourceControllerData;
|
sl@0
|
78 |
#endif
|
sl@0
|
79 |
public:
|
sl@0
|
80 |
|
sl@0
|
81 |
|
sl@0
|
82 |
/**
|
sl@0
|
83 |
The target power state of the last, possibly still not completed,
|
sl@0
|
84 |
kernel transition.
|
sl@0
|
85 |
*/
|
sl@0
|
86 |
volatile TPowerState iTargetState;
|
sl@0
|
87 |
public:
|
sl@0
|
88 |
|
sl@0
|
89 |
|
sl@0
|
90 |
/**
|
sl@0
|
91 |
Puts the CPU into the Idle mode.
|
sl@0
|
92 |
*/
|
sl@0
|
93 |
virtual void CpuIdle() = 0;
|
sl@0
|
94 |
|
sl@0
|
95 |
|
sl@0
|
96 |
/**
|
sl@0
|
97 |
Enables wakeup events.
|
sl@0
|
98 |
|
sl@0
|
99 |
When called, iTargetState is guaranteed NOT to be equal to EPwActive.
|
sl@0
|
100 |
|
sl@0
|
101 |
After this call, and until a DisableWakeupEvents() or PowerDown() call,
|
sl@0
|
102 |
the power controller must track and signal wakeup events corresponding
|
sl@0
|
103 |
to iTargetState.
|
sl@0
|
104 |
|
sl@0
|
105 |
@see DPowerController::iTargetState
|
sl@0
|
106 |
@see TPowerState
|
sl@0
|
107 |
*/
|
sl@0
|
108 |
virtual void EnableWakeupEvents() = 0;
|
sl@0
|
109 |
|
sl@0
|
110 |
|
sl@0
|
111 |
/**
|
sl@0
|
112 |
Disables wakeup events.
|
sl@0
|
113 |
|
sl@0
|
114 |
When called, iTargetState is guaranteed to be equal to EPwActive.
|
sl@0
|
115 |
|
sl@0
|
116 |
After this call, the power controller must stop signalling wakeup events.
|
sl@0
|
117 |
|
sl@0
|
118 |
@see DPowerController::iTargetState
|
sl@0
|
119 |
@see TPowerState
|
sl@0
|
120 |
*/
|
sl@0
|
121 |
virtual void DisableWakeupEvents() = 0;
|
sl@0
|
122 |
|
sl@0
|
123 |
|
sl@0
|
124 |
/**
|
sl@0
|
125 |
Notifies an absolute timer expiration.
|
sl@0
|
126 |
|
sl@0
|
127 |
The power controller implementation must call WakeupEvent() if absolute
|
sl@0
|
128 |
timer expiration is currently tracking wakeup events.
|
sl@0
|
129 |
*/
|
sl@0
|
130 |
virtual void AbsoluteTimerExpired() = 0;
|
sl@0
|
131 |
|
sl@0
|
132 |
|
sl@0
|
133 |
/**
|
sl@0
|
134 |
Puts the CPU into the low power state.
|
sl@0
|
135 |
|
sl@0
|
136 |
When called, iTargetState is guaranteed NOT to be equal to EPwActive.
|
sl@0
|
137 |
|
sl@0
|
138 |
If iTargetState is EPwStandby, the power controller will put
|
sl@0
|
139 |
the hardware into standby.
|
sl@0
|
140 |
|
sl@0
|
141 |
If at least one wakeup event has been detected since the last
|
sl@0
|
142 |
call to EnableWakeupEvents(), then PowerDown() returns immediately;
|
sl@0
|
143 |
otherwise, PowerDown() returns when a wakeup event occurs.
|
sl@0
|
144 |
|
sl@0
|
145 |
When PowerDown() returns, wakeup events must be considered as disabled.
|
sl@0
|
146 |
|
sl@0
|
147 |
If iTargetState is EPwOff, then PowerDown() must never return.
|
sl@0
|
148 |
Typically, it turns the platform off, but may perform any other
|
sl@0
|
149 |
platform-specific action such as system reboot.
|
sl@0
|
150 |
|
sl@0
|
151 |
@param aWakeupTime If not zero, specifies the system time when
|
sl@0
|
152 |
the system will wakeup.
|
sl@0
|
153 |
|
sl@0
|
154 |
@see DPowerController::iTargetState
|
sl@0
|
155 |
@see TPowerState
|
sl@0
|
156 |
*/
|
sl@0
|
157 |
virtual void PowerDown(TTimeK aWakeupTime) = 0;
|
sl@0
|
158 |
};
|
sl@0
|
159 |
|
sl@0
|
160 |
#ifndef __X86__
|
sl@0
|
161 |
/**
|
sl@0
|
162 |
@internalTechnology
|
sl@0
|
163 |
@prototype 9.5
|
sl@0
|
164 |
*/
|
sl@0
|
165 |
class TPowerController
|
sl@0
|
166 |
{
|
sl@0
|
167 |
public:
|
sl@0
|
168 |
IMPORT_C static DPowerController* PowerController();
|
sl@0
|
169 |
public:
|
sl@0
|
170 |
static DPowerController* ThePowerController;
|
sl@0
|
171 |
};
|
sl@0
|
172 |
#endif
|
sl@0
|
173 |
|
sl@0
|
174 |
/**
|
sl@0
|
175 |
@internalTechnology
|
sl@0
|
176 |
*/
|
sl@0
|
177 |
class DBatteryMonitor
|
sl@0
|
178 |
{
|
sl@0
|
179 |
public:
|
sl@0
|
180 |
IMPORT_C DBatteryMonitor();
|
sl@0
|
181 |
IMPORT_C void Register();
|
sl@0
|
182 |
public:
|
sl@0
|
183 |
virtual TSupplyStatus MachinePowerStatus() = 0;
|
sl@0
|
184 |
virtual void SystemTimeChanged(TInt anOldTime, TInt aNewTime) = 0;
|
sl@0
|
185 |
};
|
sl@0
|
186 |
|
sl@0
|
187 |
/**
|
sl@0
|
188 |
@internalTechnology
|
sl@0
|
189 |
*/
|
sl@0
|
190 |
class DPowerHal : public DBase
|
sl@0
|
191 |
{
|
sl@0
|
192 |
public:
|
sl@0
|
193 |
IMPORT_C DPowerHal();
|
sl@0
|
194 |
IMPORT_C void Register();
|
sl@0
|
195 |
public:
|
sl@0
|
196 |
virtual TInt PowerHalFunction(TInt aFunction, TAny* a1, TAny* a2) = 0;
|
sl@0
|
197 |
};
|
sl@0
|
198 |
|
sl@0
|
199 |
|
sl@0
|
200 |
/**
|
sl@0
|
201 |
@publishedPartner
|
sl@0
|
202 |
@released
|
sl@0
|
203 |
|
sl@0
|
204 |
Interface and support functions for a device driver's power-handler.
|
sl@0
|
205 |
|
sl@0
|
206 |
There is typically one power handler object per peripheral. The object
|
sl@0
|
207 |
is typically implemented by the peripheral's device driver.
|
sl@0
|
208 |
|
sl@0
|
209 |
The class defines the interface that the driver must provide to
|
sl@0
|
210 |
the generic kernel-side power manager.
|
sl@0
|
211 |
|
sl@0
|
212 |
It also provides the driver with an API to the kernel-side power manager.
|
sl@0
|
213 |
*/
|
sl@0
|
214 |
class DPowerHandler : public DBase
|
sl@0
|
215 |
{
|
sl@0
|
216 |
public: // from DBase
|
sl@0
|
217 |
IMPORT_C ~DPowerHandler();
|
sl@0
|
218 |
public:
|
sl@0
|
219 |
IMPORT_C DPowerHandler(const TDesC& aName);
|
sl@0
|
220 |
IMPORT_C void Add();
|
sl@0
|
221 |
IMPORT_C void Remove();
|
sl@0
|
222 |
IMPORT_C void PowerUpDone();
|
sl@0
|
223 |
IMPORT_C void PowerDownDone();
|
sl@0
|
224 |
/** @deprecated, no replacement */
|
sl@0
|
225 |
IMPORT_C void SetCurrentConsumption(TInt aCurrent);
|
sl@0
|
226 |
/** @deprecated, no replacement */
|
sl@0
|
227 |
IMPORT_C void DeltaCurrentConsumption(TInt aCurrent);
|
sl@0
|
228 |
public:
|
sl@0
|
229 |
/**
|
sl@0
|
230 |
Requests peripheral power down.
|
sl@0
|
231 |
|
sl@0
|
232 |
The power manager calls PowerDown() during a transition to standby
|
sl@0
|
233 |
or power off.
|
sl@0
|
234 |
|
sl@0
|
235 |
The driver must signal the completion of peripheral power down to
|
sl@0
|
236 |
the power manager by calling PowerDownDone().
|
sl@0
|
237 |
Note that PowerDownDone() can be called from the path of PowerDown(),
|
sl@0
|
238 |
as well as asynchronously by another thread before or
|
sl@0
|
239 |
after PowerDown() returns.
|
sl@0
|
240 |
|
sl@0
|
241 |
Note that the implementation of Add() & Remove() acquires
|
sl@0
|
242 |
an internal lock (a DMutex), which is also held when the power manager
|
sl@0
|
243 |
calls PowerDown(). This means that the device driver cannot hold a lock
|
sl@0
|
244 |
over Add() & Remove() calls if the same lock is acquired
|
sl@0
|
245 |
by PowerDown() implementations.
|
sl@0
|
246 |
|
sl@0
|
247 |
You can find an example of synchronization between outgoing Add() & Remove()
|
sl@0
|
248 |
and incoming PowerDown() in e32/drivers/ecomm/d_comm.cpp.
|
sl@0
|
249 |
|
sl@0
|
250 |
@param aState the target power state; can be EPwStandby or EPwOff only
|
sl@0
|
251 |
*/
|
sl@0
|
252 |
virtual void PowerDown(TPowerState aState) = 0;
|
sl@0
|
253 |
|
sl@0
|
254 |
/**
|
sl@0
|
255 |
Notifies the peripheral of system power up.
|
sl@0
|
256 |
|
sl@0
|
257 |
The power manager calls PowerUp() during a transition from standby.
|
sl@0
|
258 |
|
sl@0
|
259 |
It is up to the device driver's policy whether to power up the periphiral or not.
|
sl@0
|
260 |
The driver must signal the completion of the operation to the power manager by calling PowerUpDone().
|
sl@0
|
261 |
Note that PowerUpDone() can be called from the path of PowerUp(), as well as asynchronously by another
|
sl@0
|
262 |
thread before or after PowerUp() returns.
|
sl@0
|
263 |
|
sl@0
|
264 |
Note that the implementation of Add() & Remove() acquires
|
sl@0
|
265 |
an internal lock (a DMutex), which is also held when the power manager
|
sl@0
|
266 |
calls PowerUp(). This means that the device driver cannot hold a lock
|
sl@0
|
267 |
over Add() & Remove() calls if the same lock is acquired
|
sl@0
|
268 |
by PowerUp() implementations.
|
sl@0
|
269 |
|
sl@0
|
270 |
You can find an example of synchronization between outgoing Add() & Remove()
|
sl@0
|
271 |
and incoming PowerUp() in e32/drivers/ecomm/d_comm.cpp.
|
sl@0
|
272 |
*/
|
sl@0
|
273 |
virtual void PowerUp() = 0;
|
sl@0
|
274 |
|
sl@0
|
275 |
private:
|
sl@0
|
276 |
friend class DPowerManager;
|
sl@0
|
277 |
|
sl@0
|
278 |
typedef TUint8 TStatus;
|
sl@0
|
279 |
enum { EDone = 0x01 };
|
sl@0
|
280 |
|
sl@0
|
281 |
void Wait();
|
sl@0
|
282 |
void Done();
|
sl@0
|
283 |
|
sl@0
|
284 |
const TDesC& iName;
|
sl@0
|
285 |
DPowerHandler* iNext;
|
sl@0
|
286 |
DPowerHandler* iPrev;
|
sl@0
|
287 |
NFastSemaphore* iSem;
|
sl@0
|
288 |
TStatus iStatus;
|
sl@0
|
289 |
TUint8 i_DPowerHandler_Spare[3];
|
sl@0
|
290 |
TInt iCurrent;
|
sl@0
|
291 |
};
|
sl@0
|
292 |
|
sl@0
|
293 |
|
sl@0
|
294 |
|
sl@0
|
295 |
|
sl@0
|
296 |
/**
|
sl@0
|
297 |
@publishedPartner
|
sl@0
|
298 |
@released
|
sl@0
|
299 |
|
sl@0
|
300 |
The recommended interface for objects that represent shared power sources.
|
sl@0
|
301 |
|
sl@0
|
302 |
The objects representing shared power sources are typically implemented by
|
sl@0
|
303 |
the variant and used by device drivers.
|
sl@0
|
304 |
|
sl@0
|
305 |
We recommend that these objects implement the MPowerInput interface.
|
sl@0
|
306 |
*/
|
sl@0
|
307 |
class MPowerInput
|
sl@0
|
308 |
{
|
sl@0
|
309 |
public:
|
sl@0
|
310 |
|
sl@0
|
311 |
|
sl@0
|
312 |
/**
|
sl@0
|
313 |
Signals that the power source is in use.
|
sl@0
|
314 |
|
sl@0
|
315 |
Typically, a driver calls this function when it needs the source
|
sl@0
|
316 |
to be powered on.
|
sl@0
|
317 |
|
sl@0
|
318 |
A typical implementation associates a counter with the object.
|
sl@0
|
319 |
The initial counter's value is 0. Use() increments the counter and, if
|
sl@0
|
320 |
the counter's value changes from 0 to 1, powers on the source.
|
sl@0
|
321 |
*/
|
sl@0
|
322 |
virtual void Use() = 0;
|
sl@0
|
323 |
|
sl@0
|
324 |
|
sl@0
|
325 |
/**
|
sl@0
|
326 |
Signals that the power source is not in use.
|
sl@0
|
327 |
|
sl@0
|
328 |
Typically, a driver calls this function when it no longer needs
|
sl@0
|
329 |
the source to be powered on.
|
sl@0
|
330 |
|
sl@0
|
331 |
A typical implementation associates a counter with the object.
|
sl@0
|
332 |
The initial counter's value is 0. While the implementation of
|
sl@0
|
333 |
Use() would increment the counter, Release() would decrement it.
|
sl@0
|
334 |
If the counter's value changes from 1 to 0, Release() powers off
|
sl@0
|
335 |
the source.
|
sl@0
|
336 |
*/
|
sl@0
|
337 |
virtual void Release() = 0;
|
sl@0
|
338 |
};
|
sl@0
|
339 |
|
sl@0
|
340 |
//
|
sl@0
|
341 |
// Kernel private
|
sl@0
|
342 |
//
|
sl@0
|
343 |
|
sl@0
|
344 |
/**
|
sl@0
|
345 |
@internalAll
|
sl@0
|
346 |
*/
|
sl@0
|
347 |
class DPowerModel : public DBase
|
sl@0
|
348 |
{
|
sl@0
|
349 |
public:
|
sl@0
|
350 |
virtual void AbsoluteTimerExpired() = 0;
|
sl@0
|
351 |
virtual void RegisterUserActivity(const TRawEvent& anEvent) = 0;
|
sl@0
|
352 |
public:
|
sl@0
|
353 |
virtual void CpuIdle() = 0;
|
sl@0
|
354 |
public:
|
sl@0
|
355 |
virtual void SystemTimeChanged(TInt anOldTime, TInt aNewTime) = 0;
|
sl@0
|
356 |
virtual TSupplyStatus MachinePowerStatus() = 0;
|
sl@0
|
357 |
public:
|
sl@0
|
358 |
virtual TInt PowerHalFunction(TInt aFunction, TAny* a1, TAny* a2) = 0;
|
sl@0
|
359 |
};
|
sl@0
|
360 |
|
sl@0
|
361 |
TInt PowerModelInit();
|
sl@0
|
362 |
|
sl@0
|
363 |
#endif
|
sl@0
|
364 |
|