00001 00006 /* Embedded XINU, Copyright (C) 2007. All rights reserved. */ 00007 00008 #ifndef __XINU_SERIAL_H__ 00009 #define __XINU_SERIAL_H__ 00010 00011 #include <semaphore.h> 00012 #include <device.h> 00013 00018 struct uart_csreg 00019 { 00020 volatile uchar buffer; 00022 volatile uchar ier; 00023 volatile uchar iir; 00025 volatile uchar lcr; 00026 volatile uchar mcr; 00027 volatile uchar lsr; 00028 volatile uchar msr; 00029 volatile uchar scr; 00030 }; 00031 00032 /* Alternative names for control and status registers */ 00033 #define rbr buffer 00034 #define thr buffer 00035 #define fcr iir 00036 #define dll buffer 00037 #define dlm ier 00039 /* UART Bit flags for control and status registers */ 00040 /* Interrupt enable bits */ 00041 #define UART_IER_ERBFI 0x01 00042 #define UART_IER_ETBEI 0x02 00043 #define UART_IER_ELSI 0x04 00044 #define UART_IER_EMSI 0x08 00046 /* Interrupt identification masks */ 00047 #define UART_IIR_IRQ 0x01 00048 #define UART_IIR_IDMASK 0x0E 00049 #define UART_IIR_MSC 0x00 00050 #define UART_IIR_THRE 0x02 00051 #define UART_IIR_RTO 0x04 00052 #define UART_IIR_RLSI 0x06 00053 #define UART_IIR_RDA 0x0C 00055 /* FIFO control bits */ 00056 #define UART_FCR_EFIFO 0x01 00057 #define UART_FCR_RRESET 0x02 00058 #define UART_FCR_TRESET 0x04 00059 #define UART_FCR_TRIG0 0x00 00060 #define UART_FCR_TRIG1 0x40 00061 #define UART_FCR_TRIG2 0x80 00062 #define UART_FCR_TRIG3 0xC0 00064 /* Line control bits */ 00065 #define UART_LCR_DLAB 0x80 00066 #define UART_LCR_8N1 0x03 00068 /* Modem control bits */ 00069 #define UART_MCR_OUT2 0x08 00070 #define UART_MCR_LOOP 0x10 00072 /* Line status bits */ 00073 #define UART_LSR_DR 0x01 00074 #define UART_LSR_THRE 0x20 00075 #define UART_LSR_TEMT 0x40 00077 #define UART_FIFO_LEN 64 00079 /* UART Buffer lengths */ 00080 #define UART_IBLEN 1024 00081 #define UART_OBLEN 1024 00082 00083 /* UART 16550 control block */ 00084 struct uart 00085 { 00086 /* Pointers to associated structures */ 00087 struct uart_csreg *csr; 00088 device *dev; 00090 /* Statistical Counts */ 00091 long cout; 00092 long cin; 00093 long lserr; 00094 long ovrrn; 00095 long iirq; 00096 long oirq; 00098 /* UART input fields */ 00099 uchar iflags; 00100 semaphore isema; 00101 ushort istart; 00102 ushort icount; 00103 uchar in[UART_IBLEN]; 00105 /* UART output fields */ 00106 uchar oflags; 00107 semaphore osema; 00108 ushort ostart; 00109 ushort ocount; 00110 uchar out[UART_OBLEN]; 00111 bool oidle; 00112 }; 00113 00114 extern struct uart uarttab[]; 00115 00116 /* UART input flags */ 00117 #define UART_IFLAG_NOBLOCK 0x0001 00118 #define UART_IFLAG_ECHO 0x0002 00120 /* UART output flags */ 00121 #define UART_OFLAG_NOBLOCK 0x0001 00123 /* uartControl() functions */ 00124 #define UART_IOC_SETIFLAG 0x0010 00125 #define UART_IOC_CLRIFLAG 0x0011 00126 #define UART_IOC_GETIFLAG 0x0012 00127 #define UART_IOC_SETOFLAG 0x0013 00128 #define UART_IOC_CLROFLAG 0x0014 00129 #define UART_IOC_GETOFLAG 0x0015 00130 #define UART_IOC_OUTPUT_IDLE 0x0016 00132 /* Driver functions */ 00133 devcall uartInit(device *); 00134 devcall uartRead(device *, unsigned char *, int); 00135 devcall uartWrite(device *, unsigned char *, int); 00136 devcall uartGetChar(device *); 00137 devcall uartPutChar(device *, unsigned char); 00138 devcall uartControl(device *, int, unsigned char, unsigned char); 00139 interrupt uartIntr(void); 00140 00141 #endif /* _UART_H_ */