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