|
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 "k32bm.h" |
|
17 |
|
18 #include <emulator.h> |
|
19 |
|
20 class DBMWinsDevice : public DPhysicalDevice |
|
21 { |
|
22 public: |
|
23 DBMWinsDevice(); |
|
24 virtual TInt Install(); |
|
25 virtual void GetCaps(TDes8& aDes) const; |
|
26 virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
27 virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
28 }; |
|
29 |
|
30 class DBMWinsChannel : public DBMPChannel |
|
31 { |
|
32 public: |
|
33 DBMWinsChannel(); |
|
34 ~DBMWinsChannel(); |
|
35 virtual TBMTicks TimerPeriod(); |
|
36 virtual TBMTicks TimerStamp(); |
|
37 virtual TBMNs TimerTicksToNs(TBMTicks); |
|
38 virtual TBMTicks TimerNsToTicks(TBMNs); |
|
39 virtual TInt BindInterrupt(MBMIsr*); |
|
40 virtual TInt BindInterrupt(MBMInterruptLatencyIsr*); |
|
41 virtual void RequestInterrupt(); |
|
42 virtual void CancelInterrupt(); |
|
43 |
|
44 private: |
|
45 |
|
46 static const TInt KBMWinsInterruptDelayMs; |
|
47 static const TBMNs KBMWinsNsPerTick; |
|
48 static const TBMTicks KBMWinsPeriod; |
|
49 |
|
50 static void Isr(TAny*); |
|
51 static void InterruptLatencyIsr(TAny*); |
|
52 |
|
53 TInt iRequestedTime; |
|
54 MBMIsr* iIsr; |
|
55 MBMInterruptLatencyIsr* iInterruptLatencyIsr; |
|
56 NTimer iTimer; |
|
57 }; |
|
58 |
|
59 const TInt DBMWinsChannel::KBMWinsInterruptDelayMs = 4; |
|
60 const TBMNs DBMWinsChannel::KBMWinsNsPerTick = 100; |
|
61 const TBMTicks DBMWinsChannel::KBMWinsPeriod = (((TBMTicks) 1) << 32); |
|
62 |
|
63 DECLARE_STANDARD_PDD() |
|
64 // |
|
65 // Create a new device |
|
66 // |
|
67 { |
|
68 __ASSERT_CRITICAL; |
|
69 return new DBMWinsDevice; |
|
70 } |
|
71 |
|
72 DBMWinsDevice::DBMWinsDevice() |
|
73 // |
|
74 // Constructor |
|
75 // |
|
76 { |
|
77 //iUnitsMask=0; |
|
78 iVersion = TVersion(1,0,1); |
|
79 } |
|
80 |
|
81 TInt DBMWinsDevice::Install() |
|
82 // |
|
83 // Install the device driver. |
|
84 // |
|
85 { |
|
86 TInt r = SetName(&KBMPdName); |
|
87 return r; |
|
88 } |
|
89 |
|
90 void DBMWinsDevice::GetCaps(TDes8&) const |
|
91 // |
|
92 // Return the Comm capabilities. |
|
93 // |
|
94 { |
|
95 } |
|
96 |
|
97 TInt DBMWinsDevice::Create(DBase*& aChannel, TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/) |
|
98 // |
|
99 // Create a channel on the device. |
|
100 // |
|
101 { |
|
102 __ASSERT_CRITICAL; |
|
103 aChannel = new DBMWinsChannel(); |
|
104 return aChannel ? KErrNone : KErrNoMemory; |
|
105 } |
|
106 |
|
107 TInt DBMWinsDevice::Validate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer) |
|
108 { |
|
109 if (!Kern::QueryVersionSupported(iVersion,aVer)) |
|
110 { |
|
111 return KErrNotSupported; |
|
112 } |
|
113 return KErrNone; |
|
114 } |
|
115 |
|
116 DBMWinsChannel::DBMWinsChannel() : iTimer(Isr, this) |
|
117 { |
|
118 // iIsr = NULL; |
|
119 // iInterruptLatencyIsr = NULL; |
|
120 } |
|
121 |
|
122 DBMWinsChannel::~DBMWinsChannel() |
|
123 { |
|
124 } |
|
125 |
|
126 TBMTicks DBMWinsChannel::TimerPeriod() |
|
127 { |
|
128 return KBMWinsPeriod; |
|
129 } |
|
130 |
|
131 TBMTicks DBMWinsChannel::TimerStamp() |
|
132 { |
|
133 FILETIME now; |
|
134 GetSystemTimeAsFileTime(&now); |
|
135 return now.dwLowDateTime; |
|
136 } |
|
137 |
|
138 TBMNs DBMWinsChannel::TimerTicksToNs(TBMTicks ticks) |
|
139 { |
|
140 return ticks * KBMWinsNsPerTick; |
|
141 } |
|
142 |
|
143 TBMTicks DBMWinsChannel::TimerNsToTicks(TBMNs ns) |
|
144 { |
|
145 return ns / KBMWinsNsPerTick; |
|
146 } |
|
147 |
|
148 void DBMWinsChannel::Isr(TAny* ptr) |
|
149 { |
|
150 FILETIME now; |
|
151 GetSystemTimeAsFileTime(&now); |
|
152 DBMWinsChannel* pCh = (DBMWinsChannel*) ptr; |
|
153 BM_ASSERT(pCh->iIsr); |
|
154 pCh->iIsr->Isr(now.dwLowDateTime); |
|
155 } |
|
156 |
|
157 TInt DBMWinsChannel::BindInterrupt(MBMIsr* aIsr) |
|
158 { |
|
159 BM_ASSERT(!iIsr); |
|
160 BM_ASSERT(!iInterruptLatencyIsr); |
|
161 iIsr = aIsr; |
|
162 return KErrNone; |
|
163 } |
|
164 |
|
165 void DBMWinsChannel::InterruptLatencyIsr(TAny* ptr) |
|
166 { |
|
167 FILETIME now; |
|
168 GetSystemTimeAsFileTime(&now); |
|
169 DBMWinsChannel* pCh = (DBMWinsChannel*) ptr; |
|
170 TBMTicks latency = now.dwLowDateTime - pCh->iRequestedTime; |
|
171 BM_ASSERT(pCh->iInterruptLatencyIsr); |
|
172 pCh->iInterruptLatencyIsr->InterruptLatencyIsr(latency); |
|
173 } |
|
174 |
|
175 TInt DBMWinsChannel::BindInterrupt(MBMInterruptLatencyIsr* aIsr) |
|
176 { |
|
177 BM_ASSERT(!iIsr); |
|
178 BM_ASSERT(!iInterruptLatencyIsr); |
|
179 iInterruptLatencyIsr = aIsr; |
|
180 iTimer.iFunction = InterruptLatencyIsr; |
|
181 return KErrNone; |
|
182 } |
|
183 |
|
184 void DBMWinsChannel::RequestInterrupt() |
|
185 { |
|
186 BM_ASSERT(iIsr || iInterruptLatencyIsr); |
|
187 FILETIME now; |
|
188 GetSystemTimeAsFileTime(&now); |
|
189 iRequestedTime = now.dwLowDateTime + ((KBMWinsInterruptDelayMs * ((1000 * 1000) / (TInt) KBMWinsNsPerTick))); |
|
190 iTimer.OneShot(KBMWinsInterruptDelayMs); |
|
191 } |
|
192 |
|
193 void DBMWinsChannel::CancelInterrupt() |
|
194 { |
|
195 iTimer.Cancel(); |
|
196 } |
|
197 |