|
1 // Copyright (c) 1995-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 "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 |
|
17 #if !defined(__D_COMM_H__) |
|
18 #define __D_COMM_H__ |
|
19 #if !defined(__K32STD_H__) |
|
20 #include <k32std.h> |
|
21 #endif |
|
22 #if !defined(__D32COMM_H__) |
|
23 #include <d32comm.h> |
|
24 #endif |
|
25 #if !defined(__E32VER_H__) |
|
26 #include <e32ver.h> |
|
27 #endif |
|
28 // |
|
29 const TInt KCommsMajorVersionNumber=1; |
|
30 const TInt KCommsMinorVersionNumber=0; |
|
31 const TInt KCommsBuildVersionNumber=KE32BuildVersionNumber; |
|
32 // |
|
33 const TInt KDefaultRxBufferSize=0x400; |
|
34 const TInt KTxBufferSize=0x400; |
|
35 const TInt KMaxHighWaterMark=0x080; |
|
36 // |
|
37 const TUint KReceiveIsrParityError=0x10000000; |
|
38 const TUint KReceiveIsrFrameError=0x20000000; |
|
39 const TUint KReceiveIsrOverrunError=0x40000000; |
|
40 const TUint KReceiveIsrMaskError=0x70000000; |
|
41 // |
|
42 const TInt KTransmitIrqEmpty=KErrGeneral; |
|
43 // |
|
44 const TUint KReceiveIsrTermChar=0x80000000; |
|
45 const TUint KReceiveIsrMaskComplete=0xf0000000; |
|
46 const TUint KReceiveIsrShift=24; |
|
47 const TUint KReceiveIsrShiftedMask=0x0f; |
|
48 // |
|
49 // |
|
50 enum TStopMode {EStopNormal,EStopPwrDown,EStopEmergency}; |
|
51 // |
|
52 // |
|
53 class DChannelComm; |
|
54 class DComm : public CBase |
|
55 { |
|
56 public: |
|
57 virtual TInt Start() =0; |
|
58 virtual void Stop(TStopMode aMode) =0; |
|
59 virtual void Break(TBool aState) =0; |
|
60 virtual void EnableTransmit() =0; |
|
61 virtual TUint Signals() const =0; |
|
62 virtual void SetSignals(TUint aSetMask,TUint aClearMask) =0; |
|
63 virtual TInt Validate(const TCommConfigV01 &aConfig) const =0; |
|
64 virtual void Configure(TCommConfigV01 &aConfig) =0; |
|
65 virtual void Caps(TDes8 &aCaps) const =0; |
|
66 virtual void CheckConfig(TCommConfigV01& aConfig)=0; |
|
67 virtual void EnableInterrupts() =0; |
|
68 virtual void DisableInterrupts() =0; |
|
69 virtual TInt CompleteSlowOpen(DThread *aThread,TRequestStatus *aReqStat) =0; |
|
70 inline DChannelComm &Comm() {return(*iComm);} |
|
71 inline void SetComm(DChannelComm *aComm) {iComm=aComm;} |
|
72 virtual void SetTimer(const TUint aTimeOut) =0; |
|
73 virtual void CancelTimer() =0; |
|
74 private: |
|
75 DChannelComm *iComm; |
|
76 #ifdef _DEBUG_DEVCOMM |
|
77 public: |
|
78 TInt iRxIntCount; |
|
79 TInt iTxIntCount; |
|
80 TInt iRxErrCount; |
|
81 TInt iTxErrCount; |
|
82 #endif |
|
83 }; |
|
84 // |
|
85 // 32 bit sequence number space |
|
86 // |
|
87 class TCommSeqNum |
|
88 { |
|
89 public: |
|
90 inline TCommSeqNum& operator++(); |
|
91 inline TCommSeqNum& operator++(TInt); |
|
92 inline TCommSeqNum& operator--(); |
|
93 inline TCommSeqNum& operator--(TInt); |
|
94 inline TCommSeqNum& operator=(TUint aVal); |
|
95 inline TCommSeqNum& operator=(const TCommSeqNum& aVal); |
|
96 inline TCommSeqNum& operator+=(TInt aVal); |
|
97 inline TCommSeqNum& operator-=(TInt aVal); |
|
98 inline TBool operator==(const TCommSeqNum& aVal) const; |
|
99 inline TBool operator!=(const TCommSeqNum& aVal) const; |
|
100 inline TBool operator<(const TCommSeqNum& aVal) const; |
|
101 inline TBool operator<=(const TCommSeqNum& aVal) const; |
|
102 inline TBool operator>(const TCommSeqNum& aVal) const; |
|
103 inline TBool operator>=(const TCommSeqNum& aVal) const; |
|
104 inline TCommSeqNum operator+(TInt aVal); |
|
105 inline TCommSeqNum operator-(TInt aVal); |
|
106 inline TInt operator-(const TCommSeqNum& aVal); |
|
107 inline TUint Int() const; |
|
108 private: |
|
109 TUint iNum; |
|
110 }; |
|
111 // |
|
112 class CCommRxBuf : public CBase |
|
113 { |
|
114 public: |
|
115 CCommRxBuf(); |
|
116 ~CCommRxBuf(); |
|
117 void SetLengthL(TInt aLength); |
|
118 void Reset(); |
|
119 inline TInt Count() { return iCount; } |
|
120 inline TInt Length() { return iLength; } |
|
121 TInt PutChar(TUint aChar); |
|
122 TInt ClientWrite(TUint& aStatus, DComm* aDriver, DThread* aThread, const TAny* aPtr, TInt& aRxLength, TInt& aRxOffset, TInt aMode); |
|
123 TInt TestTerm(TInt aCount, TInt aTermCount, TUint8* aTermList); |
|
124 TBool RescanTerminators(DComm* aDriver, TInt aTermCount, TText8* aTermChars); |
|
125 public: |
|
126 TInt iLength; |
|
127 TInt iCount; |
|
128 TInt iInsP; |
|
129 TInt iRemP; |
|
130 TUint8* iCharPtr; |
|
131 TUint8* iInfoPtr; |
|
132 TCommSeqNum iInsSeqNum; |
|
133 TCommSeqNum iRemSeqNum; |
|
134 TCommSeqNum iLastSeqNum; |
|
135 }; |
|
136 |
|
137 class CCommTxBuf : public CCirBuffer |
|
138 { |
|
139 public: |
|
140 CCommTxBuf(); |
|
141 TInt ClientRead(DComm* aDriver, DThread* aThread, const TAny* aPtr, TInt& aTxLength, TInt& aTxOffset, TInt aMode); |
|
142 }; |
|
143 |
|
144 // |
|
145 class DDeviceComm : public DLogicalDevice |
|
146 { |
|
147 public: |
|
148 DDeviceComm(); |
|
149 virtual TInt Install(); |
|
150 virtual void GetCaps(TDes8 &aDes) const; |
|
151 virtual DLogicalChannel *CreateL(); |
|
152 }; |
|
153 // |
|
154 |
|
155 class DCommPowerHandler : public DPowerHandler |
|
156 { |
|
157 public: |
|
158 DCommPowerHandler(DChannelComm *aLdd); |
|
159 void RequestComplete(); |
|
160 void RequestPending(); |
|
161 static void Timeout(TAny *, TInt); |
|
162 |
|
163 virtual TInt DoPowerOn(); |
|
164 virtual void DoPowerStandby(); |
|
165 virtual void DoPowerEmergencyStandby(); |
|
166 public: |
|
167 DChannelComm *iLdd; |
|
168 TTickLink iTimer; |
|
169 }; |
|
170 |
|
171 class DChannelComm : public DLogicalChannel |
|
172 { |
|
173 public: |
|
174 enum TState {ENotActive,EActive,EClosed}; |
|
175 private: |
|
176 enum TDfcRequestFlags |
|
177 { |
|
178 EFillTxBufferRequired=0x00000001, |
|
179 EDrainRxBufferRequired=0x00000002, |
|
180 ECompleteRead=0x00000008, |
|
181 ECompleteWrite=0x00000010, |
|
182 ECompleteBreak=0x00000020, |
|
183 EEarlyCompleteWrite=0x00000040, |
|
184 ECompleteEmergency=0x00000080, |
|
185 ECompleteSignalChange=0x00000100, |
|
186 ECompleteDataAvailable=0x00000200, |
|
187 ETurnaroundTimerDfc=0x00000400 |
|
188 }; |
|
189 public: |
|
190 DChannelComm(DLogicalDevice *aDevice); |
|
191 ~DChannelComm(); |
|
192 virtual void ReceiveIsr(TUint aChar); |
|
193 virtual TInt TransmitIsr(); |
|
194 virtual void StateIsr(TUint aStatus); |
|
195 inline TBool IsPowerGood(); |
|
196 inline void SetStatus(TState aStatus); |
|
197 inline void CompleteAllReqs(TInt aReason); |
|
198 inline TBool IsReading() const; |
|
199 inline TBool IsWriting() const; |
|
200 protected: |
|
201 virtual void DoCreateL(TInt aUnit,CBase *aDriver,const TDesC *anInfo,const TVersion &aVer); |
|
202 virtual void DoCancel(TInt aReqNo); |
|
203 virtual void DoRequest(TInt aReqNo,TAny *a1,TAny *a2); |
|
204 virtual TInt DoControl(TInt aFunction,TAny *a1,TAny *a2); |
|
205 inline TBool AreAnyPending() const; |
|
206 void Start(); |
|
207 void Stop(TStopMode aMode); |
|
208 void BreakOn(); |
|
209 void BreakOff(); |
|
210 void EnableTransmit(); |
|
211 TInt SetRxBufferSize(TInt aSize); |
|
212 void ResetBuffers(); |
|
213 TBool IsLineFail(TUint aHandshake); |
|
214 void DoDrainRxBuffer(); |
|
215 void DoFillTxBuffer(); |
|
216 inline void DrainRxBuffer() {QueueDfc(EDrainRxBufferRequired);}; |
|
217 inline void FillTxBuffer() {QueueDfc(EFillTxBufferRequired);}; |
|
218 inline void CompleteWrite() {QueueDfc(ECompleteWrite);}; |
|
219 inline void EarlyCompleteWrite() {QueueDfc(EEarlyCompleteWrite);}; |
|
220 inline void CompleteSignalChange() {QueueDfc(ECompleteSignalChange);}; |
|
221 inline void CompleteDataAvailable() {QueueDfc(ECompleteDataAvailable);}; |
|
222 // void CompleteWrite(TInt anError=KErrNone); |
|
223 // void CompleteRead(TInt anError=KErrNone); |
|
224 // void DoCompleteWrite(); |
|
225 // void DoCompleteRead(); |
|
226 public: |
|
227 virtual void DoPowerDown(); |
|
228 virtual void DoEmergencyPowerDown(); |
|
229 |
|
230 TInt TurnaroundSet(TUint aNewTurnaroundMicroSeconds); |
|
231 TInt TurnaroundClear(); |
|
232 void RestartTurnaroundTimer(); |
|
233 virtual void TurnaroundStartDfcImplementation(); |
|
234 void TurnaroundTimeoutImplementation(); |
|
235 |
|
236 private: |
|
237 static TInt CallDfc(TAny* aDChannelComm); |
|
238 void DfcHandler(); |
|
239 void QueueDfc(TUint aRequestMask); |
|
240 void ResetDevice(); |
|
241 void RestoreDtrRrs(); |
|
242 public: |
|
243 TCommConfigV02 iConfig; |
|
244 private: |
|
245 DComm *iDriver; |
|
246 DCommPowerHandler *iPowerHandler; |
|
247 TState iStatus; |
|
248 TUint iDfcRequest; |
|
249 TDfc iDfc; |
|
250 TInt iInputHeld; // Receive suspended by signalling peer |
|
251 TInt iOutputHeld; // Transmit suspended by peer |
|
252 TInt iReceiveError; |
|
253 TInt iWriteError; |
|
254 TInt iReceiveOneOrMore; |
|
255 TInt iWriteZero; // Awaiting ability to write |
|
256 TInt iReceiveErrorLength; |
|
257 TInt iReceiveLength; |
|
258 TInt iReceiveOffset; |
|
259 TInt iTransmitLength; |
|
260 TInt iTransmitOffset; |
|
261 TUint iFlags; |
|
262 TUint iSignals; |
|
263 TInt iLowWaterMark; |
|
264 TInt iHighWaterMark; |
|
265 TInt iHalfFullMark; |
|
266 TUint8 *iReceivePtr; // Client space pointer |
|
267 TUint8 *iTransmitPtr; // Client space pointer |
|
268 CCommRxBuf *iRxBuf; |
|
269 CCommTxBuf *iTxBuf; |
|
270 TBool iIsReading; |
|
271 TBool iIsWriting; |
|
272 TBool iDrainingRxBuf; |
|
273 TBool iFillingTxBuf; |
|
274 TBool iRunningDfc; |
|
275 TBool iIsClientWriting; |
|
276 TBool iSignalChangeNotification; |
|
277 TUint* iSignalChangePtr; |
|
278 TUint iSignalMask; |
|
279 TUint iSignalChangeInfo; |
|
280 TBool iDataAvailableNotification; |
|
281 |
|
282 // Min Turnaround time between Rx and Tx |
|
283 TUint iTurnaroundMinMicroSeconds; // delay after a receive before transmission |
|
284 TBool iTurnaroundTimerRunning; // a receive has started the timer |
|
285 TBool iTurnaroundTransmitDelayed; // a transmission is held until time elapses after a receive |
|
286 TAny* iTurnaroundTxDesPtr; // client descriptor awaiting transmission |
|
287 TInt iTurnaroundTxDesLength; // initial size of tx descriptor |
|
288 |
|
289 #ifdef _DEBUG_DEVCOMM |
|
290 TInt iDfcCount; |
|
291 TInt iDfcReqSeq; |
|
292 TInt iDfcHandlerSeq; |
|
293 TInt iDoDrainSeq; |
|
294 TInt iTxChars, iRxChars; |
|
295 TInt iTxXon, iTxXoff, iRxXon, iRxXoff; |
|
296 #endif |
|
297 friend class DCommPowerHandler; |
|
298 }; |
|
299 |
|
300 #include "d_comm.inl" |
|
301 |
|
302 #endif |