Update contrib.
1 // Copyright (c) 2003-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\benchmark\bm_momap_pdd.cpp
18 #include <kernel/kernel.h>
20 #include <omap_plat.h>
21 #include <omap_powerresources.h> // TResourceMgr methods
22 #include <powerresources_assp.h> // ASSP resources
25 // Note that this uses GPTimer2, these make it easy to swap around
26 const TUint KGPTimerBase = KHwBaseGpTimer2Reg;
27 const TUint KGPTimerClkSel = KHt_MOD_CONF_CTRL1_GPTIMER2_CLK_SEL;
28 const TUint KGPTimerInt = EIrqLv1_GpTimer2;
30 class DBmOmap : public DPhysicalDevice
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);
41 class DBmOmapChannel : public DBMPChannel
46 virtual TBMTicks TimerPeriod(); // Report timing spec
47 virtual TBMTicks TimerStamp(); // Get current system timer tick time
48 virtual TBMNs TimerTicksToNs(TBMTicks); // Tick/nS conversions
49 virtual TBMTicks TimerNsToTicks(TBMNs);
50 virtual TInt BindInterrupt(MBMIsr*); // Pass in client ISRs to invoke
51 virtual TInt BindInterrupt(MBMInterruptLatencyIsr*);
52 virtual void RequestInterrupt(); // Invoke an ISR
53 virtual void CancelInterrupt();
56 TInt BindInterrupt(); // Attach to OST interrupt
58 static const TInt KOmapOscFreqHz = 3000000; // 12Mhz / 4 = 3MHz
59 static const TBMTicks KBMOmapPeriod = (((TBMTicks) 1) << 32);
60 static const TBMNs KBMOmapNsPerTick = (1000*1000*1000) / KOmapOscFreqHz;
62 // calculate 1ms in timer ticks
63 static const TInt KBMOmapInterruptDelayTicks = KOmapOscFreqHz / 1000;
65 static void Isr(TAny*);
68 MBMInterruptLatencyIsr* iInterruptLatencyIsr;
72 DECLARE_STANDARD_PDD()
74 // Create a new device
87 iVersion = TVersion(1,0,1);
89 // place requirement on xor clock
90 TResourceMgr::Request(KPowerArmEn_XorpCk);
92 TOmap::ModifyRegister32(KGPTimerBase + KHoGpTimer_TCLR, KHtGpTimer_TCLR_St, KClear32); //Stop the timer
94 // Drive this gptimer by the arm xor clock
95 TOmapPlat::ModifyConfigReg(KHoBaseConfMOD_CONF_CTRL1, KGPTimerClkSel, 0);
96 // Prescale enable = 12/4 = 3MHz
97 TOmap::ModifyRegister32(KGPTimerBase + KHoGpTimer_TCLR, (KHmGpTimer_TCLR_PTV), (1 << KHsGpTimer_TCLR_PTV | KHtGpTimer_TCLR_PRE) );
99 // Enable "smart Idle mode"
100 TOmap::SetRegister32(KGPTimerBase + KHoGpTimerTIOCP_CFG, (KHtGpTimer_TIOCP_CFG_SmartIdle << KHsGpTimer_TIOCP_CFG_IdleMode));
101 // Load TimerLoad register to zero so when overflow occurs the counter starts from zero again.
102 TOmap::SetRegister32(KGPTimerBase + KHoGpTimer_TLDR, 0x0);
103 // Load Timer Trig register which clears the prescale counter and loads the value in TLDR to TCRR
104 TOmap::SetRegister32(KGPTimerBase + KHoGpTimer_TTGR, 0x1);
106 // Start the GPTimer. This configuration will pause counting when stopped by the jtag
107 TOmap::ModifyRegister32(KGPTimerBase + KHoGpTimer_TCLR, KClear32, (KHtGpTimer_TCLR_St|KHtGpTimer_TCLR_AR|KHtGpTimer_TCLR_CE));
108 while(TOmap::Register32(KGPTimerBase + KHoGpTimer_TWPS));
114 TOmap::ModifyRegister32(KGPTimerBase + KHoGpTimer_TCLR, KHtGpTimer_TCLR_St, KClear32);
115 while(TOmap::Register32(KGPTimerBase + KHoGpTimer_TWPS));
117 // Release requirement on xor clock
118 TResourceMgr::Release(KPowerArmEn_XorpCk);
121 TInt DBmOmap::Install()
123 // Install the device driver.
126 TInt r = SetName(&KBMPdName);
130 void DBmOmap::GetCaps(TDes8& aDes) const
132 // Return the Comm capabilities.
137 TInt DBmOmap::Create(DBase*& aChannel, TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
139 // Create a channel on the device.
143 aChannel = new DBmOmapChannel;
144 return aChannel?KErrNone:KErrNoMemory;
147 TInt DBmOmap::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
149 if (!Kern::QueryVersionSupported(iVersion,aVer))
151 return KErrNotSupported;
156 // Note that the standard benchmark tests will expect to create >1
157 // channel (with the same LDD/PDD(unit)) hence this function must be
158 // capable of being invoked multiple times.
160 DBmOmapChannel::DBmOmapChannel()
163 // iInterruptLatencyIsr = NULL;
166 DBmOmapChannel::~DBmOmapChannel()
168 if (iIsr || iInterruptLatencyIsr)
170 // Leave timer running
171 // TOmap::ModifyRegister32(KGPTimerBase + KHoGpTimer_TCLR, KHtGpTimer_TCLR_St, KClear32); //Stop the timer
172 Interrupt::Disable(KGPTimerInt);
173 Interrupt::Unbind(KGPTimerInt);
177 TBMTicks DBmOmapChannel::TimerPeriod()
179 return KBMOmapPeriod;
182 TBMTicks DBmOmapChannel::TimerStamp()
184 return TUint(TOmap::Register32(KGPTimerBase + KHoGpTimer_TCRR));
187 TBMNs DBmOmapChannel::TimerTicksToNs(TBMTicks ticks)
189 return ticks * KBMOmapNsPerTick;
192 TBMTicks DBmOmapChannel::TimerNsToTicks(TBMNs ns)
194 return ns / KBMOmapNsPerTick;
197 void DBmOmapChannel::Isr(TAny* ptr)
199 DBmOmapChannel* mCh = (DBmOmapChannel*) ptr;
200 BM_ASSERT(mCh->iIsr || mCh->iInterruptLatencyIsr);
203 mCh->iIsr->Isr(TUint(TOmap::Register32(KGPTimerBase + KHoGpTimer_TCRR)));
207 mCh->iInterruptLatencyIsr->InterruptLatencyIsr(TOmap::Register32(KGPTimerBase+KHoGpTimer_TCRR) - TOmap::Register32(KGPTimerBase+KHoGpTimer_TMAR));
209 TOmap::ModifyRegister32(KGPTimerBase+KHoGpTimer_TIER, KHtGpTimer_TIER_Match, KClear32);
212 TInt DBmOmapChannel::BindInterrupt()
214 TInt r=Interrupt::Bind(KGPTimerInt, Isr, this);
219 // Clear Match interrupt status bit
220 TOmap::SetRegister32(KGPTimerBase + KHoGpTimer_TISR, KHtGpTimer_TISR_Match);
222 Interrupt::Enable(KGPTimerInt);
226 TInt DBmOmapChannel::BindInterrupt(MBMIsr* aIsr)
229 BM_ASSERT(!iInterruptLatencyIsr);
231 return BindInterrupt();
234 TInt DBmOmapChannel::BindInterrupt(MBMInterruptLatencyIsr* aIsr)
237 BM_ASSERT(!iInterruptLatencyIsr);
238 iInterruptLatencyIsr = aIsr;
239 return BindInterrupt();
243 void DBmOmapChannel::RequestInterrupt()
245 BM_ASSERT(iIsr || iInterruptLatencyIsr);
246 TOmap::SetRegister32(KGPTimerBase+KHoGpTimer_TMAR, TOmap::Register32(KGPTimerBase+KHoGpTimer_TCRR) + KBMOmapInterruptDelayTicks);
247 // Clear Match interrupt
248 TOmap::SetRegister32(KGPTimerBase+KHoGpTimer_TISR, KHtGpTimer_TISR_Match);
249 // Enable Match interrupt
250 TOmap::SetRegister32(KGPTimerBase+KHoGpTimer_TIER, KHtGpTimer_TIER_Match);
253 void DBmOmapChannel::CancelInterrupt()
255 if (iIsr || iInterruptLatencyIsr)
257 // Disable Match interrupt
258 TOmap::ModifyRegister32(KGPTimerBase+KHoGpTimer_TIER, KHtGpTimer_TIER_Match, KClear32);