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\drivers\power\binary\bpower.cpp
|
sl@0
|
15 |
// Binary power model
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <assp.h>
|
sl@0
|
20 |
#include <kernel/kern_priv.h>
|
sl@0
|
21 |
#include <kernel/kpower.h>
|
sl@0
|
22 |
#include "mconf.h"
|
sl@0
|
23 |
#include <e32keys.h>
|
sl@0
|
24 |
|
sl@0
|
25 |
NONSHARABLE_CLASS(DBinaryBatteryMonitor) : public DBatteryMonitor
|
sl@0
|
26 |
{
|
sl@0
|
27 |
public: // from DBatteryMonitor
|
sl@0
|
28 |
void SystemTimeChanged(TInt anOldTime, TInt aNewTime);
|
sl@0
|
29 |
TSupplyStatus MachinePowerStatus();
|
sl@0
|
30 |
public:
|
sl@0
|
31 |
DBinaryBatteryMonitor();
|
sl@0
|
32 |
void SupplyInfo(TSupplyInfoV1& si);
|
sl@0
|
33 |
};
|
sl@0
|
34 |
DBinaryBatteryMonitor* BinaryBatteryMonitor;
|
sl@0
|
35 |
|
sl@0
|
36 |
NONSHARABLE_CLASS(DBinaryPowerHal) : public DPowerHal
|
sl@0
|
37 |
{
|
sl@0
|
38 |
public: // from DPowerHal
|
sl@0
|
39 |
TInt PowerHalFunction(TInt aFunction, TAny* a1, TAny* a2);
|
sl@0
|
40 |
public:
|
sl@0
|
41 |
DBinaryPowerHal();
|
sl@0
|
42 |
private:
|
sl@0
|
43 |
void InitData();
|
sl@0
|
44 |
};
|
sl@0
|
45 |
DBinaryPowerHal* BinaryPowerHal;
|
sl@0
|
46 |
|
sl@0
|
47 |
DBinaryBatteryMonitor::DBinaryBatteryMonitor()
|
sl@0
|
48 |
{
|
sl@0
|
49 |
Register();
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
void DBinaryBatteryMonitor::SystemTimeChanged(TInt /* aOldTime */, TInt /* aNewTime */)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
void DBinaryBatteryMonitor::SupplyInfo(TSupplyInfoV1& si)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
si.iMainBatteryStatus = EZero;
|
sl@0
|
59 |
si.iMainBatteryMilliVolts = 0;
|
sl@0
|
60 |
si.iMainBatteryMaxMilliVolts = 0;
|
sl@0
|
61 |
si.iBackupBatteryStatus = EZero;
|
sl@0
|
62 |
si.iBackupBatteryMilliVolts = 0;
|
sl@0
|
63 |
si.iBackupBatteryMaxMilliVolts = 0;
|
sl@0
|
64 |
si.iMainBatteryInsertionTime = 0;
|
sl@0
|
65 |
si.iMainBatteryInUseMicroSeconds = 0;
|
sl@0
|
66 |
si.iMainBatteryConsumedMilliAmpSeconds = 0;
|
sl@0
|
67 |
si.iExternalPowerPresent = 0;
|
sl@0
|
68 |
si.iExternalPowerInUseMicroSeconds = 0;
|
sl@0
|
69 |
si.iCurrentConsumptionMilliAmps = 0;
|
sl@0
|
70 |
si.iFlags = 0;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
TSupplyStatus DBinaryBatteryMonitor::MachinePowerStatus()
|
sl@0
|
74 |
{
|
sl@0
|
75 |
return EGood;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
|
sl@0
|
79 |
DBinaryPowerHal::DBinaryPowerHal()
|
sl@0
|
80 |
{
|
sl@0
|
81 |
Register();
|
sl@0
|
82 |
// initialise persistent data on cold start
|
sl@0
|
83 |
if (Kern::ColdStart())
|
sl@0
|
84 |
InitData();
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
void DBinaryPowerHal::InitData()
|
sl@0
|
88 |
{
|
sl@0
|
89 |
TActualMachineConfig& mc = TheActualMachineConfig();
|
sl@0
|
90 |
TOnOffInfoV1& i = mc.iOnOffInfo;
|
sl@0
|
91 |
i.iPointerSwitchesOn = EFalse;
|
sl@0
|
92 |
i.iCaseOpenSwitchesOn = EFalse;
|
sl@0
|
93 |
i.iCaseCloseSwitchesOff = EFalse;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
TInt DBinaryPowerHal::PowerHalFunction(TInt aFunction, TAny* a1, TAny* /* a2 */)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
__KTRACE_OPT(KPOWER,Kern::Printf("DBinaryPowerHal::PowerHalFunction() func=0x%x, a1=0x%x", aFunction, a1));
|
sl@0
|
99 |
TActualMachineConfig& mc=TheActualMachineConfig();
|
sl@0
|
100 |
TInt r=KErrNone;
|
sl@0
|
101 |
switch(aFunction)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
case EPowerHalSwitchOff:
|
sl@0
|
104 |
if(!Kern::CurrentThreadHasCapability(ECapabilityPowerMgmt,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EPowerHalSwitchOff")))
|
sl@0
|
105 |
return KErrPermissionDenied;
|
sl@0
|
106 |
{
|
sl@0
|
107 |
TRawEvent v;
|
sl@0
|
108 |
v.Set(TRawEvent::ESwitchOff);
|
sl@0
|
109 |
Kern::AddEvent(v);
|
sl@0
|
110 |
}
|
sl@0
|
111 |
break;
|
sl@0
|
112 |
case EPowerHalOnOffInfo:
|
sl@0
|
113 |
Kern::InfoCopy(*(TDes8*)a1, (TUint8*)&mc.iOnOffInfo, sizeof(mc.iOnOffInfo));
|
sl@0
|
114 |
break;
|
sl@0
|
115 |
case EPowerHalSupplyInfo:
|
sl@0
|
116 |
{
|
sl@0
|
117 |
TSupplyInfoV1 si;
|
sl@0
|
118 |
BinaryBatteryMonitor->SupplyInfo(si);
|
sl@0
|
119 |
Kern::InfoCopy(*(TDes8*)a1, (TUint8*)&si, sizeof(si));
|
sl@0
|
120 |
break;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
case EPowerHalSetPointerSwitchesOn:
|
sl@0
|
123 |
if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal Function EPowerHalSetPointerSwitchesOn")))
|
sl@0
|
124 |
return KErrPermissionDenied;
|
sl@0
|
125 |
mc.iOnOffInfo.iPointerSwitchesOn = (TUint8)(TUint)a1;
|
sl@0
|
126 |
break;
|
sl@0
|
127 |
case EPowerHalPointerSwitchesOn:
|
sl@0
|
128 |
kumemput32(a1, &mc.iOnOffInfo.iPointerSwitchesOn, sizeof(TBool));
|
sl@0
|
129 |
break;
|
sl@0
|
130 |
case EPowerHalSetCaseOpenSwitchesOn:
|
sl@0
|
131 |
if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EPowerHalSetCaseOpenSwitchesOn")))
|
sl@0
|
132 |
return KErrPermissionDenied;
|
sl@0
|
133 |
mc.iOnOffInfo.iCaseOpenSwitchesOn = (TUint8)(TUint)a1;
|
sl@0
|
134 |
break;
|
sl@0
|
135 |
case EPowerHalCaseOpenSwitchesOn:
|
sl@0
|
136 |
kumemput32(a1, &mc.iOnOffInfo.iCaseOpenSwitchesOn, sizeof(TBool));
|
sl@0
|
137 |
break;
|
sl@0
|
138 |
case EPowerHalSetCaseCloseSwitchesOff:
|
sl@0
|
139 |
if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EPowerHalSetCaseCloseSwitchesOff")))
|
sl@0
|
140 |
return KErrPermissionDenied;
|
sl@0
|
141 |
mc.iOnOffInfo.iCaseCloseSwitchesOff = (TUint8)(TUint)a1;
|
sl@0
|
142 |
break;
|
sl@0
|
143 |
case EPowerHalCaseCloseSwitchesOff:
|
sl@0
|
144 |
kumemput32(a1, &mc.iOnOffInfo.iCaseCloseSwitchesOff, sizeof(TBool));
|
sl@0
|
145 |
break;
|
sl@0
|
146 |
case EPowerHalTestBootSequence:
|
sl@0
|
147 |
r = EFalse;
|
sl@0
|
148 |
break;
|
sl@0
|
149 |
case EPowerHalBackupPresent:
|
sl@0
|
150 |
{
|
sl@0
|
151 |
TBool ret=EFalse;
|
sl@0
|
152 |
kumemput32(a1, &ret, sizeof(TBool));
|
sl@0
|
153 |
}
|
sl@0
|
154 |
break;
|
sl@0
|
155 |
case EPowerHalAcessoryPowerPresent:
|
sl@0
|
156 |
{
|
sl@0
|
157 |
TBool ret=EFalse;
|
sl@0
|
158 |
kumemput32(a1, &ret, sizeof(TBool));
|
sl@0
|
159 |
}
|
sl@0
|
160 |
break;
|
sl@0
|
161 |
default:
|
sl@0
|
162 |
r = KErrNotSupported;
|
sl@0
|
163 |
break;
|
sl@0
|
164 |
}
|
sl@0
|
165 |
return r;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
|
sl@0
|
168 |
TInt BinaryPowerInit()
|
sl@0
|
169 |
{
|
sl@0
|
170 |
__KTRACE_OPT(KPOWER,Kern::Printf("BinaryPowerInit()"));
|
sl@0
|
171 |
BinaryBatteryMonitor = new DBinaryBatteryMonitor();
|
sl@0
|
172 |
if (!BinaryBatteryMonitor)
|
sl@0
|
173 |
return KErrNoMemory;
|
sl@0
|
174 |
BinaryPowerHal = new DBinaryPowerHal();
|
sl@0
|
175 |
if (!BinaryPowerHal)
|
sl@0
|
176 |
return KErrNoMemory;
|
sl@0
|
177 |
return KErrNone;
|
sl@0
|
178 |
}
|