/*********************************  port.h  *******************************
 * $Source: /home/cvs/ESP/gen2/software/msp430/dwarves/port.h,v $
 *  Copyright (C) 2005 MBARI
 *
 *  MBARI Proprietary Information. All rights reserved.
 * $Id: port.h,v 1.1 2005/12/12 21:23:08 brent Exp $
 *
 * Serial Port forwarding for dwarves
 *
 *****************************************************************************/

#include "parser.h"

extern byte portReqTag;    //tag that node wants us to associate with our data
extern byte portFlowReqTag;        //tag associated with outbound flow control

//is the port being forwarded?
#define forwardingSerialPort() validTag(portReqTag)

//resume writing if there's space after a flow controlled shutdown
#macro serialPortTic(resumeThreshold)
{
  size_t free;
  if (validTag(portFlowReqTag) &&
        (free=FIFOfree(debugPort.output)) >= resumeThreshold )
    resumeSerialWriteFlow(free);
}
#endm


//initialize -- cancel port forwarding
void initSerialPort(void);

//cancel port forwarding
void cancelSerialForwarding(void);


//configure the specified serial channel
//reply with error code
void doSerialConfigureRequest(unsigned src,unsigned tag,unsigned reqLen);


//reply with current serial port configuration
void doSerialGetConfigRequest(unsigned src,unsigned tag,unsigned reqLen);


//reply with information about our one available serial channel
void doSerialInfoRequest(unsigned src,unsigned tag,unsigned reqLen);


//write the requested string and reply with the # of bytes written
void doSerialWriteRequest(unsigned src,unsigned tag,unsigned reqLen);


//flush serial buffers and/or assert RS-232 break condition
void doSerialFlushMsg(unsigned msgLen);


//forward received bytes to the requester
void doSerialReadRequest(unsigned src,unsigned tag,unsigned reqLen);


//forward bytes just received to requester
//(call with interrupts disabled)
//return true interrupts were enabled
boolean forwardSerial(void);


//record serial port error
//returns true if system should reset
boolean recordSerialPortErr (byte usartErr);


//resume writing after flow shutdown
void resumeSerialWriteFlow(size_t bytesFree);

