os/kernelhwsrv/kerneltest/e32test/benchmark/bm_mi920_pdd.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 <integratorap.h>
    18 #include <iolines.h>
    19 
    20 //	NOTE:
    21 //	We use 2 different timers on this test:
    22 //		1) the Core module FRC - 32-bit clocked at 24MHz, non-interruptible, for the time stamps
    23 //		2) IntegratorAP Timer 1 - 16-bit, clocked at 1.5MHz , interruptible, for the Interrupts latency measurements
    24 //
    25 
    26 #define KHwFrcFreqHz	24000000			// uses the core module FRC clocked at 24MHz
    27 #define KHwApFreqHz		24000000			// uses the IntegratorAP Timer 1 clocked at 24MHz
    28 
    29 #include "k32bm.h"
    30 
    31 class DBMMi920Device : public DPhysicalDevice
    32 	{
    33 public:
    34 	DBMMi920Device();
    35 	virtual TInt Install();
    36 	virtual void GetCaps(TDes8& aDes) const;
    37 	virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    38 	virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    39 	};
    40 
    41 class DBMMi920Channel : public DBMPChannel
    42 	{
    43 public:
    44 	DBMMi920Channel();
    45 	~DBMMi920Channel();
    46 	TInt InitialiseTimer();
    47 	virtual TBMTicks TimerPeriod();
    48 	virtual TBMTicks TimerStamp();
    49 	virtual TBMNs TimerTicksToNs(TBMTicks);
    50 	virtual TBMTicks TimerNsToTicks(TBMNs);
    51 	virtual TInt BindInterrupt(MBMIsr*);
    52 	virtual TInt BindInterrupt(MBMInterruptLatencyIsr*);
    53 	virtual void RequestInterrupt();
    54 	virtual void CancelInterrupt();
    55 
    56 private:
    57 
    58 	static void ClearAp1TimerInt();
    59 	TInt BindInterrupt();
    60 
    61 	static const TBMTicks	KBMMi920FrcPeriod = (((TBMTicks) 1) << 32);				// FRC
    62 	static const TUint		KBMMi920ApPeriod = (((TBMTicks) 1) << 16);				// FRC
    63 	static const TBMNs		KBMMi920NsPerTick = (1000*1000*1000) / KHwFrcFreqHz;	// FRC
    64 	static const TUint		KBMMi920InterruptDelayTicks = KHwApFreqHz / 1000;		// 1ms in AP Timer 1 ticks
    65 	
    66 	static void Isr(TAny*);
    67 	
    68 	MBMIsr*						iIsr;
    69 	MBMInterruptLatencyIsr*		iInterruptLatencyIsr;
    70 	TInt				iInterruptId;
    71 	};
    72 
    73 DECLARE_STANDARD_PDD()
    74 //
    75 // Create a new device
    76 //
    77 	{
    78 	__ASSERT_CRITICAL;
    79 	return new DBMMi920Device;
    80 	}
    81 
    82 DBMMi920Device::DBMMi920Device()
    83 //
    84 // Constructor
    85 //
    86 	{
    87 	//iUnitsMask=0;
    88 	iVersion = TVersion(1,0,1);
    89 	}
    90 
    91 TInt DBMMi920Device::Install()
    92 //
    93 // Install the device driver.
    94 //
    95 	{
    96 	TInt r = SetName(&KBMPdName);
    97 	return r;
    98 	}
    99 
   100 void DBMMi920Device::GetCaps(TDes8& aDes) const
   101 //
   102 // Return the Comm capabilities.
   103 //
   104 	{
   105 	}
   106 
   107 TInt DBMMi920Device::Create(DBase*& aChannel, TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
   108 //
   109 // Create a channel on the device.
   110 //
   111 	{
   112 	__ASSERT_CRITICAL;
   113 	DBMMi920Channel* pD= new DBMMi920Channel;
   114 	aChannel = pD;
   115 	TInt r=KErrNoMemory;
   116 	if (pD)
   117 		r=pD->InitialiseTimer();
   118 	return r;
   119 	}
   120 
   121 TInt DBMMi920Device::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
   122 	{
   123 	if (!Kern::QueryVersionSupported(iVersion,aVer))
   124 		{
   125 		return KErrNotSupported;
   126 		}
   127 	return KErrNone;
   128 	}
   129 
   130 void DBMMi920Channel::ClearAp1TimerInt()
   131 	{
   132 	do
   133 		TIntegratorAP::ClearTimerInt(TIntegratorAP::ECounterTimer1);
   134 		// WARNING: Integrator bug! The timer interrupts are not always cleared the first time round
   135 		// so keep on clearing them until they are no longer active.
   136 	while (*(volatile TUint*)(KHwIrqBaseSet0) & KHtIntTimer1);
   137 	}
   138 
   139 DBMMi920Channel::DBMMi920Channel()
   140 	{
   141 	//	iIsr = NULL;
   142 	//	iInterruptLatencyIsr = NULL;
   143 	iInterruptId = KIntIdMatchGeneral2;
   144 	}
   145 
   146 DBMMi920Channel::~DBMMi920Channel()
   147 	{
   148 	// Disable the IntegratorAP Timer 1 and associated interrupt
   149 	if (iIsr || iInterruptLatencyIsr)
   150 		{
   151 		ClearAp1TimerInt();
   152 		Interrupt::Disable(iInterruptId);
   153 		Interrupt::Unbind(iInterruptId);
   154 		}
   155 	TIntegratorAP::EnableTimer(TIntegratorAP::ECounterTimer1, TIntegratorAP::EDisable);
   156 	}
   157 
   158 TInt DBMMi920Channel::InitialiseTimer()
   159 	{
   160 	// Set up the IntegratorAP Timer 1 to run at 1.5MHz, free-running mode, and enable it
   161     TIntegratorAP::SetTimerMode(TIntegratorAP::ECounterTimer1, TIntegratorAP::ETimerModeFreeRunning);
   162 	TIntegratorAP::SetTimerPreScale(TIntegratorAP::ECounterTimer1, TIntegratorAP::ETimerPreScaleNone);	// 24MHz
   163     TIntegratorAP::EnableTimer(TIntegratorAP::ECounterTimer1, TIntegratorAP::EEnable);
   164 	return KErrNone;
   165 	}
   166 
   167 TBMTicks DBMMi920Channel::TimerPeriod()
   168 	{
   169 	return KBMMi920FrcPeriod;
   170 	}
   171 
   172 TBMTicks DBMMi920Channel::TimerStamp()
   173 	{
   174 	return (*(volatile TUint*)(KHwRwCoreClkCounter));		// FRC
   175 	}
   176 
   177 TBMNs DBMMi920Channel::TimerTicksToNs(TBMTicks ticks)
   178 	{
   179 	return ticks * KBMMi920NsPerTick;						// FRC
   180 	}
   181 
   182 TBMTicks DBMMi920Channel::TimerNsToTicks(TBMNs ns)
   183 	{
   184 	return ns / KBMMi920NsPerTick;							// FRC
   185 	}
   186 
   187 
   188 void DBMMi920Channel::Isr(TAny* ptr)
   189 	{
   190 	DBMMi920Channel* mCh = (DBMMi920Channel*) ptr;
   191 	BM_ASSERT(mCh->iIsr || mCh->iInterruptLatencyIsr);
   192 	if (mCh->iIsr)
   193 		{
   194 		mCh->iIsr->Isr(*(volatile TUint*)(KHwRwCoreClkCounter));	// read timestamp off FRC
   195 		}
   196 	else
   197 		{ // calculate time elapsed between the interrupt going off and now in FRC ticks
   198 		TUint value = TIntegratorAP::TimerValue(TIntegratorAP::ECounterTimer1);
   199 		BM_ASSERT(((KHwFrcFreqHz/KHwApFreqHz)*KHwApFreqHz) == KHwFrcFreqHz);
   200 		mCh->iInterruptLatencyIsr->InterruptLatencyIsr((KBMMi920ApPeriod - value) * (KHwFrcFreqHz/KHwApFreqHz));
   201 		}
   202 	ClearAp1TimerInt();
   203 	Interrupt::Disable(mCh->iInterruptId);
   204 	}
   205 
   206 TInt DBMMi920Channel::BindInterrupt()
   207 	{
   208 	BM_ASSERT(iInterruptId==KIntIdMatchGeneral2);
   209 	TInt r=Interrupt::Bind(iInterruptId, Isr, this);
   210 	if (r<0)
   211 		{
   212 		return r;
   213 		}
   214 	iInterruptId = r;
   215 	return KErrNone;
   216 	}
   217 
   218 TInt DBMMi920Channel::BindInterrupt(MBMIsr* aIsr)
   219 	{
   220 	BM_ASSERT(!iIsr);
   221 	BM_ASSERT(!iInterruptLatencyIsr);
   222 	iIsr = aIsr;
   223 	return BindInterrupt();
   224 	}
   225 
   226 TInt DBMMi920Channel::BindInterrupt(MBMInterruptLatencyIsr* aIsr)
   227 	{
   228 	BM_ASSERT(!iIsr);
   229 	BM_ASSERT(!iInterruptLatencyIsr);
   230 	iInterruptLatencyIsr = aIsr;
   231 	return BindInterrupt();
   232 	}
   233 
   234 
   235 void DBMMi920Channel::RequestInterrupt()
   236 	{
   237 	BM_ASSERT(iIsr || iInterruptLatencyIsr);
   238 	TIntegratorAP::SetTimerLoad(TIntegratorAP::ECounterTimer1, KBMMi920InterruptDelayTicks);
   239 	ClearAp1TimerInt();
   240 	Interrupt::Enable(iInterruptId);					// Timer interrupts on Integrator are always enabled!
   241 	}
   242 
   243 void DBMMi920Channel::CancelInterrupt()
   244 	{	
   245 	if (iIsr || iInterruptLatencyIsr)
   246 		{
   247 		TIntegratorAP::EnableTimer(TIntegratorAP::ECounterTimer1, TIntegratorAP::EDisable);
   248 		}
   249 	}
   250