// SIO.H - Definitions for SIO.C
// Written by Stefan Pfeiffer, DL1ELY, 950513
// Last Modification: 950824
// (C) 1995 by Stefan Pfeiffer, DL1ELY

#ifndef SIO_H

#define SIO_H

// Registeroffsets
#define OFS_LCR    3
#define OFS_RX     0
#define OFS_TX     0
#define OFS_IER    1
#define OFS_IIR    2
#define OFS_FCR    2    // Nur 16550-UART
#define OFS_MCR    4
#define OFS_LSR    5
#define OFS_MSR    6


#define MAX_BAUD   115200

#define PORT8259_1 0x20
#define PORT8259_2 0xA0  // Nur AT!

#define OFS_OCW2   0
#define OFS_OCW1   1
#define EOI        0x20


#define COM_USED   1
#define UART_16550 2


#define IIR_MASK   7
#define IIR_ERROR  6
#define LSR_ERROR  0x1E
#define LSR_RX     1
#define IIR_RX     4
#define IIR_TX     2


typedef unsigned char BYTE;
typedef unsigned long ULONG;
typedef unsigned int  WORD;


struct port_des
{
   BYTE  used;
   ULONG baudrate;
   WORD  base;
   BYTE  irq;
   BYTE  com;
   BYTE  tx_empty;

   BYTE *rx_buf;
   volatile WORD  rx_read;
   volatile WORD  rx_write;
   WORD  rx_size;
   volatile ULONG rx_sum;

   BYTE *tx_buf;
   volatile WORD  tx_read;
   volatile WORD  tx_write;
   WORD  tx_size;
   volatile ULONG tx_sum;

   volatile WORD  error;
   void interrupt (*old_handler)();
};

extern struct port_des *com[5];

void sio_init_port(struct port_des *);
void sio_tx(struct port_des *,unsigned int, char *);
void sio_rx(struct port_des *,unsigned int,char *);
unsigned sio_rx_bytes(struct port_des *);
void sio_close_port(struct port_des *);

#endif

