5 * Techware Information Technology, Inc.
6 * http://www.techware.com.tw/
8 * Ming-Len Wu <minglen_wu@techware.com.tw>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #if defined(CONFIG_UART1)
32 #define reg_GIUS MX1_GIUS_C
33 #define reg_GPR MX1_GPR_B
34 #define GPIO_MASK 0xFFFFE1FF
35 #define UART_BASE 0x00206000
37 #elif defined (CONFIG_UART2)
40 #define reg_GIUS MX1_GIUS_C
41 #define reg_GPR MX1_GPR_C
42 #define GPIO_MASK 0x0FFFFFFF
43 #define UART_BASE 0x207000
47 #define reg_URXD (*((volatile u32 *)(UART_BASE+0x00)))
48 #define reg_UTXD (*((volatile u32 *)(UART_BASE+0x40)))
49 #define reg_UCR1 (*((volatile u32 *)(UART_BASE+0x80)))
50 #define reg_UCR2 (*((volatile u32 *)(UART_BASE+0x84)))
51 #define reg_UCR3 (*((volatile u32 *)(UART_BASE+0x88)))
52 #define reg_UCR4 (*((volatile u32 *)(UART_BASE+0x8C)))
53 #define reg_UFCR (*((volatile u32 *)(UART_BASE+0x90)))
54 #define reg_USR1 (*((volatile u32 *)(UART_BASE+0x94)))
55 #define reg_USR2 (*((volatile u32 *)(UART_BASE+0x98)))
56 #define reg_UESC (*((volatile u32 *)(UART_BASE+0x9C)))
57 #define reg_UTIM (*((volatile u32 *)(UART_BASE+0xA0)))
58 #define reg_UBIR (*((volatile u32 *)(UART_BASE+0xA4)))
59 #define reg_UBMR (*((volatile u32 *)(UART_BASE+0xA8)))
60 #define reg_UBRC (*((volatile u32 *)(UART_BASE+0xAC)))
62 #define TXFE_MASK 0x4000 /* Tx buffer empty */
63 #define RDR_MASK 0x0001 /* receive data ready */
65 void serial_setbrg (void) {
67 /* config I/O pins for UART */
68 reg_GIUS &= GPIO_MASK;
83 * Initialise the serial port with the given baudrate. The settings
84 * are always 8 data bits, no parity, 1 stop bit, no start bits.
88 int serial_init (void) {
95 * Read a single byte from the serial port. Returns 1 on success, 0
96 * otherwise. When the function is succesfull, the character read is
97 * written into its argument c.
99 int serial_getc (void) {
101 while (!(reg_USR2 & RDR_MASK)) ; /* wait until RDR bit set */
107 * Output a single byte to the serial port.
109 void serial_putc (const char c) {
111 while (!(reg_USR2 & TXFE_MASK)); /* wait until TXFE bit set */
115 if (c == '\n') { /* carriage return ? append line-feed */
116 while (!(reg_USR2 & TXFE_MASK)); /* wait until TXFE bit set */
123 * Test whether a character is in the RX buffer
125 int serial_tstc (void) {
126 return reg_USR2 & RDR_MASK;
129 void serial_puts (const char *s) {