os/kernelhwsrv/kerneltest/e32test/benchmark/bm_momap_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) 2003-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
// e32test\benchmark\bm_momap_pdd.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <kernel/kernel.h>
sl@0
    19
#include <omap.h>
sl@0
    20
#include <omap_plat.h>
sl@0
    21
#include <omap_powerresources.h>	// TResourceMgr methods
sl@0
    22
#include <powerresources_assp.h>	// ASSP resources
sl@0
    23
#include "k32bm.h"
sl@0
    24
sl@0
    25
// Note that this uses GPTimer2, these make it easy to swap around
sl@0
    26
const TUint KGPTimerBase = KHwBaseGpTimer2Reg;
sl@0
    27
const TUint KGPTimerClkSel = KHt_MOD_CONF_CTRL1_GPTIMER2_CLK_SEL;
sl@0
    28
const TUint KGPTimerInt = EIrqLv1_GpTimer2;
sl@0
    29
sl@0
    30
class DBmOmap : public DPhysicalDevice
sl@0
    31
	{
sl@0
    32
public:
sl@0
    33
	DBmOmap();
sl@0
    34
	~DBmOmap();
sl@0
    35
	virtual TInt Install();
sl@0
    36
	virtual void GetCaps(TDes8& aDes) const;
sl@0
    37
	virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
sl@0
    38
	virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
sl@0
    39
	};
sl@0
    40
sl@0
    41
class DBmOmapChannel : public DBMPChannel
sl@0
    42
	{
sl@0
    43
public:
sl@0
    44
	DBmOmapChannel();
sl@0
    45
	~DBmOmapChannel();
sl@0
    46
	virtual TBMTicks TimerPeriod();						// Report timing spec
sl@0
    47
	virtual TBMTicks TimerStamp();						// Get current system timer tick time
sl@0
    48
	virtual TBMNs TimerTicksToNs(TBMTicks);				// Tick/nS conversions
sl@0
    49
	virtual TBMTicks TimerNsToTicks(TBMNs);
sl@0
    50
	virtual TInt BindInterrupt(MBMIsr*);				// Pass in client ISRs to invoke
sl@0
    51
	virtual TInt BindInterrupt(MBMInterruptLatencyIsr*);
sl@0
    52
	virtual void RequestInterrupt();					// Invoke an ISR
sl@0
    53
	virtual void CancelInterrupt();
sl@0
    54
sl@0
    55
private:
sl@0
    56
	TInt BindInterrupt();								// Attach to OST interrupt
sl@0
    57
sl@0
    58
	static const TInt		KOmapOscFreqHz = 3000000;	// 12Mhz / 4 = 3MHz
sl@0
    59
	static const TBMTicks	KBMOmapPeriod = (((TBMTicks) 1) << 32);
sl@0
    60
	static const TBMNs		KBMOmapNsPerTick = (1000*1000*1000) / KOmapOscFreqHz;
sl@0
    61
sl@0
    62
	// calculate 1ms in timer ticks
sl@0
    63
	static const TInt		KBMOmapInterruptDelayTicks = KOmapOscFreqHz / 1000;
sl@0
    64
sl@0
    65
	static void Isr(TAny*);
sl@0
    66
sl@0
    67
	MBMIsr*						iIsr;
sl@0
    68
	MBMInterruptLatencyIsr*		iInterruptLatencyIsr;
sl@0
    69
	};
sl@0
    70
sl@0
    71
sl@0
    72
DECLARE_STANDARD_PDD()
sl@0
    73
//
sl@0
    74
// Create a new device
sl@0
    75
//
sl@0
    76
	{
sl@0
    77
	__ASSERT_CRITICAL;
sl@0
    78
	return new DBmOmap;
sl@0
    79
	}
sl@0
    80
sl@0
    81
DBmOmap::DBmOmap()
sl@0
    82
//
sl@0
    83
// Constructor
sl@0
    84
//
sl@0
    85
	{
sl@0
    86
	//iUnitsMask=0;
sl@0
    87
	iVersion = TVersion(1,0,1);
sl@0
    88
sl@0
    89
	// place requirement on xor clock
sl@0
    90
	TResourceMgr::Request(KPowerArmEn_XorpCk);
sl@0
    91
	// Stop timer
sl@0
    92
	TOmap::ModifyRegister32(KGPTimerBase + KHoGpTimer_TCLR, KHtGpTimer_TCLR_St, KClear32); //Stop the timer
sl@0
    93
sl@0
    94
	// Drive this gptimer by the arm xor clock
sl@0
    95
	TOmapPlat::ModifyConfigReg(KHoBaseConfMOD_CONF_CTRL1, KGPTimerClkSel, 0);
sl@0
    96
	// Prescale enable = 12/4 = 3MHz
sl@0
    97
	TOmap::ModifyRegister32(KGPTimerBase + KHoGpTimer_TCLR, (KHmGpTimer_TCLR_PTV),  (1 << KHsGpTimer_TCLR_PTV | KHtGpTimer_TCLR_PRE) );
sl@0
    98
sl@0
    99
	// Enable "smart Idle mode"
sl@0
   100
	TOmap::SetRegister32(KGPTimerBase + KHoGpTimerTIOCP_CFG, (KHtGpTimer_TIOCP_CFG_SmartIdle << KHsGpTimer_TIOCP_CFG_IdleMode));
sl@0
   101
	// Load TimerLoad register to zero so when overflow occurs the counter starts from zero again.
sl@0
   102
	TOmap::SetRegister32(KGPTimerBase + KHoGpTimer_TLDR, 0x0);
sl@0
   103
	// Load Timer Trig register which clears the prescale counter and loads the value in TLDR to TCRR
sl@0
   104
	TOmap::SetRegister32(KGPTimerBase + KHoGpTimer_TTGR, 0x1);
sl@0
   105
sl@0
   106
	// Start the GPTimer. This configuration will pause counting when stopped by the jtag
sl@0
   107
	TOmap::ModifyRegister32(KGPTimerBase + KHoGpTimer_TCLR, KClear32, (KHtGpTimer_TCLR_St|KHtGpTimer_TCLR_AR|KHtGpTimer_TCLR_CE));
sl@0
   108
	while(TOmap::Register32(KGPTimerBase + KHoGpTimer_TWPS));
sl@0
   109
	}
sl@0
   110
sl@0
   111
DBmOmap::~DBmOmap()
sl@0
   112
	{
sl@0
   113
	// Stop timer
sl@0
   114
	TOmap::ModifyRegister32(KGPTimerBase + KHoGpTimer_TCLR, KHtGpTimer_TCLR_St, KClear32);
sl@0
   115
	while(TOmap::Register32(KGPTimerBase + KHoGpTimer_TWPS));
sl@0
   116
sl@0
   117
	// Release requirement on xor clock
sl@0
   118
	TResourceMgr::Release(KPowerArmEn_XorpCk);
sl@0
   119
	}
sl@0
   120
sl@0
   121
TInt DBmOmap::Install()
sl@0
   122
//
sl@0
   123
// Install the device driver.
sl@0
   124
//
sl@0
   125
	{
sl@0
   126
	TInt r = SetName(&KBMPdName);
sl@0
   127
	return r;
sl@0
   128
	}
sl@0
   129
sl@0
   130
void DBmOmap::GetCaps(TDes8& aDes) const
sl@0
   131
//
sl@0
   132
// Return the Comm capabilities.
sl@0
   133
//
sl@0
   134
	{
sl@0
   135
	}
sl@0
   136
sl@0
   137
TInt DBmOmap::Create(DBase*& aChannel, TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
sl@0
   138
//
sl@0
   139
// Create a channel on the device.
sl@0
   140
//
sl@0
   141
	{
sl@0
   142
	__ASSERT_CRITICAL;
sl@0
   143
	aChannel = new DBmOmapChannel;
sl@0
   144
	return aChannel?KErrNone:KErrNoMemory;
sl@0
   145
	}
sl@0
   146
sl@0
   147
TInt DBmOmap::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
sl@0
   148
	{
sl@0
   149
	if (!Kern::QueryVersionSupported(iVersion,aVer))
sl@0
   150
		{
sl@0
   151
		return KErrNotSupported;
sl@0
   152
		}
sl@0
   153
	return KErrNone;
sl@0
   154
	}
sl@0
   155
sl@0
   156
// Note that the standard benchmark tests will expect to create >1
sl@0
   157
// channel (with the same LDD/PDD(unit)) hence this function must be
sl@0
   158
// capable of being invoked multiple times.
sl@0
   159
sl@0
   160
DBmOmapChannel::DBmOmapChannel()
sl@0
   161
	{
sl@0
   162
	//	iIsr = NULL;
sl@0
   163
	//	iInterruptLatencyIsr = NULL;
sl@0
   164
	}
sl@0
   165
sl@0
   166
DBmOmapChannel::~DBmOmapChannel()
sl@0
   167
	{
sl@0
   168
	if (iIsr || iInterruptLatencyIsr)
sl@0
   169
		{
sl@0
   170
		// Leave timer running
sl@0
   171
		// TOmap::ModifyRegister32(KGPTimerBase + KHoGpTimer_TCLR, KHtGpTimer_TCLR_St, KClear32); //Stop the timer
sl@0
   172
		Interrupt::Disable(KGPTimerInt);
sl@0
   173
		Interrupt::Unbind(KGPTimerInt);
sl@0
   174
		}
sl@0
   175
	}
sl@0
   176
sl@0
   177
TBMTicks DBmOmapChannel::TimerPeriod()
sl@0
   178
	{
sl@0
   179
	return KBMOmapPeriod;
sl@0
   180
	}
sl@0
   181
sl@0
   182
TBMTicks DBmOmapChannel::TimerStamp()
sl@0
   183
	{
sl@0
   184
	return TUint(TOmap::Register32(KGPTimerBase + KHoGpTimer_TCRR));
sl@0
   185
	}
sl@0
   186
sl@0
   187
TBMNs DBmOmapChannel::TimerTicksToNs(TBMTicks ticks)
sl@0
   188
	{
sl@0
   189
	return ticks * KBMOmapNsPerTick;
sl@0
   190
	}
sl@0
   191
sl@0
   192
TBMTicks DBmOmapChannel::TimerNsToTicks(TBMNs ns)
sl@0
   193
	{
sl@0
   194
	return ns / KBMOmapNsPerTick;
sl@0
   195
	}
sl@0
   196
sl@0
   197
void DBmOmapChannel::Isr(TAny* ptr)
sl@0
   198
	{
sl@0
   199
	DBmOmapChannel* mCh = (DBmOmapChannel*) ptr;
sl@0
   200
	BM_ASSERT(mCh->iIsr || mCh->iInterruptLatencyIsr);
sl@0
   201
	if (mCh->iIsr)
sl@0
   202
		{
sl@0
   203
		mCh->iIsr->Isr(TUint(TOmap::Register32(KGPTimerBase + KHoGpTimer_TCRR)));
sl@0
   204
		}
sl@0
   205
	else
sl@0
   206
		{
sl@0
   207
		mCh->iInterruptLatencyIsr->InterruptLatencyIsr(TOmap::Register32(KGPTimerBase+KHoGpTimer_TCRR) - TOmap::Register32(KGPTimerBase+KHoGpTimer_TMAR));
sl@0
   208
		}
sl@0
   209
	TOmap::ModifyRegister32(KGPTimerBase+KHoGpTimer_TIER, KHtGpTimer_TIER_Match, KClear32);
sl@0
   210
	}
sl@0
   211
sl@0
   212
TInt DBmOmapChannel::BindInterrupt()
sl@0
   213
	{
sl@0
   214
	TInt r=Interrupt::Bind(KGPTimerInt, Isr, this);
sl@0
   215
	if (r != KErrNone)
sl@0
   216
		{
sl@0
   217
		return r;
sl@0
   218
		}
sl@0
   219
	// Clear Match interrupt status bit
sl@0
   220
	TOmap::SetRegister32(KGPTimerBase + KHoGpTimer_TISR, KHtGpTimer_TISR_Match);
sl@0
   221
sl@0
   222
	Interrupt::Enable(KGPTimerInt);
sl@0
   223
	return KErrNone;
sl@0
   224
	}
sl@0
   225
sl@0
   226
TInt DBmOmapChannel::BindInterrupt(MBMIsr* aIsr)
sl@0
   227
	{
sl@0
   228
	BM_ASSERT(!iIsr);
sl@0
   229
	BM_ASSERT(!iInterruptLatencyIsr);
sl@0
   230
	iIsr = aIsr;
sl@0
   231
	return BindInterrupt();
sl@0
   232
	}
sl@0
   233
sl@0
   234
TInt DBmOmapChannel::BindInterrupt(MBMInterruptLatencyIsr* aIsr)
sl@0
   235
	{
sl@0
   236
	BM_ASSERT(!iIsr);
sl@0
   237
	BM_ASSERT(!iInterruptLatencyIsr);
sl@0
   238
	iInterruptLatencyIsr = aIsr;
sl@0
   239
	return BindInterrupt();
sl@0
   240
	}
sl@0
   241
sl@0
   242
sl@0
   243
void DBmOmapChannel::RequestInterrupt()
sl@0
   244
	{
sl@0
   245
	BM_ASSERT(iIsr || iInterruptLatencyIsr);
sl@0
   246
	TOmap::SetRegister32(KGPTimerBase+KHoGpTimer_TMAR, TOmap::Register32(KGPTimerBase+KHoGpTimer_TCRR) + KBMOmapInterruptDelayTicks);
sl@0
   247
	// Clear Match interrupt
sl@0
   248
	TOmap::SetRegister32(KGPTimerBase+KHoGpTimer_TISR, KHtGpTimer_TISR_Match);
sl@0
   249
	// Enable Match interrupt
sl@0
   250
	TOmap::SetRegister32(KGPTimerBase+KHoGpTimer_TIER, KHtGpTimer_TIER_Match);
sl@0
   251
	}
sl@0
   252
sl@0
   253
void DBmOmapChannel::CancelInterrupt()
sl@0
   254
	{
sl@0
   255
	if (iIsr || iInterruptLatencyIsr)
sl@0
   256
		{
sl@0
   257
		// Disable Match interrupt
sl@0
   258
		TOmap::ModifyRegister32(KGPTimerBase+KHoGpTimer_TIER, KHtGpTimer_TIER_Match, KClear32);
sl@0
   259
		}
sl@0
   260
	}