os/kernelhwsrv/kerneltest/e32test/benchmark/bm_misa_pdd.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/benchmark/bm_misa_pdd.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,213 @@
     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 <kernel/kernel.h>
    1.20 +#include <sa1100.h>
    1.21 +
    1.22 +#include "k32bm.h"
    1.23 +
    1.24 +class DBMMisaDevice : public DPhysicalDevice
    1.25 +	{
    1.26 +public:
    1.27 +	DBMMisaDevice();
    1.28 +	virtual TInt Install();
    1.29 +	virtual void GetCaps(TDes8& aDes) const;
    1.30 +	virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    1.31 +	virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    1.32 +	};
    1.33 +
    1.34 +class DBMMisaChannel : public DBMPChannel
    1.35 +	{
    1.36 +public:
    1.37 +	DBMMisaChannel();
    1.38 +	~DBMMisaChannel();
    1.39 +	virtual TBMTicks TimerPeriod();
    1.40 +	virtual TBMTicks TimerStamp();
    1.41 +	virtual TBMNs TimerTicksToNs(TBMTicks);
    1.42 +	virtual TBMTicks TimerNsToTicks(TBMNs);
    1.43 +	virtual TInt BindInterrupt(MBMIsr*);
    1.44 +	virtual TInt BindInterrupt(MBMInterruptLatencyIsr*);
    1.45 +	virtual void RequestInterrupt();
    1.46 +	virtual void CancelInterrupt();
    1.47 +
    1.48 +private:
    1.49 +
    1.50 +	TInt BindInterrupt();
    1.51 +
    1.52 +	static const TInt		KBMMisaInterruptDelayTicks = KHwOscFreqHz / 1000;
    1.53 +	static const TBMTicks	KBMMisaPeriod = (((TBMTicks) 1) << 32);
    1.54 +	static const TBMNs		KBMMisaNsPerTick = (1000*1000*1000) / KHwOscFreqHz;
    1.55 +	
    1.56 +	static void Isr(TAny*);
    1.57 +	
    1.58 +	MBMIsr*						iIsr;
    1.59 +	MBMInterruptLatencyIsr*		iInterruptLatencyIsr;
    1.60 +	};
    1.61 +
    1.62 +
    1.63 +DECLARE_STANDARD_PDD()
    1.64 +//
    1.65 +// Create a new device
    1.66 +//
    1.67 +	{
    1.68 +	__ASSERT_CRITICAL;
    1.69 +	return new DBMMisaDevice;
    1.70 +	}
    1.71 +
    1.72 +DBMMisaDevice::DBMMisaDevice()
    1.73 +//
    1.74 +// Constructor
    1.75 +//
    1.76 +	{
    1.77 +	//iUnitsMask=0;
    1.78 +	iVersion = TVersion(1,0,1);
    1.79 +	}
    1.80 +
    1.81 +TInt DBMMisaDevice::Install()
    1.82 +//
    1.83 +// Install the device driver.
    1.84 +//
    1.85 +	{
    1.86 +	TInt r = SetName(&KBMPdName);
    1.87 +	return r;
    1.88 +	}
    1.89 +
    1.90 +void DBMMisaDevice::GetCaps(TDes8& aDes) const
    1.91 +//
    1.92 +// Return the Comm capabilities.
    1.93 +//
    1.94 +	{
    1.95 +	}
    1.96 +
    1.97 +TInt DBMMisaDevice::Create(DBase*& aChannel, TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
    1.98 +//
    1.99 +// Create a channel on the device.
   1.100 +//
   1.101 +	{
   1.102 +	__ASSERT_CRITICAL;
   1.103 +	aChannel = new DBMMisaChannel;
   1.104 +	return aChannel?KErrNone:KErrNoMemory;
   1.105 +	}
   1.106 +
   1.107 +TInt DBMMisaDevice::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
   1.108 +	{
   1.109 +	if (!Kern::QueryVersionSupported(iVersion,aVer))
   1.110 +		{
   1.111 +		return KErrNotSupported;
   1.112 +		}
   1.113 +	return KErrNone;
   1.114 +	}
   1.115 +
   1.116 +DBMMisaChannel::DBMMisaChannel()
   1.117 +	{
   1.118 +	//	iIsr = NULL;
   1.119 +	//	iInterruptLatencyIsr = NULL;
   1.120 +	}
   1.121 +
   1.122 +DBMMisaChannel::~DBMMisaChannel()
   1.123 +	{
   1.124 +	if (iIsr || iInterruptLatencyIsr)
   1.125 +		{
   1.126 +		TSa1100::DisableOstInterrupt(KHwOstMatchGeneral);
   1.127 +		TSa1100::SetOstMatchEOI(KHwOstMatchGeneral);
   1.128 +		Interrupt::Disable(KIntIdOstMatchGeneral);
   1.129 +		TSa1100::ModifyIntLevels(KHtIntsOstMatchGeneral,0);
   1.130 +		Interrupt::Unbind(KIntIdOstMatchGeneral);
   1.131 +		}
   1.132 +	}
   1.133 +
   1.134 +TBMTicks DBMMisaChannel::TimerPeriod()
   1.135 +	{
   1.136 +	return KBMMisaPeriod;
   1.137 +	}
   1.138 +
   1.139 +TBMTicks DBMMisaChannel::TimerStamp()
   1.140 +	{
   1.141 +	return TUint(TSa1100::OstData());
   1.142 +	}
   1.143 +
   1.144 +TBMNs DBMMisaChannel::TimerTicksToNs(TBMTicks ticks)
   1.145 +	{
   1.146 +	return ticks * KBMMisaNsPerTick;
   1.147 +	}
   1.148 +
   1.149 +TBMTicks DBMMisaChannel::TimerNsToTicks(TBMNs ns)
   1.150 +	{
   1.151 +	return ns / KBMMisaNsPerTick;
   1.152 +	}
   1.153 +
   1.154 +void DBMMisaChannel::Isr(TAny* ptr)
   1.155 +	{
   1.156 +	DBMMisaChannel* mCh = (DBMMisaChannel*) ptr;
   1.157 +	BM_ASSERT(mCh->iIsr || mCh->iInterruptLatencyIsr);
   1.158 +	if (mCh->iIsr)
   1.159 +		{
   1.160 +		mCh->iIsr->Isr(TUint(TSa1100::OstData()));
   1.161 +		}
   1.162 +	else
   1.163 +		{
   1.164 +		mCh->iInterruptLatencyIsr->InterruptLatencyIsr(TSa1100::OstData() - TSa1100::OstMatch(KHwOstMatchGeneral));
   1.165 +		}
   1.166 +	TSa1100::DisableOstInterrupt(KHwOstMatchGeneral);
   1.167 +	TSa1100::SetOstMatchEOI(KHwOstMatchGeneral);
   1.168 +	}
   1.169 +
   1.170 +TInt DBMMisaChannel::BindInterrupt()
   1.171 +	{
   1.172 +	TInt r = Interrupt::Bind(KIntIdOstMatchGeneral, Isr, this);
   1.173 +	if (r != KErrNone)
   1.174 +		{
   1.175 +		return r;
   1.176 +		}
   1.177 +	TSa1100::ModifyIntLevels(0, KHtIntsOstMatchGeneral);	// route new timer interrupt to FIQ
   1.178 +	TSa1100::SetOstMatchEOI(KHwOstMatchGeneral);
   1.179 +	Interrupt::Enable(KIntIdOstMatchGeneral);
   1.180 +	return KErrNone;
   1.181 +	}
   1.182 +
   1.183 +TInt DBMMisaChannel::BindInterrupt(MBMIsr* aIsr)
   1.184 +	{
   1.185 +	BM_ASSERT(!iIsr);
   1.186 +	BM_ASSERT(!iInterruptLatencyIsr);
   1.187 +	iIsr = aIsr;
   1.188 +	return BindInterrupt();
   1.189 +	}
   1.190 +
   1.191 +TInt DBMMisaChannel::BindInterrupt(MBMInterruptLatencyIsr* aIsr)
   1.192 +	{
   1.193 +	BM_ASSERT(!iIsr);
   1.194 +	BM_ASSERT(!iInterruptLatencyIsr);
   1.195 +	iInterruptLatencyIsr = aIsr;
   1.196 +	return BindInterrupt();
   1.197 +	}
   1.198 +
   1.199 +
   1.200 +void DBMMisaChannel::RequestInterrupt()
   1.201 +	{
   1.202 +	BM_ASSERT(iIsr || iInterruptLatencyIsr);
   1.203 +	TSa1100::SetOstMatch(KHwOstMatchGeneral, TSa1100::OstData() + KBMMisaInterruptDelayTicks);
   1.204 +	TSa1100::SetOstMatchEOI(KHwOstMatchGeneral);
   1.205 +	TSa1100::EnableOstInterrupt(KHwOstMatchGeneral);
   1.206 +	}
   1.207 +
   1.208 +void DBMMisaChannel::CancelInterrupt()
   1.209 +	{	
   1.210 +	if (iIsr || iInterruptLatencyIsr)
   1.211 +		{
   1.212 +		TSa1100::DisableOstInterrupt(KHwOstMatchGeneral);
   1.213 +		TSa1100::SetOstMatchEOI(KHwOstMatchGeneral);
   1.214 +		}
   1.215 +	}
   1.216 +