sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "k32bm.h" sl@0: sl@0: #include sl@0: sl@0: class DBMWinsDevice : public DPhysicalDevice sl@0: { sl@0: public: sl@0: DBMWinsDevice(); sl@0: virtual TInt Install(); sl@0: virtual void GetCaps(TDes8& aDes) const; sl@0: virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); sl@0: virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); sl@0: }; sl@0: sl@0: class DBMWinsChannel : public DBMPChannel sl@0: { sl@0: public: sl@0: DBMWinsChannel(); sl@0: ~DBMWinsChannel(); sl@0: virtual TBMTicks TimerPeriod(); sl@0: virtual TBMTicks TimerStamp(); sl@0: virtual TBMNs TimerTicksToNs(TBMTicks); sl@0: virtual TBMTicks TimerNsToTicks(TBMNs); sl@0: virtual TInt BindInterrupt(MBMIsr*); sl@0: virtual TInt BindInterrupt(MBMInterruptLatencyIsr*); sl@0: virtual void RequestInterrupt(); sl@0: virtual void CancelInterrupt(); sl@0: sl@0: private: sl@0: sl@0: static const TInt KBMWinsInterruptDelayMs; sl@0: static const TBMNs KBMWinsNsPerTick; sl@0: static const TBMTicks KBMWinsPeriod; sl@0: sl@0: static void Isr(TAny*); sl@0: static void InterruptLatencyIsr(TAny*); sl@0: sl@0: TInt iRequestedTime; sl@0: MBMIsr* iIsr; sl@0: MBMInterruptLatencyIsr* iInterruptLatencyIsr; sl@0: NTimer iTimer; sl@0: }; sl@0: sl@0: const TInt DBMWinsChannel::KBMWinsInterruptDelayMs = 4; sl@0: const TBMNs DBMWinsChannel::KBMWinsNsPerTick = 100; sl@0: const TBMTicks DBMWinsChannel::KBMWinsPeriod = (((TBMTicks) 1) << 32); sl@0: sl@0: DECLARE_STANDARD_PDD() sl@0: // sl@0: // Create a new device sl@0: // sl@0: { sl@0: __ASSERT_CRITICAL; sl@0: return new DBMWinsDevice; sl@0: } sl@0: sl@0: DBMWinsDevice::DBMWinsDevice() sl@0: // sl@0: // Constructor sl@0: // sl@0: { sl@0: //iUnitsMask=0; sl@0: iVersion = TVersion(1,0,1); sl@0: } sl@0: sl@0: TInt DBMWinsDevice::Install() sl@0: // sl@0: // Install the device driver. sl@0: // sl@0: { sl@0: TInt r = SetName(&KBMPdName); sl@0: return r; sl@0: } sl@0: sl@0: void DBMWinsDevice::GetCaps(TDes8&) const sl@0: // sl@0: // Return the Comm capabilities. sl@0: // sl@0: { sl@0: } sl@0: sl@0: TInt DBMWinsDevice::Create(DBase*& aChannel, TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/) sl@0: // sl@0: // Create a channel on the device. sl@0: // sl@0: { sl@0: __ASSERT_CRITICAL; sl@0: aChannel = new DBMWinsChannel(); sl@0: return aChannel ? KErrNone : KErrNoMemory; sl@0: } sl@0: sl@0: TInt DBMWinsDevice::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer) sl@0: { sl@0: if (!Kern::QueryVersionSupported(iVersion,aVer)) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: DBMWinsChannel::DBMWinsChannel() : iTimer(Isr, this) sl@0: { sl@0: // iIsr = NULL; sl@0: // iInterruptLatencyIsr = NULL; sl@0: } sl@0: sl@0: DBMWinsChannel::~DBMWinsChannel() sl@0: { sl@0: } sl@0: sl@0: TBMTicks DBMWinsChannel::TimerPeriod() sl@0: { sl@0: return KBMWinsPeriod; sl@0: } sl@0: sl@0: TBMTicks DBMWinsChannel::TimerStamp() sl@0: { sl@0: FILETIME now; sl@0: GetSystemTimeAsFileTime(&now); sl@0: return now.dwLowDateTime; sl@0: } sl@0: sl@0: TBMNs DBMWinsChannel::TimerTicksToNs(TBMTicks ticks) sl@0: { sl@0: return ticks * KBMWinsNsPerTick; sl@0: } sl@0: sl@0: TBMTicks DBMWinsChannel::TimerNsToTicks(TBMNs ns) sl@0: { sl@0: return ns / KBMWinsNsPerTick; sl@0: } sl@0: sl@0: void DBMWinsChannel::Isr(TAny* ptr) sl@0: { sl@0: FILETIME now; sl@0: GetSystemTimeAsFileTime(&now); sl@0: DBMWinsChannel* pCh = (DBMWinsChannel*) ptr; sl@0: BM_ASSERT(pCh->iIsr); sl@0: pCh->iIsr->Isr(now.dwLowDateTime); sl@0: } sl@0: sl@0: TInt DBMWinsChannel::BindInterrupt(MBMIsr* aIsr) sl@0: { sl@0: BM_ASSERT(!iIsr); sl@0: BM_ASSERT(!iInterruptLatencyIsr); sl@0: iIsr = aIsr; sl@0: return KErrNone; sl@0: } sl@0: sl@0: void DBMWinsChannel::InterruptLatencyIsr(TAny* ptr) sl@0: { sl@0: FILETIME now; sl@0: GetSystemTimeAsFileTime(&now); sl@0: DBMWinsChannel* pCh = (DBMWinsChannel*) ptr; sl@0: TBMTicks latency = now.dwLowDateTime - pCh->iRequestedTime; sl@0: BM_ASSERT(pCh->iInterruptLatencyIsr); sl@0: pCh->iInterruptLatencyIsr->InterruptLatencyIsr(latency); sl@0: } sl@0: sl@0: TInt DBMWinsChannel::BindInterrupt(MBMInterruptLatencyIsr* aIsr) sl@0: { sl@0: BM_ASSERT(!iIsr); sl@0: BM_ASSERT(!iInterruptLatencyIsr); sl@0: iInterruptLatencyIsr = aIsr; sl@0: iTimer.iFunction = InterruptLatencyIsr; sl@0: return KErrNone; sl@0: } sl@0: sl@0: void DBMWinsChannel::RequestInterrupt() sl@0: { sl@0: BM_ASSERT(iIsr || iInterruptLatencyIsr); sl@0: FILETIME now; sl@0: GetSystemTimeAsFileTime(&now); sl@0: iRequestedTime = now.dwLowDateTime + ((KBMWinsInterruptDelayMs * ((1000 * 1000) / (TInt) KBMWinsNsPerTick))); sl@0: iTimer.OneShot(KBMWinsInterruptDelayMs); sl@0: } sl@0: sl@0: void DBMWinsChannel::CancelInterrupt() sl@0: { sl@0: iTimer.Cancel(); sl@0: } sl@0: