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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <kernel/kernel.h>
21 class DBMMisaDevice : public DPhysicalDevice
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);
31 class DBMMisaChannel : public DBMPChannel
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();
49 static const TInt KBMMisaInterruptDelayTicks = KHwOscFreqHz / 1000;
50 static const TBMTicks KBMMisaPeriod = (((TBMTicks) 1) << 32);
51 static const TBMNs KBMMisaNsPerTick = (1000*1000*1000) / KHwOscFreqHz;
53 static void Isr(TAny*);
56 MBMInterruptLatencyIsr* iInterruptLatencyIsr;
60 DECLARE_STANDARD_PDD()
62 // Create a new device
66 return new DBMMisaDevice;
69 DBMMisaDevice::DBMMisaDevice()
75 iVersion = TVersion(1,0,1);
78 TInt DBMMisaDevice::Install()
80 // Install the device driver.
83 TInt r = SetName(&KBMPdName);
87 void DBMMisaDevice::GetCaps(TDes8& aDes) const
89 // Return the Comm capabilities.
94 TInt DBMMisaDevice::Create(DBase*& aChannel, TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
96 // Create a channel on the device.
100 aChannel = new DBMMisaChannel;
101 return aChannel?KErrNone:KErrNoMemory;
104 TInt DBMMisaDevice::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
106 if (!Kern::QueryVersionSupported(iVersion,aVer))
108 return KErrNotSupported;
113 DBMMisaChannel::DBMMisaChannel()
116 // iInterruptLatencyIsr = NULL;
119 DBMMisaChannel::~DBMMisaChannel()
121 if (iIsr || iInterruptLatencyIsr)
123 TSa1100::DisableOstInterrupt(KHwOstMatchGeneral);
124 TSa1100::SetOstMatchEOI(KHwOstMatchGeneral);
125 Interrupt::Disable(KIntIdOstMatchGeneral);
126 TSa1100::ModifyIntLevels(KHtIntsOstMatchGeneral,0);
127 Interrupt::Unbind(KIntIdOstMatchGeneral);
131 TBMTicks DBMMisaChannel::TimerPeriod()
133 return KBMMisaPeriod;
136 TBMTicks DBMMisaChannel::TimerStamp()
138 return TUint(TSa1100::OstData());
141 TBMNs DBMMisaChannel::TimerTicksToNs(TBMTicks ticks)
143 return ticks * KBMMisaNsPerTick;
146 TBMTicks DBMMisaChannel::TimerNsToTicks(TBMNs ns)
148 return ns / KBMMisaNsPerTick;
151 void DBMMisaChannel::Isr(TAny* ptr)
153 DBMMisaChannel* mCh = (DBMMisaChannel*) ptr;
154 BM_ASSERT(mCh->iIsr || mCh->iInterruptLatencyIsr);
157 mCh->iIsr->Isr(TUint(TSa1100::OstData()));
161 mCh->iInterruptLatencyIsr->InterruptLatencyIsr(TSa1100::OstData() - TSa1100::OstMatch(KHwOstMatchGeneral));
163 TSa1100::DisableOstInterrupt(KHwOstMatchGeneral);
164 TSa1100::SetOstMatchEOI(KHwOstMatchGeneral);
167 TInt DBMMisaChannel::BindInterrupt()
169 TInt r = Interrupt::Bind(KIntIdOstMatchGeneral, Isr, this);
174 TSa1100::ModifyIntLevels(0, KHtIntsOstMatchGeneral); // route new timer interrupt to FIQ
175 TSa1100::SetOstMatchEOI(KHwOstMatchGeneral);
176 Interrupt::Enable(KIntIdOstMatchGeneral);
180 TInt DBMMisaChannel::BindInterrupt(MBMIsr* aIsr)
183 BM_ASSERT(!iInterruptLatencyIsr);
185 return BindInterrupt();
188 TInt DBMMisaChannel::BindInterrupt(MBMInterruptLatencyIsr* aIsr)
191 BM_ASSERT(!iInterruptLatencyIsr);
192 iInterruptLatencyIsr = aIsr;
193 return BindInterrupt();
197 void DBMMisaChannel::RequestInterrupt()
199 BM_ASSERT(iIsr || iInterruptLatencyIsr);
200 TSa1100::SetOstMatch(KHwOstMatchGeneral, TSa1100::OstData() + KBMMisaInterruptDelayTicks);
201 TSa1100::SetOstMatchEOI(KHwOstMatchGeneral);
202 TSa1100::EnableOstInterrupt(KHwOstMatchGeneral);
205 void DBMMisaChannel::CancelInterrupt()
207 if (iIsr || iInterruptLatencyIsr)
209 TSa1100::DisableOstInterrupt(KHwOstMatchGeneral);
210 TSa1100::SetOstMatchEOI(KHwOstMatchGeneral);