/************************************************************************* ** ** Broadcom Corp. Confidential ** Copyright 1999, 2000 Broadcom Corp. All Rights Reserved. ** ** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE ** AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR ** EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. ** ** File: serial.h ** Description: polled uart io ** Created: Jeff Fisher ** REVISION: ** ****************************************************************************/ #include "serial.h" /***********************************************************************/ /* serial_init(UartChannel *uart,unsigned int baud)*/ /***********************************************************************/ void serial_init(volatile UartChannel *uart, unsigned int baud) { #if (BCHP_CHIP==7550) uart->sdw_lsr = 0; #else /*---------------------------------------------------------------------*/ /* Dissable channel's receiver and transmitter. */ /*---------------------------------------------------------------------*/ uart->control = 0; // uart->control &= ~(TXEN|RXEN); /*---------------------------------------------------------------------*/ /* disable interrupts on this channel . */ /*---------------------------------------------------------------------*/ uart->rxstat = 0; uart->txstat = 0; /*-----------------------------------------------------------------*/ /* set character size and parity control bit (8,none only) */ /*-----------------------------------------------------------------*/ uart->control = BITM8; baud = ((XTALFREQ / baud) /16); uart->baudh = (unsigned char)((baud >> 8) & 0xFF); uart->baudl = (unsigned char)(baud & 0xFF); /*---------------------------------------------------------------------*/ /* Finally, re-enable the transmitter and receiver. */ /*---------------------------------------------------------------------*/ uart->control |= (TXEN|RXEN); #endif } /***********************************************************************/ /* serial_getc(UartChannel *uart, int block)*/ /***********************************************************************/ #define RXRDA 0x01 #define RXOVFERR 0x02 #define RXPARERR 0x04 #define RXFRAMERR 0x08 #define RXBIERR 0x10 /* BI error */ #define RXFIFOERR 0x80 /* Rx FIFO error */ int serial_getc(volatile UartChannel *uart, bool block) { #if (BCHP_CHIP==7550) int blen = 1; unsigned int status; char tval; while (blen > 0) { status = uart->sdw_lsr; if(status & (RXOVFERR | RXPARERR | RXFRAMERR | RXBIERR | RXFIFOERR)) { /* Just read the bad character to clear the bit. */ tval = uart->sdw_rbr_thr_dll & 0xFF; } else if(status & RXRDA) { tval = uart->sdw_rbr_thr_dll & 0xFF; blen--; } else { /* block if required */ if (!block) { return 0; } } } return tval; #else if (!block) { if (!(uart->rxstat & RXDATARDY)) { return 0; } } while (!(uart->rxstat & RXDATARDY)) ; return (unsigned char)uart->rxdata; #endif } /***********************************************************************/ /* serial_putc(UartChannel *uart, unsigned int c)*/ /***********************************************************************/ static inline void serial_do_putc(volatile UartChannel *uart, int c) { #if (BCHP_CHIP==7550) while (!(uart->sdw_lsr & THRE)) ; uart->sdw_rbr_thr_dll = (unsigned char)c; #else while (!(uart->txstat & TXDREGEMT)) ; uart->txdata = (unsigned char)c; #endif } /***********************************************************************/ /* serial_putc(UartChannel *uart, unsigned int c)*/ /***********************************************************************/ void serial_putc(volatile UartChannel *uart, int c) { serial_do_putc(uart,c); }