

#ifndef _VXCARD_H_

#define _VXCARD_H_



#define  WORD  unsigned int

#define  DWORD unsigned long



/* Register Offset */

#define VXC_RESET             0x0

#define VXC_AUX_CONTROL       0x2

#define VXC_AUX_DATA          0x3

#define VXC_AUX_STATUS        0x7



#define VXC_INT_MASK          0x5

#define VXC_INT_POLARITY      0x2A



#define VXC_PORT1             0xC0

#define VXC_PORT2             0xE0

#define VXC_PORT1_SPEED_MODE  0xDC

#define VXC_PORT2_SPEED_MODE  0xFC



#define VXC_BOARD_ID          0xDC



/* Values */

#define VXC_LOW_SPEED         0x00

#define VXC_HIGH_SPEED        0x02



#define VXC_LED_OFF           0x00 // Off all output state

#define VXC_142_CONFIG        0x80 // Aux7 for LED Output, Aux0/1 for Int Input

#define VXC_182i_CONFIG       0x80

#define VXC_112A_CONFIG       0x20 // Aux5 for LED Output, Aux2/3 for Int Input

#define VXC_142_LED_ON        0x80 // Aux7 for LED On

#define VXC_182i_LED_ON       0x80

#define VXC_112A_LED_ON       0x20 // Aux5 for LED On



#define THR   0   /* Transmitter Holding Register, tx buffer */

#define RBR   0   /* Receiver Buffer Register    , rx buffer */

#define DLL   0   /* Baud LSB        */

#define DLH   1   /* Baud MSB        */

#define IER   1   /* Interrupt Enable Register    */

#define FCR   2   /* FIFO Control Register        */

#define LCR   3   /* Line Control Register        */

#define DFR   3   /* Data Format Register         */

#define MCR   4   /* Modem Control Register       */

#define LSR   5   /* Line Status Register         */



#define VXC_THR    0   /* Transmitter Holding Register, tx buffer */

#define VXC_RBR    0   /* Receiver Buffer Register    , rx buffer */

#define VXC_DLL    0   /* Baud LSB        */

#define VXC_DLH    4   /* Baud MSB        */

#define VXC_IER    4   /* Interrupt Enable Register    */

#define VXC_FCR    8   /* FIFO Control Register        */

#define VXC_IIR    8   /* Interrupt Identify Register  */

#define VXC_LCR   12   /* Line Control Register        */

#define VXC_DFR   12   /* Data Format Register         */

#define VXC_MCR   16   /* Modem Control Register       */

#define VXC_LSR   20   /* Line Status Register         */



// Error Codes

#define  VXC_NoError            0

#define  VXC_InvalidBaudrate    1

#define  VXC_InvalidDataFormat  2

#define  VXC_Timeout            3

#define  VXC_ChecksumError      4





/* Configure the AUX I/O direction for VXC series */

// wBase   : Base Address

// bConfig : VXC_142_CONFIG, VXC_182i_CONFIG

#define Vxc_SetConfig(wBase,bConfig)\

outportb((wBase)+VXC_AUX_CONTROL,(bConfig))



/* Set VXC Card LED On or Off */

// wBase  : Base Address

// bOnOff : VXC_LED_OFF, VXC_142_LED_ON, VXC_182i_LED_ON

#define Vxc_SetLed(wBase,bOnOff)\

outportb((wBase)+VXC_AUX_DATA,(bOnOff))



/* Read VXC Card Board ID number */

// wBase : Base Address

#define Vxc_GetBoardID(wBase)\

(0xFF & ~inportb((wBase)+VXC_BOARD_ID))



// Set the base Clcok Rate

// wBase    : Base Address

// bChannel : 0 for Port1, 1 for Port2

// bMode    : VXC_LOW_SPEED VXC_HIGH_SPEED clock

#define Vxc_SetSpeedMode(wBase,bChannel,bMode)\

outportb((wBase)+VXC_PORT1_SPEED_MODE+0x20*bChannel,(bMode))





int Vxc_OpenCom( WORD wPortAddr, DWORD dwBaudRate, char szFormat[]);

int Vxc_CloseCom(WORD wPortAddr);



int Vxc_SendChar(   WORD wPortAddr, int ch,  WORD wTimeout);

int Vxc_ReceiveChar(WORD wPortAddr, int *ch, WORD wTimeout);



int Vxc_SendCmd(    WORD wPortAddr, char cCmd[], DWORD lTimeout, int iChksum);

int Vxc_ReceiveCmd( WORD wPortAddr, char cCmd[], DWORD lTimeout, int iChksum);



#endif

