diff --git a/serial.c b/serial.c index 391c356..e107ec2 100644 --- a/serial.c +++ b/serial.c @@ -6,7 +6,7 @@ #define SERIAL_USB -#ifdef SERIAL_UART +#if defined(SERIAL_UART) #define UART_IS_DLL 0x100 #define UART_IS_LCR 0x200 @@ -48,17 +48,6 @@ enum uart_baudrate { }; #define UART_BAUD_RATE UART_115200 -#if 0 -/* 26MHz clock input (used when no PLL initialized directly after poweron) */ -static const uint16_t divider[] = { - [UART_38400] = 42, - [UART_57600] = 28, - [UART_115200] = 14, - [UART_230400] = 7, - [UART_460800] = 14, /* would need UART_REG(HIGHSPEED) = 1 or 2 */ - [UART_921600] = 7, /* would need UART_REG(HIGHSPEED) = 2 */ -}; -#else /* 52MHz clock input (after PLL init) */ static const uint16_t divider[] = { [UART_38400] = 85, @@ -68,7 +57,6 @@ static const uint16_t divider[] = { [UART_460800] = 7, [UART_921600] = 7, /* would need UART_REG(HIGHSPEED) = 1 */ }; -#endif static uint8_t uart_getreg(int regnum) { @@ -133,20 +121,20 @@ void serial_init(void) { int tmp; - // Setup 8-N-1,(UART_WLS_8 | UART_NONE_PARITY | UART_1_STOP) = 0x03 + /* Setup 8-N-1,(UART_WLS_8 | UART_NONE_PARITY | UART_1_STOP) = 0x03 */ uart_setreg(UART_LCR, 0x03); - // Set BaudRate - // config by UART_BAUD_RATE(9:115200) + /* Set BaudRate + * config by UART_BAUD_RATE(9:115200) + */ uart_setreg(UART_DLL, divider[UART_BAUD_RATE]&0xff); uart_setreg(UART_DLH, divider[UART_BAUD_RATE]>>8); uart_setreg(UART_LCR, 0x03); - // Enable Fifo, and Rx Trigger level = 16bytes, flush Tx, Rx fifo - // (UART_FCR_FIFOEN | UART_FCR_4Byte_Level | UART_FCR_RFR | UART_FCR_TFR) = 0x47 + /* Enable Fifo, and Rx Trigger level = 16bytes, flush Tx, Rx fifo */ uart_setreg(UART_FCR, 0x47); - // DTR , RTS is on, data will be coming,Output2 is high + /* DTR , RTS is on, data will be coming, Output2 is high */ uart_setreg(UART_MCR, 0x03); /* Set up normal interrupts */ @@ -155,7 +143,7 @@ void serial_init(void) /* Pause a while */ for (tmp=0; tmp<0xff; tmp++); } -#else /* SERIAL_USB */ +#elif defined(SERIAL_USB) #include "fernvale-usb.h" @@ -358,7 +346,6 @@ void serial_init(void) writeb(USB_CTRL_EP_INCSR1_FLUSHFIFO, USB_CTRL_EP_INCSR1); /* Set up FIFO to automatically transmit when the buffer is full */ - //writeb(USB_CTRL_EP_INCSR2_AUTOSET, USB_CTRL_EP_INCSR2); writeb(0, USB_CTRL_EP_INCSR2); /* Set the USB mode to OUT, to ensure we receive packets from host */ @@ -369,4 +356,6 @@ void serial_init(void) usb_handle_irqs(1); } -#endif /* !SERIAL_UART */ +#else /* SERIAL_USB || SERIAL_UART */ +#error "No serial port defined! Must define SERIAL_USB or SERIAL_UART" +#endif /* SERIAL_USB || SERIAL_UART */