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