|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 // template\template_variant\inc\template_power.h |
|
15 // Template Power Management Header |
|
16 // (see also assp.cpp for a discussion on Sleep modes and xyin.cpp for example |
|
17 // of usage of Resource Manager and Peripheral self power down and interaction |
|
18 // with Power Controller for Wakeup Events) |
|
19 // |
|
20 // |
|
21 |
|
22 #ifndef __PM_STD_H__ |
|
23 #define __PM_STD_H__ |
|
24 #include <kernel/kpower.h> |
|
25 #include "variant.h" |
|
26 |
|
27 // |
|
28 // TO DO: (mandatory) |
|
29 // |
|
30 // Definition of the DPowerController derived class |
|
31 // |
|
32 NONSHARABLE_CLASS(DTemplatePowerController) : public DPowerController |
|
33 { |
|
34 public: // from DPowerController |
|
35 void CpuIdle(); |
|
36 void EnableWakeupEvents(); |
|
37 void AbsoluteTimerExpired(); |
|
38 void DisableWakeupEvents(); |
|
39 void PowerDown(TTimeK aWakeupTime); |
|
40 public: |
|
41 DTemplatePowerController(); |
|
42 private: |
|
43 void DoStandby(TBool aTimed, TUint32 aWakeupRTC); |
|
44 public: |
|
45 TBool iWakeupEventsOn; |
|
46 }; |
|
47 |
|
48 // |
|
49 // TO DO: (optional) |
|
50 // |
|
51 // If you need to access to the Power Controller from Drivers/Extensions/Variant |
|
52 // or access to Resource Manager then define an accessor class as below |
|
53 // |
|
54 |
|
55 class TemplateResourceManager; |
|
56 |
|
57 class TTemplatePowerController |
|
58 { |
|
59 public: |
|
60 // to allow Variant/Drivers/Extensions access to Resource Manager |
|
61 IMPORT_C static TemplateResourceManager* ResourceManager(); |
|
62 // used by drivers/extensions to signal a wakeup event to Power Controller |
|
63 IMPORT_C static void WakeupEvent(); |
|
64 |
|
65 inline static void RegisterPowerController(DTemplatePowerController* aPowerController); |
|
66 private: |
|
67 static DTemplatePowerController* iPowerController; |
|
68 }; |
|
69 |
|
70 NONSHARABLE_CLASS(SharedBinaryResource1) : public MPowerInput |
|
71 { |
|
72 public: // from MPowerInput |
|
73 void Use(); |
|
74 void Release(); |
|
75 public: |
|
76 TUint GetCount(); // gets current usage count |
|
77 private: |
|
78 TUint iCount; |
|
79 }; |
|
80 |
|
81 // Prototype class for Multilevel resources |
|
82 |
|
83 class MSharedMultilevelResource // Multilevel Shared Input |
|
84 { |
|
85 public: |
|
86 virtual void IncreaseToLevel(TUint aLevel, TInt aRequester) = 0; |
|
87 virtual void ReduceToLevel(TUint aLevel, TInt aRequester) = 0; |
|
88 virtual TUint GetResourceLevel() = 0; |
|
89 }; |
|
90 |
|
91 // EXAMPLE ONLY |
|
92 const TUint KSharers = 3; |
|
93 |
|
94 NONSHARABLE_CLASS(SharedMultilevelResource1) : public MSharedMultilevelResource |
|
95 { |
|
96 public: |
|
97 enum TRequesterId |
|
98 { |
|
99 // |
|
100 // Identify all possible users of this resource |
|
101 // |
|
102 ERequesterX = 0, |
|
103 ERequesterY = 1, |
|
104 ERequesterZ = 2 |
|
105 }; |
|
106 SharedMultilevelResource1(); |
|
107 public: // from MSharedMultilevelResource |
|
108 void IncreaseToLevel(TUint aLevel, TInt aRequester); |
|
109 void ReduceToLevel(TUint aLevel, TInt aRequester); |
|
110 TUint GetResourceLevel(); |
|
111 private: |
|
112 void FindMaxLevel(TUint* aLevel, TInt* aId); |
|
113 private: |
|
114 TUint Levels[KSharers]; // one element per user of resource |
|
115 TUint iCurrentLevel; |
|
116 TInt iCurrentLevelOwnerId; |
|
117 }; |
|
118 |
|
119 // |
|
120 // TO DO: (optional) |
|
121 // |
|
122 // The Resource Manager class |
|
123 // |
|
124 NONSHARABLE_CLASS(TemplateResourceManager) |
|
125 { |
|
126 public: |
|
127 enum TResource // a list of controllable resources (e.g clocks, voltages, power lines) |
|
128 { |
|
129 SynchBinResourceUsedByZOnly, |
|
130 AsynchBinResourceUsedByZOnly, |
|
131 // ... other non-shared binary resources, synchronous or asynchronous |
|
132 BinResourceSharedByZAndY, |
|
133 // ... other shared binary resources, synchronous or asynchronous |
|
134 SynchMlResourceUsedByXOnly, |
|
135 AsynchMlResourceUsedByXOnly, |
|
136 // ... other non-shared multilevel resources, synchronous or asynchronous |
|
137 MlResourceSharedByXAndW, |
|
138 // ... other shared multilevel resources, synchronous or asynchronous |
|
139 }; |
|
140 enum TSleepModes |
|
141 { |
|
142 Snooze, |
|
143 // ... |
|
144 Sleep, |
|
145 // ... |
|
146 DeepSleep, |
|
147 // ... |
|
148 Coma |
|
149 }; |
|
150 |
|
151 void InitResources(); // initialises power Resources not initialised by Bootstrap |
|
152 |
|
153 inline TSleepModes MapSleepMode(TInt aSleepPeriod); |
|
154 |
|
155 // interface for non-shared shared resources |
|
156 |
|
157 inline void Modify(TResource aResource, TBool aOnOff); // for non-shared binary resources |
|
158 inline void ModifyToLevel(TResource aResource, TInt aLevel); // for non-shared multilevel resources |
|
159 // the following functions may be used by Drivers/Extensions or the Idle routine to |
|
160 // determine what resources are On or Off or their levels |
|
161 inline TBool GetResourceState(TResource aResource); // for non-shared binary resources |
|
162 inline TUint GetResourceLevel(TResource aResource); // for non-shared multilevel resources |
|
163 public: |
|
164 // interface for shared resources |
|
165 |
|
166 SharedBinaryResource1 iSharedBResource1; |
|
167 // ... other shared Binary resources, synchronous or asynchronous |
|
168 inline SharedBinaryResource1* SharedBResource1(); |
|
169 |
|
170 SharedMultilevelResource1 iSharedMlResource1; |
|
171 // ... other shared Multilevel resources |
|
172 inline SharedMultilevelResource1* SharedMlResource1(); |
|
173 }; |
|
174 |
|
175 #include "template_power.inl" |
|
176 |
|
177 #endif |