/****************************************************************************/
/* Copyright 2009 MBARI.                                                    */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
#ifndef SERIAL_H
#define SERIAL_H

//buffer that can be used for sprintf()
#define MSG_BUFF_SZ 64
extern char Msg_Buff[];

//init registers, init software buffers, install IRQ
void serInit();
//set new baudrate
int serSetBaud(int port, ULONG baud);

//remove and return one byte from serial buffer
int serGetByte(int port, unsigned char* b);
//get next byte from buffer, but leave it in buffer
unsigned char serPeek(int port);
//fill buffer until "period" has elapsed
int serGetSTO(int port, char* buffer, int buflen, ULONG period);
//fill buffer until a char in "ends" is found
int serGetUntil(int port, const char* ends, char* buffer, int buflen);
//scan input until "targ" is matched(true) or "term"(false)
int serScanUntil(int port, char* targ, const char* term);
//scan input until "targ" or timeout
int serScanTO(int port, char* targ, ULONG period);


//place a byte in port's SW Tx buffer
int serPutChar(int port, char b);
//send a string to port's SW Tx buffer
int serPutString(int port, char* buff);
//send a string to console if not in "terse" mode
int serPutSDebug(char* buff);
//force a byte onto HW Tx buffer
int serSetByte(int port, BYTE b);


//return number of bytes in ports buffer
int serIsAvail(int port);
//true if Rx buffer has no space left
int serIsRxFull(int port);
//true if Tx buffer has no space left
int serIsTxFull(int port);

//did the Rx buffer overflow
int serGetRxOverFlow(int port);
//clear overflow flag
void serClrRxOverFlow(int port);

//clear the contents of port's Rx buffers
void serRxFlush(int port);
//clear the port's Tx buffers
void serTxFlush(int port);
//wait untill all bytes are sent from port
void serTxWait(int port);

#endif

