os/kernelhwsrv/kerneltest/e32test/benchmark/bm_wins_pdd.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2002-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
//
sl@0
    15
sl@0
    16
#include "k32bm.h"
sl@0
    17
sl@0
    18
#include <emulator.h>
sl@0
    19
sl@0
    20
class DBMWinsDevice : public DPhysicalDevice
sl@0
    21
	{
sl@0
    22
public:
sl@0
    23
	DBMWinsDevice();
sl@0
    24
	virtual TInt Install();
sl@0
    25
	virtual void GetCaps(TDes8& aDes) const;
sl@0
    26
	virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
sl@0
    27
	virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
sl@0
    28
	};
sl@0
    29
sl@0
    30
class DBMWinsChannel : public DBMPChannel
sl@0
    31
	{
sl@0
    32
public:
sl@0
    33
	DBMWinsChannel();
sl@0
    34
	~DBMWinsChannel();
sl@0
    35
	virtual TBMTicks TimerPeriod();
sl@0
    36
	virtual TBMTicks TimerStamp();
sl@0
    37
	virtual TBMNs TimerTicksToNs(TBMTicks);
sl@0
    38
	virtual TBMTicks TimerNsToTicks(TBMNs);
sl@0
    39
	virtual TInt BindInterrupt(MBMIsr*);
sl@0
    40
	virtual TInt BindInterrupt(MBMInterruptLatencyIsr*);
sl@0
    41
	virtual void RequestInterrupt();
sl@0
    42
	virtual void CancelInterrupt();
sl@0
    43
sl@0
    44
private:
sl@0
    45
sl@0
    46
	static const TInt		KBMWinsInterruptDelayMs;
sl@0
    47
	static const TBMNs		KBMWinsNsPerTick;
sl@0
    48
	static const TBMTicks	KBMWinsPeriod;
sl@0
    49
sl@0
    50
	static void Isr(TAny*);
sl@0
    51
	static void InterruptLatencyIsr(TAny*);
sl@0
    52
sl@0
    53
	TInt						iRequestedTime;
sl@0
    54
	MBMIsr*						iIsr;
sl@0
    55
	MBMInterruptLatencyIsr*		iInterruptLatencyIsr;
sl@0
    56
	NTimer						iTimer;
sl@0
    57
	};
sl@0
    58
	
sl@0
    59
const TInt		DBMWinsChannel::KBMWinsInterruptDelayMs = 4;
sl@0
    60
const TBMNs		DBMWinsChannel::KBMWinsNsPerTick = 100;
sl@0
    61
const TBMTicks	DBMWinsChannel::KBMWinsPeriod = (((TBMTicks) 1) << 32);
sl@0
    62
sl@0
    63
DECLARE_STANDARD_PDD()
sl@0
    64
//
sl@0
    65
// Create a new device
sl@0
    66
//
sl@0
    67
	{
sl@0
    68
	__ASSERT_CRITICAL;
sl@0
    69
	return new DBMWinsDevice;
sl@0
    70
	}
sl@0
    71
sl@0
    72
DBMWinsDevice::DBMWinsDevice()
sl@0
    73
//
sl@0
    74
// Constructor
sl@0
    75
//
sl@0
    76
	{
sl@0
    77
	//iUnitsMask=0;
sl@0
    78
	iVersion = TVersion(1,0,1);
sl@0
    79
	}
sl@0
    80
sl@0
    81
TInt DBMWinsDevice::Install()
sl@0
    82
//
sl@0
    83
// Install the device driver.
sl@0
    84
//
sl@0
    85
	{
sl@0
    86
	TInt r = SetName(&KBMPdName);
sl@0
    87
	return r;
sl@0
    88
	}
sl@0
    89
sl@0
    90
void DBMWinsDevice::GetCaps(TDes8&) const
sl@0
    91
//
sl@0
    92
// Return the Comm capabilities.
sl@0
    93
//
sl@0
    94
	{
sl@0
    95
	}
sl@0
    96
sl@0
    97
TInt DBMWinsDevice::Create(DBase*& aChannel, TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
sl@0
    98
//
sl@0
    99
// Create a channel on the device.
sl@0
   100
//
sl@0
   101
	{
sl@0
   102
	__ASSERT_CRITICAL;
sl@0
   103
	aChannel = new DBMWinsChannel();
sl@0
   104
	return aChannel ? KErrNone : KErrNoMemory;
sl@0
   105
	}
sl@0
   106
sl@0
   107
TInt DBMWinsDevice::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
sl@0
   108
	{
sl@0
   109
	if (!Kern::QueryVersionSupported(iVersion,aVer))
sl@0
   110
		{
sl@0
   111
		return KErrNotSupported;
sl@0
   112
		}
sl@0
   113
	return KErrNone;
sl@0
   114
	}
sl@0
   115
sl@0
   116
DBMWinsChannel::DBMWinsChannel() : iTimer(Isr, this)
sl@0
   117
	{
sl@0
   118
	// iIsr = NULL;
sl@0
   119
	// iInterruptLatencyIsr = NULL;
sl@0
   120
	}
sl@0
   121
sl@0
   122
DBMWinsChannel::~DBMWinsChannel()
sl@0
   123
	{
sl@0
   124
	}
sl@0
   125
sl@0
   126
TBMTicks DBMWinsChannel::TimerPeriod()
sl@0
   127
	{
sl@0
   128
	return KBMWinsPeriod;
sl@0
   129
	}
sl@0
   130
sl@0
   131
TBMTicks DBMWinsChannel::TimerStamp()
sl@0
   132
	{
sl@0
   133
	FILETIME now;
sl@0
   134
	GetSystemTimeAsFileTime(&now);
sl@0
   135
	return now.dwLowDateTime; 
sl@0
   136
	}
sl@0
   137
sl@0
   138
TBMNs DBMWinsChannel::TimerTicksToNs(TBMTicks ticks)
sl@0
   139
	{
sl@0
   140
	return ticks * KBMWinsNsPerTick;
sl@0
   141
	}
sl@0
   142
sl@0
   143
TBMTicks DBMWinsChannel::TimerNsToTicks(TBMNs ns)
sl@0
   144
	{
sl@0
   145
	return ns / KBMWinsNsPerTick;
sl@0
   146
	}
sl@0
   147
sl@0
   148
void DBMWinsChannel::Isr(TAny* ptr)
sl@0
   149
	{
sl@0
   150
	FILETIME now;
sl@0
   151
	GetSystemTimeAsFileTime(&now);
sl@0
   152
	DBMWinsChannel* pCh = (DBMWinsChannel*) ptr;
sl@0
   153
	BM_ASSERT(pCh->iIsr);
sl@0
   154
	pCh->iIsr->Isr(now.dwLowDateTime);
sl@0
   155
	}
sl@0
   156
sl@0
   157
TInt DBMWinsChannel::BindInterrupt(MBMIsr* aIsr)
sl@0
   158
	{
sl@0
   159
	BM_ASSERT(!iIsr);
sl@0
   160
	BM_ASSERT(!iInterruptLatencyIsr);
sl@0
   161
	iIsr = aIsr;
sl@0
   162
	return KErrNone;
sl@0
   163
	}
sl@0
   164
sl@0
   165
void DBMWinsChannel::InterruptLatencyIsr(TAny* ptr)
sl@0
   166
	{
sl@0
   167
	FILETIME now;
sl@0
   168
	GetSystemTimeAsFileTime(&now);
sl@0
   169
	DBMWinsChannel* pCh = (DBMWinsChannel*) ptr;
sl@0
   170
	TBMTicks latency = now.dwLowDateTime - pCh->iRequestedTime;
sl@0
   171
	BM_ASSERT(pCh->iInterruptLatencyIsr);
sl@0
   172
	pCh->iInterruptLatencyIsr->InterruptLatencyIsr(latency);
sl@0
   173
	}
sl@0
   174
sl@0
   175
TInt DBMWinsChannel::BindInterrupt(MBMInterruptLatencyIsr* aIsr)
sl@0
   176
	{
sl@0
   177
	BM_ASSERT(!iIsr);
sl@0
   178
	BM_ASSERT(!iInterruptLatencyIsr);
sl@0
   179
	iInterruptLatencyIsr = aIsr;
sl@0
   180
	iTimer.iFunction = InterruptLatencyIsr;
sl@0
   181
	return KErrNone;
sl@0
   182
	}
sl@0
   183
sl@0
   184
void DBMWinsChannel::RequestInterrupt()
sl@0
   185
	{
sl@0
   186
	BM_ASSERT(iIsr || iInterruptLatencyIsr);
sl@0
   187
	FILETIME now;
sl@0
   188
	GetSystemTimeAsFileTime(&now);
sl@0
   189
	iRequestedTime = now.dwLowDateTime + ((KBMWinsInterruptDelayMs * ((1000 * 1000) / (TInt) KBMWinsNsPerTick)));
sl@0
   190
	iTimer.OneShot(KBMWinsInterruptDelayMs);
sl@0
   191
	}
sl@0
   192
	
sl@0
   193
void DBMWinsChannel::CancelInterrupt()
sl@0
   194
	{
sl@0
   195
	iTimer.Cancel();
sl@0
   196
	}
sl@0
   197