Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\drivers\power\binary\bpower.cpp
20 #include <kernel/kern_priv.h>
21 #include <kernel/kpower.h>
25 NONSHARABLE_CLASS(DBinaryBatteryMonitor) : public DBatteryMonitor
27 public: // from DBatteryMonitor
28 void SystemTimeChanged(TInt anOldTime, TInt aNewTime);
29 TSupplyStatus MachinePowerStatus();
31 DBinaryBatteryMonitor();
32 void SupplyInfo(TSupplyInfoV1& si);
34 DBinaryBatteryMonitor* BinaryBatteryMonitor;
36 NONSHARABLE_CLASS(DBinaryPowerHal) : public DPowerHal
38 public: // from DPowerHal
39 TInt PowerHalFunction(TInt aFunction, TAny* a1, TAny* a2);
45 DBinaryPowerHal* BinaryPowerHal;
47 DBinaryBatteryMonitor::DBinaryBatteryMonitor()
52 void DBinaryBatteryMonitor::SystemTimeChanged(TInt /* aOldTime */, TInt /* aNewTime */)
56 void DBinaryBatteryMonitor::SupplyInfo(TSupplyInfoV1& si)
58 si.iMainBatteryStatus = EZero;
59 si.iMainBatteryMilliVolts = 0;
60 si.iMainBatteryMaxMilliVolts = 0;
61 si.iBackupBatteryStatus = EZero;
62 si.iBackupBatteryMilliVolts = 0;
63 si.iBackupBatteryMaxMilliVolts = 0;
64 si.iMainBatteryInsertionTime = 0;
65 si.iMainBatteryInUseMicroSeconds = 0;
66 si.iMainBatteryConsumedMilliAmpSeconds = 0;
67 si.iExternalPowerPresent = 0;
68 si.iExternalPowerInUseMicroSeconds = 0;
69 si.iCurrentConsumptionMilliAmps = 0;
73 TSupplyStatus DBinaryBatteryMonitor::MachinePowerStatus()
79 DBinaryPowerHal::DBinaryPowerHal()
82 // initialise persistent data on cold start
83 if (Kern::ColdStart())
87 void DBinaryPowerHal::InitData()
89 TActualMachineConfig& mc = TheActualMachineConfig();
90 TOnOffInfoV1& i = mc.iOnOffInfo;
91 i.iPointerSwitchesOn = EFalse;
92 i.iCaseOpenSwitchesOn = EFalse;
93 i.iCaseCloseSwitchesOff = EFalse;
96 TInt DBinaryPowerHal::PowerHalFunction(TInt aFunction, TAny* a1, TAny* /* a2 */)
98 __KTRACE_OPT(KPOWER,Kern::Printf("DBinaryPowerHal::PowerHalFunction() func=0x%x, a1=0x%x", aFunction, a1));
99 TActualMachineConfig& mc=TheActualMachineConfig();
103 case EPowerHalSwitchOff:
104 if(!Kern::CurrentThreadHasCapability(ECapabilityPowerMgmt,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EPowerHalSwitchOff")))
105 return KErrPermissionDenied;
108 v.Set(TRawEvent::ESwitchOff);
112 case EPowerHalOnOffInfo:
113 Kern::InfoCopy(*(TDes8*)a1, (TUint8*)&mc.iOnOffInfo, sizeof(mc.iOnOffInfo));
115 case EPowerHalSupplyInfo:
118 BinaryBatteryMonitor->SupplyInfo(si);
119 Kern::InfoCopy(*(TDes8*)a1, (TUint8*)&si, sizeof(si));
122 case EPowerHalSetPointerSwitchesOn:
123 if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal Function EPowerHalSetPointerSwitchesOn")))
124 return KErrPermissionDenied;
125 mc.iOnOffInfo.iPointerSwitchesOn = (TUint8)(TUint)a1;
127 case EPowerHalPointerSwitchesOn:
128 kumemput32(a1, &mc.iOnOffInfo.iPointerSwitchesOn, sizeof(TBool));
130 case EPowerHalSetCaseOpenSwitchesOn:
131 if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EPowerHalSetCaseOpenSwitchesOn")))
132 return KErrPermissionDenied;
133 mc.iOnOffInfo.iCaseOpenSwitchesOn = (TUint8)(TUint)a1;
135 case EPowerHalCaseOpenSwitchesOn:
136 kumemput32(a1, &mc.iOnOffInfo.iCaseOpenSwitchesOn, sizeof(TBool));
138 case EPowerHalSetCaseCloseSwitchesOff:
139 if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EPowerHalSetCaseCloseSwitchesOff")))
140 return KErrPermissionDenied;
141 mc.iOnOffInfo.iCaseCloseSwitchesOff = (TUint8)(TUint)a1;
143 case EPowerHalCaseCloseSwitchesOff:
144 kumemput32(a1, &mc.iOnOffInfo.iCaseCloseSwitchesOff, sizeof(TBool));
146 case EPowerHalTestBootSequence:
149 case EPowerHalBackupPresent:
152 kumemput32(a1, &ret, sizeof(TBool));
155 case EPowerHalAcessoryPowerPresent:
158 kumemput32(a1, &ret, sizeof(TBool));
162 r = KErrNotSupported;
168 TInt BinaryPowerInit()
170 __KTRACE_OPT(KPOWER,Kern::Printf("BinaryPowerInit()"));
171 BinaryBatteryMonitor = new DBinaryBatteryMonitor();
172 if (!BinaryBatteryMonitor)
174 BinaryPowerHal = new DBinaryPowerHal();