First public contribution.
1 // Copyright (c) 2002-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.
20 class DBMWinsDevice : public DPhysicalDevice
24 virtual TInt Install();
25 virtual void GetCaps(TDes8& aDes) const;
26 virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
27 virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
30 class DBMWinsChannel : public DBMPChannel
35 virtual TBMTicks TimerPeriod();
36 virtual TBMTicks TimerStamp();
37 virtual TBMNs TimerTicksToNs(TBMTicks);
38 virtual TBMTicks TimerNsToTicks(TBMNs);
39 virtual TInt BindInterrupt(MBMIsr*);
40 virtual TInt BindInterrupt(MBMInterruptLatencyIsr*);
41 virtual void RequestInterrupt();
42 virtual void CancelInterrupt();
46 static const TInt KBMWinsInterruptDelayMs;
47 static const TBMNs KBMWinsNsPerTick;
48 static const TBMTicks KBMWinsPeriod;
50 static void Isr(TAny*);
51 static void InterruptLatencyIsr(TAny*);
55 MBMInterruptLatencyIsr* iInterruptLatencyIsr;
59 const TInt DBMWinsChannel::KBMWinsInterruptDelayMs = 4;
60 const TBMNs DBMWinsChannel::KBMWinsNsPerTick = 100;
61 const TBMTicks DBMWinsChannel::KBMWinsPeriod = (((TBMTicks) 1) << 32);
63 DECLARE_STANDARD_PDD()
65 // Create a new device
69 return new DBMWinsDevice;
72 DBMWinsDevice::DBMWinsDevice()
78 iVersion = TVersion(1,0,1);
81 TInt DBMWinsDevice::Install()
83 // Install the device driver.
86 TInt r = SetName(&KBMPdName);
90 void DBMWinsDevice::GetCaps(TDes8&) const
92 // Return the Comm capabilities.
97 TInt DBMWinsDevice::Create(DBase*& aChannel, TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
99 // Create a channel on the device.
103 aChannel = new DBMWinsChannel();
104 return aChannel ? KErrNone : KErrNoMemory;
107 TInt DBMWinsDevice::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
109 if (!Kern::QueryVersionSupported(iVersion,aVer))
111 return KErrNotSupported;
116 DBMWinsChannel::DBMWinsChannel() : iTimer(Isr, this)
119 // iInterruptLatencyIsr = NULL;
122 DBMWinsChannel::~DBMWinsChannel()
126 TBMTicks DBMWinsChannel::TimerPeriod()
128 return KBMWinsPeriod;
131 TBMTicks DBMWinsChannel::TimerStamp()
134 GetSystemTimeAsFileTime(&now);
135 return now.dwLowDateTime;
138 TBMNs DBMWinsChannel::TimerTicksToNs(TBMTicks ticks)
140 return ticks * KBMWinsNsPerTick;
143 TBMTicks DBMWinsChannel::TimerNsToTicks(TBMNs ns)
145 return ns / KBMWinsNsPerTick;
148 void DBMWinsChannel::Isr(TAny* ptr)
151 GetSystemTimeAsFileTime(&now);
152 DBMWinsChannel* pCh = (DBMWinsChannel*) ptr;
153 BM_ASSERT(pCh->iIsr);
154 pCh->iIsr->Isr(now.dwLowDateTime);
157 TInt DBMWinsChannel::BindInterrupt(MBMIsr* aIsr)
160 BM_ASSERT(!iInterruptLatencyIsr);
165 void DBMWinsChannel::InterruptLatencyIsr(TAny* ptr)
168 GetSystemTimeAsFileTime(&now);
169 DBMWinsChannel* pCh = (DBMWinsChannel*) ptr;
170 TBMTicks latency = now.dwLowDateTime - pCh->iRequestedTime;
171 BM_ASSERT(pCh->iInterruptLatencyIsr);
172 pCh->iInterruptLatencyIsr->InterruptLatencyIsr(latency);
175 TInt DBMWinsChannel::BindInterrupt(MBMInterruptLatencyIsr* aIsr)
178 BM_ASSERT(!iInterruptLatencyIsr);
179 iInterruptLatencyIsr = aIsr;
180 iTimer.iFunction = InterruptLatencyIsr;
184 void DBMWinsChannel::RequestInterrupt()
186 BM_ASSERT(iIsr || iInterruptLatencyIsr);
188 GetSystemTimeAsFileTime(&now);
189 iRequestedTime = now.dwLowDateTime + ((KBMWinsInterruptDelayMs * ((1000 * 1000) / (TInt) KBMWinsNsPerTick)));
190 iTimer.OneShot(KBMWinsInterruptDelayMs);
193 void DBMWinsChannel::CancelInterrupt()