|
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 <sa1100.h> |
|
18 |
|
19 #include "k32bm.h" |
|
20 |
|
21 class DBMMisaDevice : public DPhysicalDevice |
|
22 { |
|
23 public: |
|
24 DBMMisaDevice(); |
|
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); |
|
29 }; |
|
30 |
|
31 class DBMMisaChannel : public DBMPChannel |
|
32 { |
|
33 public: |
|
34 DBMMisaChannel(); |
|
35 ~DBMMisaChannel(); |
|
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(); |
|
44 |
|
45 private: |
|
46 |
|
47 TInt BindInterrupt(); |
|
48 |
|
49 static const TInt KBMMisaInterruptDelayTicks = KHwOscFreqHz / 1000; |
|
50 static const TBMTicks KBMMisaPeriod = (((TBMTicks) 1) << 32); |
|
51 static const TBMNs KBMMisaNsPerTick = (1000*1000*1000) / KHwOscFreqHz; |
|
52 |
|
53 static void Isr(TAny*); |
|
54 |
|
55 MBMIsr* iIsr; |
|
56 MBMInterruptLatencyIsr* iInterruptLatencyIsr; |
|
57 }; |
|
58 |
|
59 |
|
60 DECLARE_STANDARD_PDD() |
|
61 // |
|
62 // Create a new device |
|
63 // |
|
64 { |
|
65 __ASSERT_CRITICAL; |
|
66 return new DBMMisaDevice; |
|
67 } |
|
68 |
|
69 DBMMisaDevice::DBMMisaDevice() |
|
70 // |
|
71 // Constructor |
|
72 // |
|
73 { |
|
74 //iUnitsMask=0; |
|
75 iVersion = TVersion(1,0,1); |
|
76 } |
|
77 |
|
78 TInt DBMMisaDevice::Install() |
|
79 // |
|
80 // Install the device driver. |
|
81 // |
|
82 { |
|
83 TInt r = SetName(&KBMPdName); |
|
84 return r; |
|
85 } |
|
86 |
|
87 void DBMMisaDevice::GetCaps(TDes8& aDes) const |
|
88 // |
|
89 // Return the Comm capabilities. |
|
90 // |
|
91 { |
|
92 } |
|
93 |
|
94 TInt DBMMisaDevice::Create(DBase*& aChannel, TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/) |
|
95 // |
|
96 // Create a channel on the device. |
|
97 // |
|
98 { |
|
99 __ASSERT_CRITICAL; |
|
100 aChannel = new DBMMisaChannel; |
|
101 return aChannel?KErrNone:KErrNoMemory; |
|
102 } |
|
103 |
|
104 TInt DBMMisaDevice::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer) |
|
105 { |
|
106 if (!Kern::QueryVersionSupported(iVersion,aVer)) |
|
107 { |
|
108 return KErrNotSupported; |
|
109 } |
|
110 return KErrNone; |
|
111 } |
|
112 |
|
113 DBMMisaChannel::DBMMisaChannel() |
|
114 { |
|
115 // iIsr = NULL; |
|
116 // iInterruptLatencyIsr = NULL; |
|
117 } |
|
118 |
|
119 DBMMisaChannel::~DBMMisaChannel() |
|
120 { |
|
121 if (iIsr || iInterruptLatencyIsr) |
|
122 { |
|
123 TSa1100::DisableOstInterrupt(KHwOstMatchGeneral); |
|
124 TSa1100::SetOstMatchEOI(KHwOstMatchGeneral); |
|
125 Interrupt::Disable(KIntIdOstMatchGeneral); |
|
126 TSa1100::ModifyIntLevels(KHtIntsOstMatchGeneral,0); |
|
127 Interrupt::Unbind(KIntIdOstMatchGeneral); |
|
128 } |
|
129 } |
|
130 |
|
131 TBMTicks DBMMisaChannel::TimerPeriod() |
|
132 { |
|
133 return KBMMisaPeriod; |
|
134 } |
|
135 |
|
136 TBMTicks DBMMisaChannel::TimerStamp() |
|
137 { |
|
138 return TUint(TSa1100::OstData()); |
|
139 } |
|
140 |
|
141 TBMNs DBMMisaChannel::TimerTicksToNs(TBMTicks ticks) |
|
142 { |
|
143 return ticks * KBMMisaNsPerTick; |
|
144 } |
|
145 |
|
146 TBMTicks DBMMisaChannel::TimerNsToTicks(TBMNs ns) |
|
147 { |
|
148 return ns / KBMMisaNsPerTick; |
|
149 } |
|
150 |
|
151 void DBMMisaChannel::Isr(TAny* ptr) |
|
152 { |
|
153 DBMMisaChannel* mCh = (DBMMisaChannel*) ptr; |
|
154 BM_ASSERT(mCh->iIsr || mCh->iInterruptLatencyIsr); |
|
155 if (mCh->iIsr) |
|
156 { |
|
157 mCh->iIsr->Isr(TUint(TSa1100::OstData())); |
|
158 } |
|
159 else |
|
160 { |
|
161 mCh->iInterruptLatencyIsr->InterruptLatencyIsr(TSa1100::OstData() - TSa1100::OstMatch(KHwOstMatchGeneral)); |
|
162 } |
|
163 TSa1100::DisableOstInterrupt(KHwOstMatchGeneral); |
|
164 TSa1100::SetOstMatchEOI(KHwOstMatchGeneral); |
|
165 } |
|
166 |
|
167 TInt DBMMisaChannel::BindInterrupt() |
|
168 { |
|
169 TInt r = Interrupt::Bind(KIntIdOstMatchGeneral, Isr, this); |
|
170 if (r != KErrNone) |
|
171 { |
|
172 return r; |
|
173 } |
|
174 TSa1100::ModifyIntLevels(0, KHtIntsOstMatchGeneral); // route new timer interrupt to FIQ |
|
175 TSa1100::SetOstMatchEOI(KHwOstMatchGeneral); |
|
176 Interrupt::Enable(KIntIdOstMatchGeneral); |
|
177 return KErrNone; |
|
178 } |
|
179 |
|
180 TInt DBMMisaChannel::BindInterrupt(MBMIsr* aIsr) |
|
181 { |
|
182 BM_ASSERT(!iIsr); |
|
183 BM_ASSERT(!iInterruptLatencyIsr); |
|
184 iIsr = aIsr; |
|
185 return BindInterrupt(); |
|
186 } |
|
187 |
|
188 TInt DBMMisaChannel::BindInterrupt(MBMInterruptLatencyIsr* aIsr) |
|
189 { |
|
190 BM_ASSERT(!iIsr); |
|
191 BM_ASSERT(!iInterruptLatencyIsr); |
|
192 iInterruptLatencyIsr = aIsr; |
|
193 return BindInterrupt(); |
|
194 } |
|
195 |
|
196 |
|
197 void DBMMisaChannel::RequestInterrupt() |
|
198 { |
|
199 BM_ASSERT(iIsr || iInterruptLatencyIsr); |
|
200 TSa1100::SetOstMatch(KHwOstMatchGeneral, TSa1100::OstData() + KBMMisaInterruptDelayTicks); |
|
201 TSa1100::SetOstMatchEOI(KHwOstMatchGeneral); |
|
202 TSa1100::EnableOstInterrupt(KHwOstMatchGeneral); |
|
203 } |
|
204 |
|
205 void DBMMisaChannel::CancelInterrupt() |
|
206 { |
|
207 if (iIsr || iInterruptLatencyIsr) |
|
208 { |
|
209 TSa1100::DisableOstInterrupt(KHwOstMatchGeneral); |
|
210 TSa1100::SetOstMatchEOI(KHwOstMatchGeneral); |
|
211 } |
|
212 } |
|
213 |