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 "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // wins/specific/winscomm.h
25 const TInt KCommsMajorVersionNumber=1;
26 const TInt KCommsMinorVersionNumber=1;
27 const TInt KCommsBuildVersionNumber=KE32BuildVersionNumber;
30 enum TStopMode {EStopNormal,EStopPwrDown,EStopEmergency};
34 class DComm : public DBase
37 virtual TInt Start() =0;
38 virtual void Stop(TStopMode aMode) =0;
39 virtual void Break(TBool aState) =0;
40 virtual void Write(DThread*,TAny*,TInt) = 0;
41 virtual void Read(DThread*,TAny*,TInt) = 0;
42 virtual void NotifySignals(DThread*, TInt) = 0;
43 virtual void NotifyDataAvailable() = 0;
44 virtual TUint Signals() const =0;
45 virtual void SetSignals(TUint aSetMask,TUint aClearMask) =0;
46 virtual TInt ValidateConfig(const TCommConfigV01 &aConfig) const =0;
47 virtual void Configure(TCommConfigV01 &aConfig) =0;
48 virtual void Caps(TDes8 &aCaps) const =0;
49 virtual void CheckConfig(TCommConfigV01& aConfig)=0;
50 virtual TDfcQue* DfcQ(TInt aUnit)=0;
51 inline void SetCurrent(TInt aCurrent);
52 inline TBool Transmitting();
53 virtual TInt RxCount() =0;
54 virtual void ResetBuffers(TBool) = 0;
55 virtual TInt SetRxBufferSize(TInt aSize) = 0;
56 virtual TInt RxBufferSize() =0;
57 virtual TDes8* RxBuffer() =0;
58 virtual TBool AreAnyPending() = 0;
59 virtual void ReadCancel() = 0;
60 virtual void WriteCancel() = 0;
61 virtual void SignalChangeCancel() = 0;
62 virtual inline TBool LineFail() =0;
72 class DDeviceComm : public DLogicalDevice
76 virtual TInt Install();
77 virtual void GetCaps(TDes8 &aDes) const;
78 virtual TInt Create(DLogicalChannelBase*& aChannel);
81 //class DCommPowerHandler;
82 class DChannelComm : public DLogicalChannel
85 enum TState {EOpen,EActive,EClosed};
86 enum TRequest {ERx=1, ETx=2, ESigChg=4, ERxDA=8, EBreak=16, EAll=0xff};
90 inline void SetStatus(TState aStatus);
91 TInt TurnaroundSet(TUint aNewTurnaroundMilliSeconds);
92 TBool TurnaroundStopTimer();
93 TInt TurnaroundClear();
94 static void TurnaroundStartDfc(TAny* aSelf);
95 void TurnaroundStartDfcImplementation(TBool inIsr);
96 static void TurnaroundTimeout(TAny* aSelf);
97 void TurnaroundTimeoutImplementation(void);
100 virtual TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
101 virtual void HandleMsg(TMessageBase* aMsg);
102 void DoCancel(TInt aMask);
103 TInt DoControl(TInt aId, TAny* a1, TAny* a2);
104 TInt DoRequest(TInt aId, TRequestStatus* aStatus, TAny* a1, TAny* a2);
109 void ResetBuffers(TBool aResetTx);
112 void DoSignalNotify();
113 void DoRxDataAvailable();
114 void Complete(TInt aMask, TInt aReason);
115 inline void CompleteRead() { iRxCompleteDfc.Add(); }
116 inline void CompleteWrite() { iTxCompleteDfc.Add(); }
118 inline void Write(DThread* aT, TAny* aP, TInt aL) {((DComm*)iPdd)->Write(aT, aP,aL);}
119 inline void Read(DThread* aT, TAny* aP, TInt aL) {((DComm*)iPdd)->Read(aT, aP,aL);}
120 inline void NotifySignals(DThread* aThread, TInt aMask) {((DComm*)iPdd)->NotifySignals(aThread, aMask);}
121 inline void NotifyDataAvailable() {((DComm*)iPdd)->NotifyDataAvailable(); }
122 inline TInt PddStart();
123 inline void Stop(TStopMode aMode);
124 inline void PddBreak(TBool aState);
125 inline TUint Signals() const;
126 inline void SetSignals(TUint aSetMask,TUint aClearMask);
127 inline TInt ValidateConfig(const TCommConfigV01 &aConfig) const;
128 inline void PddConfigure(TCommConfigV01 &aConfig);
129 inline void PddCaps(TDes8 &aCaps) const;
130 inline void PddCheckConfig(TCommConfigV01& aConfig);
131 inline TBool Transmitting();
132 inline TInt BufferSize();
133 inline void ReadCancel();
134 inline void WriteCancel();
135 inline void SignalChangeCancel();
137 static void FinishBreakDfc(TAny* aSelf);
138 void QueueFinishBreakDfc();
139 static void FinishBreak(TAny* aSelf);
140 void FinishBreakImplementation(TInt aBreakError);
142 // static void PowerUpDfc(TAny* aPtr);
143 // static void PowerDownDfc(TAny* aPtr);
144 static void CompleteRxDfc(TAny* aPtr);
145 static void CompleteTxDfc(TAny* aPtr);
146 static void SignalNotifyDfc(TAny* aPtr);
147 static void RxDataAvailableDfc(TAny* aPtr);
148 inline TInt RxCount();
149 inline TInt RxBufferSize();
150 inline TDes8* RxBuffer();
151 inline TInt SetRxBufferSize(TInt aSize);
152 inline TBool AreAnyPending() const;
153 // void UpdateSignals();
154 void UpdateAndProcessSignals();
155 void InitiateRead(TAny* aRxDes, TInt aLength);
156 void InitiateWrite(TAny* aTxDes, TInt aLength);
157 void InitiateNotifySignals(TAny* aResult, TInt aMask);
158 void NotifyReadDataAvailable();
159 // TUint FailSignals(TUint aHandshake);
160 // TUint HoldSignals(TUint aHandshake);
161 // TUint FlowControlSignals(TUint aHandshake);
162 // TUint AutoSignals(TUint aHandshake);
163 TInt SetConfig(TCommConfigV01& aConfig);
164 // void CheckOutputHeld();
165 // void ReleaseBuffers();
166 inline TBool LineFail();
168 // Min Turnaround time between Rx and Tx
169 TUint iTurnaroundMicroSeconds; // delay after a receive before transmission in us
170 TUint iTurnaroundMinMilliSeconds; // delay after a receive before transmission in ms
171 TUint iTurnaroundTimerStartTime; // stores the start time of the turnaround timer.
172 TUint8 iTurnaroundTimerStartTimeValid; // stores turnaround timer status 0 after boot, 1 if the timestamp is valid, and 2 if invalid
173 TUint8 iTurnaroundTimerRunning; // a receive has started the timer
174 TUint8 iTurnaroundTransmitDelayed; // a transmission is held until time elapses after a receive
176 NTimer iTurnaroundTimer; // used to delay transmission after a receive
177 TDfc iTurnaroundDfc; // used in interrupt space, to trigger a call in user space
179 TAny* iTurnaroundTxDesPtr; // client descriptor awaiting transmission
180 TInt iTurnaroundTxDesLength; // initial size of tx descriptor
183 TTickLink iBreakTimer;
185 TRequestStatus* iBreakStatus;
186 TInt iBreakTimeMicroSeconds;
187 TBool iTurnaroundBreakDelayed;
188 TAny* iBreakDelayedTxDesPtr; // client descriptor awaiting transmission
189 TInt iBreakDelayedTxDesLength; // initial size of tx descriptor
190 TBool iBreakDelayedTx;
192 // Port configuration
193 TCommConfigV01 iConfig;
197 TAny* iClientDestPtr;
198 // DCommPowerHandler* iPowerHandler;
200 // TDfc iPowerDownDfc;
201 // TUint32 iPowerDownMask;
205 TDfc iRxDataAvailableDfc;
208 TUint iSignals; // State of handshake lines
209 // TUint iFailSignals; // 1 bit means line low causes line fail error
210 // TUint iHoldSignals; // 1 bit means line low halts TX
211 // TUint iFlowControlSignals; // 1 bit means signal is used for RX flow control
212 // TUint iAutoSignals; // 1 bit means signal is high when channel is open
213 TBool iShutdown; // ETrue means device is being closed
214 TBool iMsgHeld; // ETrue means a message has been held up waiting power on
216 // RX client related items
218 TRequestStatus* iRxStatus;
221 // TX client related items
223 TRequestStatus* iTxStatus;
225 // DataAvailable client related items
227 TRequestStatus* iRxDAStatus;
229 // Signal change notification
231 TRequestStatus* iSignalStatus;
232 TUint* iClientSignalResultPtr; //ptr to uint in client address space
233 TUint iSignalResult; //holds result of the signal (in Symbian OS values)
236 //class DCommPowerHandler : public DPowerHandler
239 // DCommPowerHandler(DChannelComm* aChannel);
240 // virtual TInt DoPowerUp();
241 // virtual void DoPowerDown(TUint32 aPowerDownMask);
242 // virtual void DoEmergencyPowerDown();
244 // DChannelComm* iChannel;
247 #include "winscomm.inl"