1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/benchmark/bm_wins_pdd.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,197 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "k32bm.h"
1.20 +
1.21 +#include <emulator.h>
1.22 +
1.23 +class DBMWinsDevice : public DPhysicalDevice
1.24 + {
1.25 +public:
1.26 + DBMWinsDevice();
1.27 + virtual TInt Install();
1.28 + virtual void GetCaps(TDes8& aDes) const;
1.29 + virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
1.30 + virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
1.31 + };
1.32 +
1.33 +class DBMWinsChannel : public DBMPChannel
1.34 + {
1.35 +public:
1.36 + DBMWinsChannel();
1.37 + ~DBMWinsChannel();
1.38 + virtual TBMTicks TimerPeriod();
1.39 + virtual TBMTicks TimerStamp();
1.40 + virtual TBMNs TimerTicksToNs(TBMTicks);
1.41 + virtual TBMTicks TimerNsToTicks(TBMNs);
1.42 + virtual TInt BindInterrupt(MBMIsr*);
1.43 + virtual TInt BindInterrupt(MBMInterruptLatencyIsr*);
1.44 + virtual void RequestInterrupt();
1.45 + virtual void CancelInterrupt();
1.46 +
1.47 +private:
1.48 +
1.49 + static const TInt KBMWinsInterruptDelayMs;
1.50 + static const TBMNs KBMWinsNsPerTick;
1.51 + static const TBMTicks KBMWinsPeriod;
1.52 +
1.53 + static void Isr(TAny*);
1.54 + static void InterruptLatencyIsr(TAny*);
1.55 +
1.56 + TInt iRequestedTime;
1.57 + MBMIsr* iIsr;
1.58 + MBMInterruptLatencyIsr* iInterruptLatencyIsr;
1.59 + NTimer iTimer;
1.60 + };
1.61 +
1.62 +const TInt DBMWinsChannel::KBMWinsInterruptDelayMs = 4;
1.63 +const TBMNs DBMWinsChannel::KBMWinsNsPerTick = 100;
1.64 +const TBMTicks DBMWinsChannel::KBMWinsPeriod = (((TBMTicks) 1) << 32);
1.65 +
1.66 +DECLARE_STANDARD_PDD()
1.67 +//
1.68 +// Create a new device
1.69 +//
1.70 + {
1.71 + __ASSERT_CRITICAL;
1.72 + return new DBMWinsDevice;
1.73 + }
1.74 +
1.75 +DBMWinsDevice::DBMWinsDevice()
1.76 +//
1.77 +// Constructor
1.78 +//
1.79 + {
1.80 + //iUnitsMask=0;
1.81 + iVersion = TVersion(1,0,1);
1.82 + }
1.83 +
1.84 +TInt DBMWinsDevice::Install()
1.85 +//
1.86 +// Install the device driver.
1.87 +//
1.88 + {
1.89 + TInt r = SetName(&KBMPdName);
1.90 + return r;
1.91 + }
1.92 +
1.93 +void DBMWinsDevice::GetCaps(TDes8&) const
1.94 +//
1.95 +// Return the Comm capabilities.
1.96 +//
1.97 + {
1.98 + }
1.99 +
1.100 +TInt DBMWinsDevice::Create(DBase*& aChannel, TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
1.101 +//
1.102 +// Create a channel on the device.
1.103 +//
1.104 + {
1.105 + __ASSERT_CRITICAL;
1.106 + aChannel = new DBMWinsChannel();
1.107 + return aChannel ? KErrNone : KErrNoMemory;
1.108 + }
1.109 +
1.110 +TInt DBMWinsDevice::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
1.111 + {
1.112 + if (!Kern::QueryVersionSupported(iVersion,aVer))
1.113 + {
1.114 + return KErrNotSupported;
1.115 + }
1.116 + return KErrNone;
1.117 + }
1.118 +
1.119 +DBMWinsChannel::DBMWinsChannel() : iTimer(Isr, this)
1.120 + {
1.121 + // iIsr = NULL;
1.122 + // iInterruptLatencyIsr = NULL;
1.123 + }
1.124 +
1.125 +DBMWinsChannel::~DBMWinsChannel()
1.126 + {
1.127 + }
1.128 +
1.129 +TBMTicks DBMWinsChannel::TimerPeriod()
1.130 + {
1.131 + return KBMWinsPeriod;
1.132 + }
1.133 +
1.134 +TBMTicks DBMWinsChannel::TimerStamp()
1.135 + {
1.136 + FILETIME now;
1.137 + GetSystemTimeAsFileTime(&now);
1.138 + return now.dwLowDateTime;
1.139 + }
1.140 +
1.141 +TBMNs DBMWinsChannel::TimerTicksToNs(TBMTicks ticks)
1.142 + {
1.143 + return ticks * KBMWinsNsPerTick;
1.144 + }
1.145 +
1.146 +TBMTicks DBMWinsChannel::TimerNsToTicks(TBMNs ns)
1.147 + {
1.148 + return ns / KBMWinsNsPerTick;
1.149 + }
1.150 +
1.151 +void DBMWinsChannel::Isr(TAny* ptr)
1.152 + {
1.153 + FILETIME now;
1.154 + GetSystemTimeAsFileTime(&now);
1.155 + DBMWinsChannel* pCh = (DBMWinsChannel*) ptr;
1.156 + BM_ASSERT(pCh->iIsr);
1.157 + pCh->iIsr->Isr(now.dwLowDateTime);
1.158 + }
1.159 +
1.160 +TInt DBMWinsChannel::BindInterrupt(MBMIsr* aIsr)
1.161 + {
1.162 + BM_ASSERT(!iIsr);
1.163 + BM_ASSERT(!iInterruptLatencyIsr);
1.164 + iIsr = aIsr;
1.165 + return KErrNone;
1.166 + }
1.167 +
1.168 +void DBMWinsChannel::InterruptLatencyIsr(TAny* ptr)
1.169 + {
1.170 + FILETIME now;
1.171 + GetSystemTimeAsFileTime(&now);
1.172 + DBMWinsChannel* pCh = (DBMWinsChannel*) ptr;
1.173 + TBMTicks latency = now.dwLowDateTime - pCh->iRequestedTime;
1.174 + BM_ASSERT(pCh->iInterruptLatencyIsr);
1.175 + pCh->iInterruptLatencyIsr->InterruptLatencyIsr(latency);
1.176 + }
1.177 +
1.178 +TInt DBMWinsChannel::BindInterrupt(MBMInterruptLatencyIsr* aIsr)
1.179 + {
1.180 + BM_ASSERT(!iIsr);
1.181 + BM_ASSERT(!iInterruptLatencyIsr);
1.182 + iInterruptLatencyIsr = aIsr;
1.183 + iTimer.iFunction = InterruptLatencyIsr;
1.184 + return KErrNone;
1.185 + }
1.186 +
1.187 +void DBMWinsChannel::RequestInterrupt()
1.188 + {
1.189 + BM_ASSERT(iIsr || iInterruptLatencyIsr);
1.190 + FILETIME now;
1.191 + GetSystemTimeAsFileTime(&now);
1.192 + iRequestedTime = now.dwLowDateTime + ((KBMWinsInterruptDelayMs * ((1000 * 1000) / (TInt) KBMWinsNsPerTick)));
1.193 + iTimer.OneShot(KBMWinsInterruptDelayMs);
1.194 + }
1.195 +
1.196 +void DBMWinsChannel::CancelInterrupt()
1.197 + {
1.198 + iTimer.Cancel();
1.199 + }
1.200 +