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