/* -- pcserial.h -- Tony Givargis Interrupt driven PC serial interface. */ /*---------------------------------------------------------------------------*/ #ifndef __pcserial_h__ #define __pcserial_h__ /*---------------------------------------------------------------------------*/ #include "l_queue.h" /*---------------------------------------------------------------------------*/ /* EL_Port Serial Port enumeration/ */ typedef enum { COM1, COM2 } EL_Port; /*---------------------------------------------------------------------------*/ /* EL_Parity Serial Port's pariy enumeration. */ typedef enum { NONE, ODD, EVEN } EL_Parity; /*---------------------------------------------------------------------------*/ /* EL_SerialPort Returned by EL_SerialPortCreate function as the ADT identifier (handle) of a serial i/0 port. */ typedef struct { EL_Queue* queue; unsigned comInt; unsigned comAdr; unsigned lcr; unsigned baudHi; unsigned baudLo; unsigned pic; void* oldISR; } EL_SerialPort; /*---------------------------------------------------------------------------*/ /* EL_SerialPort Initializes the (port) and returns an EL_SerialPort* on success or NULL otherwise to be use in subsequent calls to serial port functions. */ EL_SerialPort* EL_SerialPortCreate(EL_Port port, EL_Parity parity, long baudRate, int dataBits, int stopBits); /*---------------------------------------------------------------------------*/ /* EL_SerialPortClose Destroys (serialPort). */ void EL_SerialPortDestroy(EL_SerialPort* serialPort); /*---------------------------------------------------------------------------*/ /* EL_SerialPortRead Reads from (serialPort) (szBuf) bytes into (buf). Returns the number of bytes actually read. The use of EL_SerialPortQueueSize before a call to this function is recommended. */ unsigned EL_SerialPortRead(EL_SerialPort* serialPort, void* buf, unsigned szBuf); /*---------------------------------------------------------------------------*/ /* EL_SerialPortWrite Writes to (serialPort) (szBuf) bytes from (buf). */ void EL_SerialPortWrite(EL_SerialPort* serialPort, void* buf, unsigned szBuf); /*---------------------------------------------------------------------------*/ /* EL_SerialPortQueueSize Returns the number of elements availabe for read in receive queue of (serialPort). */ #define EL_SerialPortQueueSize(serialPort) EL_QueueSize((serialPort)->queue) /*---------------------------------------------------------------------------*/ #endif