os/boardsupport/emulator/emulatorbsp/specific/winscomm.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 "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 // wins/specific/winscomm.h
    15 // 
    16 //
    17 
    18 #ifndef __M32COMM_H__
    19 #define __M32COMM_H__
    20 #include <platform.h>
    21 //#include <kpower.h>
    22 #include <d32comm.h>
    23 #include <e32ver.h>
    24 //
    25 const TInt KCommsMajorVersionNumber=1;
    26 const TInt KCommsMinorVersionNumber=1;
    27 const TInt KCommsBuildVersionNumber=KE32BuildVersionNumber;
    28 
    29 //
    30 enum TStopMode {EStopNormal,EStopPwrDown,EStopEmergency};
    31 //
    32 //
    33 class DChannelComm;
    34 class DComm : public DBase
    35 	{
    36 public:
    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;
    63 
    64 public:
    65 	DChannelComm *iLdd;
    66 	TBool iTransmitting;
    67 	TUint8 * iInBufPtr;
    68 	TUint8 * iOutBufPtr;
    69 	};
    70 
    71 
    72 class DDeviceComm : public DLogicalDevice
    73 	{
    74 public:
    75 	DDeviceComm();
    76 	virtual TInt Install();
    77 	virtual void GetCaps(TDes8 &aDes) const;
    78 	virtual TInt Create(DLogicalChannelBase*& aChannel);
    79 	};
    80 
    81 //class DCommPowerHandler;
    82 class DChannelComm : public DLogicalChannel
    83 	{
    84 public:
    85 	enum TState {EOpen,EActive,EClosed};
    86 	enum TRequest {ERx=1, ETx=2, ESigChg=4, ERxDA=8, EBreak=16, EAll=0xff};
    87 
    88 	DChannelComm();
    89 	~DChannelComm();
    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);
    98 
    99 protected:
   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);
   105 	void Start();
   106 	void Shutdown();
   107 	void BreakOn();
   108 	void BreakOff();
   109 	void ResetBuffers(TBool aResetTx);
   110 	void DoCompleteRx();
   111 	void DoCompleteTx();
   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(); }
   117 protected:
   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();
   136 
   137 	static void FinishBreakDfc(TAny* aSelf);
   138 	void QueueFinishBreakDfc();
   139 	static void FinishBreak(TAny* aSelf);
   140 	void FinishBreakImplementation(TInt aBreakError);
   141 private:
   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();
   167 
   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
   175 	TUint8		iSpare;
   176 	NTimer		iTurnaroundTimer;				// used to delay transmission after a receive
   177 	TDfc		iTurnaroundDfc;					// used in interrupt space, to trigger a call in user space
   178 
   179 	TAny*		iTurnaroundTxDesPtr;			// client descriptor awaiting transmission
   180 	TInt		iTurnaroundTxDesLength;			// initial size of tx descriptor
   181 
   182 	// Breaks
   183 	TTickLink iBreakTimer;
   184 	TDfc		 iBreakDfc;
   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;
   191 public:
   192 	// Port configuration
   193 	TCommConfigV01 iConfig;
   194 
   195 	// General items
   196 	DThread* iClient;
   197 	TAny* iClientDestPtr;
   198 //	DCommPowerHandler* iPowerHandler;
   199 //	TDfc iPowerUpDfc;
   200 //	TDfc iPowerDownDfc;
   201 //	TUint32 iPowerDownMask;
   202 	TState iStatus;
   203 	TDfc iRxCompleteDfc;
   204 	TDfc iTxCompleteDfc;
   205 	TDfc iRxDataAvailableDfc;
   206 	TDfc iSigNotifyDfc;
   207 	TUint iFlags;				//
   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
   215 
   216 	// RX client related items
   217 	TInt iRxError;
   218 	TRequestStatus* iRxStatus;
   219 
   220 
   221 	// TX client related items
   222 	TInt iTxError;
   223 	TRequestStatus* iTxStatus;
   224 
   225 	// DataAvailable client related items
   226 	TInt iRxDAError;
   227 	TRequestStatus* iRxDAStatus;
   228 
   229 	// Signal change notification
   230 	TInt iSignalError;
   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)
   234 	};
   235 
   236 //class DCommPowerHandler : public DPowerHandler
   237 //	{
   238 //public:
   239 //	DCommPowerHandler(DChannelComm* aChannel);
   240 //	virtual TInt DoPowerUp();
   241 //	virtual void DoPowerDown(TUint32 aPowerDownMask);
   242 //	virtual void DoEmergencyPowerDown();
   243 //public:
   244 //	DChannelComm* iChannel;
   245 //	};
   246 
   247 #include "winscomm.inl"
   248 
   249 #endif