|
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 Change History: |
|
17 VERSION : 2 26-01-2010 Ruixing Yang |
|
18 REASON : |
|
19 REFERENCE : |
|
20 DESCRIPTION : The timer resolution is modified for better interrupt latency calculation |
|
21 |
|
22 Change History: |
|
23 VERSION : 1 25-01-2010 Ruixing Yang |
|
24 REASON : |
|
25 REFERENCE : |
|
26 DESCRIPTION : Initial implementation of BM_SUITE PDD for Rapu platform |
|
27 |
|
28 */ |
|
29 |
|
30 |
|
31 #include <kernel/kernel.h> |
|
32 #include <internal/rap_hw.h> |
|
33 #include <internal/rap.h> |
|
34 #include "k32bm.h" |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 class DBMRapuDevice : public DPhysicalDevice |
|
42 { |
|
43 public: |
|
44 DBMRapuDevice(); |
|
45 virtual TInt Install(); |
|
46 virtual void GetCaps(TDes8& aDes) const; |
|
47 virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
48 virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
49 }; |
|
50 |
|
51 class DBMRapuChannel : public DBMPChannel |
|
52 { |
|
53 public: |
|
54 DBMRapuChannel(); |
|
55 ~DBMRapuChannel(); |
|
56 virtual TBMTicks TimerPeriod(); |
|
57 virtual TBMTicks TimerStamp(); |
|
58 virtual TBMNs TimerTicksToNs(TBMTicks); |
|
59 virtual TBMTicks TimerNsToTicks(TBMNs); |
|
60 virtual TInt BindInterrupt(MBMIsr*); |
|
61 virtual TInt BindInterrupt(MBMInterruptLatencyIsr*); |
|
62 virtual void RequestInterrupt(); |
|
63 virtual void CancelInterrupt(); |
|
64 |
|
65 private: |
|
66 |
|
67 static const TBMTicks KBMRapuPeriod = (((TBMTicks) 1) << 32); |
|
68 // Ticks at 1000Hz, input clock to timer @ 32.768 MHz. |
|
69 static const TInt KHighResTimerFrequency = 32768000; // 32.768 MHz |
|
70 |
|
71 static const TBMNs KBMRapuNsPerTick = (1000*1000*1000) / KHighResTimerFrequency; |
|
72 static const TInt KRTC_Freq = 32768; |
|
73 static const TInt KRTC_Ratio = 1172; |
|
74 |
|
75 |
|
76 |
|
77 static void Isr(TAny*); |
|
78 |
|
79 MBMIsr* iIsr; |
|
80 MBMInterruptLatencyIsr* iInterruptLatencyIsr; |
|
81 TUint iTmpStartCount; |
|
82 TUint iTmpLongCount; |
|
83 NTimer iTimer; |
|
84 volatile TUint iStartCount; |
|
85 volatile TUint iRunCount; |
|
86 volatile TUint iCancelCount; |
|
87 }; |
|
88 |
|
89 RTC001_STR& RTC001 = *reinterpret_cast<RTC001_STR*>(KRapRegRTC001); |
|
90 GPT003_STR& GPT003 = *reinterpret_cast<GPT003_STR*>(KRapRegGPT003A0); |
|
91 |
|
92 |
|
93 DECLARE_STANDARD_PDD() |
|
94 // |
|
95 // Create a new device |
|
96 // |
|
97 { |
|
98 __ASSERT_CRITICAL; |
|
99 return new DBMRapuDevice; |
|
100 } |
|
101 |
|
102 DBMRapuDevice::DBMRapuDevice() |
|
103 // |
|
104 // Constructor |
|
105 // |
|
106 { |
|
107 |
|
108 iVersion = TVersion(1,0,1); |
|
109 } |
|
110 |
|
111 TInt DBMRapuDevice::Install() |
|
112 // |
|
113 // Install the device driver. |
|
114 // |
|
115 { |
|
116 |
|
117 TInt r = SetName(&KBMPdName); |
|
118 return r; |
|
119 } |
|
120 |
|
121 void DBMRapuDevice::GetCaps(TDes8& aDes) const |
|
122 // |
|
123 // Return the Comm capabilities. |
|
124 // |
|
125 { |
|
126 |
|
127 } |
|
128 |
|
129 TInt DBMRapuDevice::Create(DBase*& aChannel, TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/) |
|
130 // |
|
131 // Create a channel on the device. |
|
132 // |
|
133 { |
|
134 |
|
135 __ASSERT_CRITICAL; |
|
136 aChannel = new DBMRapuChannel; |
|
137 return aChannel?KErrNone:KErrNoMemory; |
|
138 } |
|
139 |
|
140 TInt DBMRapuDevice::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer) |
|
141 { |
|
142 |
|
143 if (!Kern::QueryVersionSupported(iVersion,aVer)) |
|
144 { |
|
145 return KErrNotSupported; |
|
146 } |
|
147 return KErrNone; |
|
148 } |
|
149 |
|
150 DBMRapuChannel::DBMRapuChannel() |
|
151 : iTimer(&Isr, this) |
|
152 { |
|
153 iTmpStartCount = 0; |
|
154 iTmpLongCount = 0; |
|
155 } |
|
156 |
|
157 DBMRapuChannel::~DBMRapuChannel() |
|
158 { |
|
159 //Kern::Printf(("DBMRapuChannel::~DBMRapuChannel()")); |
|
160 CancelInterrupt(); |
|
161 } |
|
162 |
|
163 TBMTicks DBMRapuChannel::TimerPeriod() |
|
164 { |
|
165 //Kern::Printf(("DBMRapuChannel::TimerPeriod()")); |
|
166 return KBMRapuPeriod; |
|
167 } |
|
168 |
|
169 TBMTicks DBMRapuChannel::TimerStamp() |
|
170 { |
|
171 //Kern::Printf(("DBMRapuChannel::TimerStamp(), iTimerCount = %u"), RPTimer1::Timer().iTimerCount); |
|
172 TUint tmpTimeStamp; |
|
173 RTC001.TRIGGER = 0; |
|
174 tmpTimeStamp = RTC001.LONGCOUNT; |
|
175 tmpTimeStamp *= KRTC_Ratio; |
|
176 tmpTimeStamp += RTC001.SHORTCOUNT; |
|
177 return tmpTimeStamp; |
|
178 } |
|
179 |
|
180 |
|
181 TBMNs DBMRapuChannel::TimerTicksToNs(TBMTicks ticks) |
|
182 { |
|
183 //Kern::Printf(("DBMRapuChannel::TimerTIcksToNs(), iNsPerTick = %u"), (TBMTicks)iNsPerTick); |
|
184 return ticks * KBMRapuNsPerTick; |
|
185 } |
|
186 |
|
187 TBMTicks DBMRapuChannel::TimerNsToTicks(TBMNs ns) |
|
188 { |
|
189 //Kern::Printf(("DBMRapuChannel::TimerNsToTicks()")); |
|
190 return ns / KBMRapuNsPerTick; |
|
191 } |
|
192 |
|
193 void DBMRapuChannel::Isr(TAny* ptr) |
|
194 { |
|
195 //Kern::Printf(("DBMRapuChannel::Isr()")); |
|
196 // Read RTC001 |
|
197 RTC001.TRIGGER = 0; |
|
198 TUint x = RTC001.LONGCOUNT; |
|
199 x *= KRTC_Ratio; |
|
200 x += RTC001.SHORTCOUNT; |
|
201 TUint wasteTime = 1000000/KBMRapuNsPerTick; //NTimer's resolution is 1 ms = 1000000 ns |
|
202 |
|
203 DBMRapuChannel* mCh = (DBMRapuChannel*) ptr; |
|
204 BM_ASSERT(mCh->iIsr || mCh->iInterruptLatencyIsr); |
|
205 if (mCh->iIsr) |
|
206 { |
|
207 mCh->iIsr->Isr( x); |
|
208 } |
|
209 else |
|
210 { |
|
211 TUint y = (TUint)( x - mCh->iTmpLongCount - wasteTime); |
|
212 //Kern::Printf(("DBMRapuChannel::Isr(), latency = %u"), y); |
|
213 mCh->iInterruptLatencyIsr->InterruptLatencyIsr(y); |
|
214 } |
|
215 __e32_atomic_add_ord32(&mCh->iRunCount, 1); |
|
216 } |
|
217 |
|
218 TInt DBMRapuChannel::BindInterrupt(MBMIsr* aIsr) |
|
219 { |
|
220 //Kern::Printf(("DBMRapuChannel::BindInterrupt(MBMIsr* aIsr)")); |
|
221 BM_ASSERT(!iIsr); |
|
222 BM_ASSERT(!iInterruptLatencyIsr); |
|
223 iIsr = aIsr; |
|
224 return KErrNone; |
|
225 } |
|
226 |
|
227 TInt DBMRapuChannel::BindInterrupt(MBMInterruptLatencyIsr* aIsr) |
|
228 { |
|
229 //Kern::Printf(("DBMRapuChannel::BindInterrupt(MBMInterruptLatencyIsr* aIsr)")); |
|
230 BM_ASSERT(!iIsr); |
|
231 BM_ASSERT(!iInterruptLatencyIsr); |
|
232 iInterruptLatencyIsr = aIsr; |
|
233 return KErrNone; |
|
234 } |
|
235 |
|
236 |
|
237 void DBMRapuChannel::RequestInterrupt() |
|
238 { |
|
239 //Kern::Printf(("DBMRapuChannel::RequestInterrupt()")); |
|
240 BM_ASSERT(iIsr || iInterruptLatencyIsr); |
|
241 // Read RTC001 |
|
242 RTC001.TRIGGER = 0; |
|
243 iTmpLongCount = RTC001.LONGCOUNT; |
|
244 iTmpLongCount *= KRTC_Ratio; |
|
245 iTmpLongCount += RTC001.SHORTCOUNT; |
|
246 if (iTimer.OneShot(1)==KErrNone) |
|
247 __e32_atomic_add_ord32(&iStartCount, 1); |
|
248 |
|
249 } |
|
250 |
|
251 void DBMRapuChannel::CancelInterrupt() |
|
252 { |
|
253 iTmpStartCount = 0; |
|
254 //Kern::Printf(("DBMRapuChannel::CancelInterrupt()")); |
|
255 if (iTimer.Cancel()) |
|
256 __e32_atomic_add_ord32(&iCancelCount, 1); |
|
257 while (iStartCount != iCancelCount + iRunCount) |
|
258 {} |
|
259 } |
|
260 |
|
261 |
|
262 |