/* ********************************************************************************* * Copyright (c) 2005 ASIX Electronic Corporation All rights reserved. * * This is unpublished proprietary source code of ASIX Electronic Corporation * * The copyright notice above does not evidence any actual or intended * publication of such source code. ********************************************************************************* */ /*================================================================================ * Module Name : uart.c * Purpose : The UART module driver. It manages the character * buffer and handles the ISR. This driver includes UART0 and UART1. * Author : Robin Lee * Date : 2006-01-10 * Notes : None. * $Log: uart.c,v $ * Revision 1.1 2006/04/07 11:39:14 robin6633 * no message * *================================================================================ */ /* INCLUDE FILE DECLARATIONS */ #include "../ax110xx.h" #include "uart.h" #if HSUR_ENABLE #include "hsuart.h" #endif /* STATIC VARIABLE DECLARATIONS */ #if UART0_ENABLE static unsigned char uart0_TxBuf[MAX_TX_UART0_BUF_SIZE]; static unsigned int uart0_TxHead = 0; static unsigned int uart0_TxTail = 0; static unsigned int uart0_TxCount = 0; static unsigned char uart0_TxFlag = 0; static unsigned char uart0_RxBuf[MAX_RX_UART0_BUF_SIZE]; static unsigned int uart0_RxHead = 0; static unsigned int uart0_RxTail = 0; static unsigned char uart0_Mode = 0; unsigned int uart0_RxCount = 0; #endif #if UART1_ENABLE static unsigned char uart1_TxBuf[MAX_TX_UART1_BUF_SIZE]; static unsigned int uart1_TxHead = 0; static unsigned int uart1_TxTail = 0; static unsigned int uart1_TxCount = 0; static unsigned char uart1_TxFlag = 0; static unsigned char uart1_RxBuf[MAX_RX_UART1_BUF_SIZE]; static unsigned int uart1_RxHead = 0; static unsigned int uart1_RxTail = 0; static unsigned char uart1_Mode = 0; unsigned int uart1_RxCount = 0; #endif static unsigned char uartPort = 0; /* LOCAL SUBPROGRAM DECLARATIONS */ #if UART0_ENABLE //void uart0_ISR(void); static void uart0_Init(void); static signed char uart0_PutChar(signed char c); static signed char uart0_GetKey(void); static signed char UART0_NoBlockGetkey(void); #endif #if UART1_ENABLE //void uart1_ISR(void); static void uart1_Init(void); static signed char uart1_PutChar(signed char c); static signed char uart1_GetKey(void); static signed char uart1_NoBlockGetkey(void); #endif /* LOCAL SUBPROGRAM BODIES */ #if UART0_ENABLE /* * ---------------------------------------------------------------------------- * static void UART0_ISR(void) * Purpose : UART0 interrupt service routine. For sending out, it puts data * from software buffer into hardware serial buffer register (SBUF0). * For receiving, it gets data from hardware serial buffer register * (SBUF0) and stores into software buffer. * Params : none * Returns : none * Note : none * ---------------------------------------------------------------------------- */ void uart0_ISR(void) __interrupt 4 __using 2 { unsigned char parity = 0; if (RI0) { EA = 0; if (uart0_RxCount != MAX_RX_UART0_BUF_SIZE) { uart0_RxBuf[uart0_RxHead] = SBUF0; if (uart0_Mode & BIT1) { parity = UART_ParityChk((unsigned char)uart0_RxBuf[uart0_RxHead]); if (RB08 != parity) P3 = 0xE7; } uart0_RxCount++; uart0_RxHead++; uart0_RxHead &= MAX_RX_UART0_MASK; } RI0 = 0; EA = 1; } /* End of if(RI0) */ if (TI0) { EA = 0; uart0_TxTail++; uart0_TxTail &= MAX_TX_UART0_MASK; uart0_TxCount--; if (uart0_TxCount > 0) { SBUF0 = uart0_TxBuf[uart0_TxTail]; if (uart0_Mode & BIT1) { parity = UART_ParityChk((unsigned char)uart0_TxBuf[uart0_TxTail]); if (parity) TB08 = 1; else TB08 = 0; } } else uart0_TxFlag = 0; TI0 = 0; EA = 1; } /* End of if(TI0) */ } /* End of UART_Int */ /* * ---------------------------------------------------------------------------- * static void uart0_Init(void) * Purpose : Setting operation mode of UART0 and initiating the global values. * Params : none * Returns : none * Note : none * ---------------------------------------------------------------------------- */ static void uart0_Init(void) { unsigned char sysClk = 0; unsigned int i; uart0_TxHead = 0; uart0_TxTail = 0; uart0_TxCount = 0; uart0_TxFlag = 0; uart0_RxHead = 0; uart0_RxTail = 0; uart0_RxCount = 0; for (i=0 ; i 0) { SBUF1 = uart1_TxBuf[uart1_TxTail]; if (uart1_Mode & BIT1) { parity = UART_ParityChk((unsigned char)uart1_TxBuf[uart1_TxTail]); if (parity) TB18 = 1; else TB18 = 0; } } else uart1_TxFlag = 0; TI1 = 0; EA = 1; } /* End of if(TI0) */ } /* * ---------------------------------------------------------------------------- * static void uart1_Init(void) * Purpose : Setting operation mode of UART1 and initiating the global values. * Params : none * Returns : none * Note : none * ---------------------------------------------------------------------------- */ static void uart1_Init(void) { unsigned char sysClk = 0; unsigned int i; uart1_TxHead = 0; uart1_TxTail = 0; uart1_TxCount = 0; uart1_TxFlag = 0; uart1_RxHead = 0; uart1_RxTail = 0; uart1_RxCount = 0; for (i=0 ; i