/************************************************************************/
/* Copyright 2003 MBARI													*/
/************************************************************************/
/* Summary	: Definitions for the OASIS3 Serial I/O						*/
/* Filename : serial.h													*/
/* Author	: Robert Herlien (rah)										*/
/* Project	: OASIS Mooring Replacement (OASIS3)						*/
/* Revision: 0.1														*/
/* Created	: 10/17/2002												*/
/*																			*/
/* 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:												*/
/* 17oct2002 rah - created from OASIS io.h								*/
/************************************************************************/

#ifndef INCserialh
#define INCserialh		1


/****************************************/
/* Miscellaneous typedefs and defines	*/
/****************************************/
#define PHYS_SER_PORTS	8				/* 8 physical serial ports			*/

#define physSer(virt)	((virt < PHYS_SER_PORTS) ? virt : 0)
#define isPhysSer(virt) (virt < PHYS_SER_PORTS)

#define CPU_SER			0				/* CPU serial port is port 0		*/
#define XON				0x11			/* Xon ASCII character				*/
#define XOFF			0x13			/* Xoff ASCII character				*/

#define TXBUFSIZE		256
#define RXBUFSIZE		1024
#define BIG_TXBUFSIZE	1024

/* Bit definitions for serMode word passed to serPortInit()					*/
/* Note - serMode is a Nat16, so only LSB 16 bits of SER_SETUP are valid	*/

#define PTY_MASK		3				/* Parity is bits 0, 1				*/
#define NO_PTY			0				/* No parity						*/
#define EVEN_PTY		1				/* Even parity						*/
#define ODD_PTY			2				/* Odd parity						*/
#define BIT8			0				/* 8 bit characters					*/
#define BIT7			4				/* 7 bit characters					*/
#define STOP2			8				/* 2 stop bits						*/
#define STOP1			0				/* 1 stop bit						*/

#define FLOW			0x10			/* Bit 4 on for XON/XOFF flow control*/
#define ECHO			0x20			/* Bit 5 on for local echo mode		*/
#define NMODE			0xc0			/* Bits 6 & 7 are \n mode			*/
#define AUTOCR			0x40			/* 01 = Add CR before LF			*/
#define NEWCR			0x80			/* 10 = Replace newline with CR		*/
#define NOLF			0xc0			/* 11 = Don't output LF				*/
#define LF_NORMAL		0x00			/* 00 = Leave LF alone				*/
#define BIG_TX_BUF		0x100			/* Bit 8 = Set TxBuf to 1024		*/

typedef enum {COMMS_OFF, RS232, SEND485, RCV485} CommsMode;


/****************************************/
/* Function Declarations				*/
/****************************************/

Void	getSerialPort(Nat16 serport);
Void	releaseSerialPort(Nat16 serport);
MBool	serPortInit(Nat16 port, Nat32 baud, Nat32 mode);
Void	serPortClose(Nat16 port, MBool makeOutput);
MBool	ser_putc(Nat16 port, Byte byte);
Int16	ser_getc(Nat16 port);
Int16	ser_sndsts(Nat16 port);
Void	ser_waitSend(Nat16 port);
Int16	serRxCount(Nat16 port);
Void	ser_iflush(Nat16 port);
Void	ser_oflush(Nat16 port);
Nat16	serGetRxOvflCnt(Nat16 port);
Void	ser_break(Nat16 port, Int16 count);
Int32	ser_read(Nat16 port, char *buffer, Int32 nbytes, Int32 tmout);
Int32	ser_write(Nat16 port, const char *buffer, Int32 nbytes, Int32 tmout);
Void	ser_init(Void);
Void	serEnableRxInt(Nat16 port);
Void	serDisableRxInt(Nat16 port);
Void	serCheckXoffStatus(Void);
#ifdef DEBUG_SERIAL_CMD
Int16	serDump(Nat16 pmask, Parm_t serchan);
#endif

#endif	/* INCserialh */
