/*
 Copyright 1999-2000 DigiInternational Inc.
 */




	// This section contains the fields used for write side  processing

	typedef struct {
	PUCHAR  shortWriteBuffer;	// buffer for short writes
	ULONG	shortWBufferMax;	// size of the short write buffers - 1
	ULONG	indexShortWBufIn;	// index into shortBuffer where next byte will be stored (buffered)
	ULONG	indexShortWBufOut;	// index into shortBuffer from where the data will be sent to the card
	ULONG	shortBufferTHold;	// Short buffer threshold - packets larger than
	
	BOOLEAN	smallPacketBuffer;	// this will not be buffered
	BOOLEAN	completeOnWrite;

	LIST_ENTRY  writeIrpQueue;	// write IRPs received by the driver not yet completed
	LIST_ENTRY	writePendedQueue;	// IRPs sent to card but waiting for Ack
	PIRP		pCurrentWriteIrp;
	PIRP		pTimeoutIrp;	

	USHORT	tmax;
	USHORT	ttime;
	USHORT	tsize;



	ULONG	tin;				// driver uses this index to put data 
	ULONG	txSequenceNumber;	// Xmit sequence number
	
	KDPC        timeoutWriteDpc;    // Write IRP timeout DPC structure. 
    KTIMER      timeoutWrite;        // timer for write tieouts
	KEVENT		writeEvent;			// Event to trigger write thread

	KDPC		shortWBufDPC;		// DPC to empty short write buffer
	KTIMER		shortWBufTimer;		// Timer for short write buffer DPC
	KSPIN_LOCK  writeLock;			// lock to protect the write "side"
	UCHAR		irql;

	} PORT_WRITE_OBJ, *PPORT_WRITE_OBJ ;


	typedef struct  {

		struct {
      //
      // Port Speed and Processing Flags
      //
			ULONG       Speed;                  // BAUD
			USHORT      Cflags;                 // COM control flags.
			USHORT      Iflags;                 // Input processing flags.
			USHORT      Oflags;                 // Output processing flags.
			USHORT      Xflags;                 // Extended control flags.
   
            // Modem Control Variables
	      //
			UCHAR       Mout;                   // Modem active signals.
			UCHAR       Mflow;                  // Modem flow control.
			UCHAR       Mctrl;                  // Modem flow control for out-of-band data.
			UCHAR       Mstat;                  // Current Modem status.
			UCHAR       Mlast;                  // Last Modem status value.
			UCHAR       Mint;                   // Modem notification events.
			UCHAR       Mflags;                 // Value of Flags field in MODEM command.


			SERIAL_HANDFLOW		handFlow;
			SERIAL_CHARS		specialChars;   
			UCHAR       escapeChar;             // NT error escape character; analogous to DosMode

   

			ULONG		sync;
			ULONG		syncAck;
			KSPIN_LOCK	lock;
			KIRQL		irql;


			 // Values in S/DXB PAUSE commands
			UCHAR       Pset;
			UCHAR       Preset;


			UCHAR		sendImmChar;

			ULONG	state;
			LIST_ENTRY	pendingQueue;
                 
		 } ioctl;


//
      // Event Reporting
      //
		USHORT      Estat;                  // Active Event conditions.
		USHORT      Eint;                   // Async event notification.
		USHORT      Elast;                  // Last state of the event conditions.




	PORT_WRITE_OBJ writeObj;
	ULONG			port;
	KSPIN_LOCK		portLock;
	KIRQL			portIrql;
	SERIAL_TIMEOUTS	 timeoutValues;
	ULONG       WaitMask; 
	ULONG       TotalRxBytesBuffered;
	ULONG		TxBytesPending;
	ULONG		LerrFlags;
	ULONG		state;
	HANDLE		hStream;

	struct {
		USHORT      Break;           // Number of Break signals received.
		USHORT      Framing;         // Framing errors.
		USHORT      Overrun;         // Buffer overflow.
		USHORT      Parity;          // Parity errors.
	} commErr;

							
	}PORT_EXT, *PPORT_EXT;




#define	DIGI_SZ_SHORTWRITEBUFFER	32





typedef enum
{
   BreakOnMask             = 0x01,
   ImmWriteMask            = 0x02,

   // Special Char Rxed signal from S/DXB, waiting on S/DXB to pass the DATA 
   // block with this special char.
   SpecialCharRxedMask     = 0x04,

   // S/DXB is currently Purging Rx, awaiting SYNC response
   RxDataPurgeMask         = 0x08,

   // This port has used up it's share of Rx Buffers
   RxDataFullMask          = 0x10,

   // S/DXB is currently Purging Tx, awaiting SYNC response
   TxDataPurgeMask         = 0x20,
   
   // Stop us pre-empting a Write which is about to take place
   TxingMask               = 0x40,
} OPEN_STATE;


typedef enum
{
   IdleState,
   OpeningState,
   OpenState,
   ClosingState,
   ClosingAwaitingCompleteState,
   ShutdownState,
	IdleState_PowerD3,
	OpenState_PowerD3,
} PORT_STATE;





/*
 * Debug Stuff
 */
#define DIGIINIT               DEBUG_00000001
#define DIGIINIT1              DEBUG_00000002
#define DIGIUNLOAD             DEBUG_00000004
#define DIGISDXB1              DEBUG_00000008

#define DIGIOPEN               DEBUG_00000010
#define DIGICLOSE              DEBUG_00000020
#define DIGICANCEL             DEBUG_00000040
#define DIGISDXB               DEBUG_00000080

#define DIGIDISPATCH           DEBUG_00000100
#define DIGITIMEOUT            DEBUG_00000200
#define DIGIPURGE              DEBUG_00000400
#define DIGIPNP	             DEBUG_00000800

#define DIGIEVENT              DEBUG_00001000
#define DIGITHREAD             DEBUG_00002000
#define DIGIIOCTL1             DEBUG_00004000
#define DIGIIRP                DEBUG_00008000

#define DIGIREAD               DEBUG_00010000
#define DIGIWRITE              DEBUG_00020000
#define DIGIIOCTL              DEBUG_00040000
#define DIGIWAIT               DEBUG_00080000

#define DIGIRXTRACE            DEBUG_00100000
#define DIGITXTRACE            DEBUG_00200000
#define DIGITIMEOUT1           DEBUG_00400000
#define DIGIPOWER              DEBUG_00800000

#define DIGIFLOW               DEBUG_01000000
#define DIGIFLOW1              DEBUG_02000000

#define DIGIERRORS             DEBUG_ERROR
#define DIGIALL                (~DEBUG_BREAK)
