/****************************************************************************/
/* Copyright 2003 MBARI														*/
/****************************************************************************/
/* Summary	: Definitions for using Internal PicoDOS data structures to		*/
/*			  implement serial XON/XOFF for OASIS3							*/
/* Filename : serInternal.h													*/
/* Author	: Robert Herlien (rah)											*/
/* Project	: OASIS Mooring Replacement (OASIS3)							*/
/* Revision: 1.0															*/
/* Created	: 02/20/2003													*/
/*																			*/
/* MBARI provides this documentation and code "as is", with no warranty,	*/
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium	*/
/* Research Institute to assist in its use, correction, modification, or	*/
/* enhancement. This information should not be published or distributed to	*/
/* third parties without specific written permission from MBARI.			*/
/*																			*/
/****************************************************************************/
/* Modification History:													*/
/* 20feb2003 rah - created													*/
/****************************************************************************/

#ifndef INCserInternalh
#define INCserInternalh 1

/****************************************************************/
/* Definitions from TUSimpleTermDrvrPatch.c						*/
/* Needed to patch the TPU interrupt in order to do XON/XOFF	*/
/****************************************************************/

enum	// UART Parameter RAM Fields
{
  uartParityTemp,
  uartMatchRate,
  uartRxTxDataReg,
  uartDataSize,
  uartActualBitCount,
  uartShiftRegister
};

typedef struct
{
  ulong			saveregs;		// 48E7 E0C0 movem.l d0-d2/a0-a1,-(a7)
  ushort		slot;			// 7008		 moveq	   #??,d0
  ushort		jsr;			// 4EB9		 jsr   TU?xHandler
  vfptr			handler;		// 0000 0000
  ulong			restregs;		// 4CDF 0307 movem.l   (a7)+,d0-d2/a0-a1
  ushort		rte;			// 4E73		 rte
} TPisr;

typedef struct
{
  void					*port;			// reverse link
  short					slot;			// TPU channel 1-15
  short					priority;		// TPU channel priority (off,lo,mid,hi)
  long					baud;			// BAUD rate
  short					autob;			// auto BAUD change
  short					flags;			// flags
  short					parity;			// parity
  short					bits;			// data bits
  vfptr					previsr;		// former interrupt handler
  TPisr					isr;			// ISR wrapper
  short					size;			// buffer size
  volatile short		free;			// free space for insert
  volatile short		head;			// head index
  volatile short		tail;			// tail index
  uchar					*buffer;
} TUChan;

#undef			TUPort	// from <cfxpico.h> vptr
typedef struct
{						
  TUChan				*rxchp;			// receiver
  TUChan				*txchp;			// transmitter
  char					*tpfbuf;		// printf buffer
} TUPort;

enum { txactiveflag = 0x0001, txbreakflag = 0x0002 };


/****************************************************************/
/* Definitions of structures I use for serial.c					*/
/****************************************************************/

typedef struct
{		
  Int16			txChan;
  Int16			rxChan;
  TUPort		*txRef;
  TUPort		*rxRef;
  Nat32			baudSave;
  Nat16			paritySave;
  Nat16			bitsSave;
} SerChanDesc;

typedef struct
{
  Int16			serChan;
  TUChan		*txTUChan;
  TUChan		*rxTUChan;
} ReverseChanDesc;


/****************************************/
/* Forward Declarations for Functions	*/
/*	that are internal to serial.c		*/
/****************************************/

MLocal Void TUEnableTx(TUChan *tchp);
MLocal void TUTxHandler(ushort slot:__d0);
MLocal void TURxHandler(ushort slot:__d0);

#endif /* INCserInternalh */
