blob: d38ac39472c4705e7a713e7cbf497abe9d8fcd94 [file] [log] [blame]
wdenkedc48b62002-09-08 17:56:50 +00001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
4 *
5 * (C) Copyright 2002
6 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
8 *
9 * (C) Copyright 2002
10 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
11 * Alex Zuepke <azu@sysgo.de>
12 *
13 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 */
30
31#include <common.h>
32#include <clps7111.h>
33
34void serial_setbrg (void)
35{
36 DECLARE_GLOBAL_DATA_PTR;
37
38 unsigned int reg = 0;
39
40 if (gd->baudrate == 1200)
41 reg = 191;
42 else if (gd->baudrate == 9600)
43 reg = 23;
44 else if (gd->baudrate == 19200)
45 reg = 11;
46 else if (gd->baudrate == 38400)
47 reg = 5;
48 else if (gd->baudrate == 57600)
49 reg = 3;
50 else if (gd->baudrate == 115200)
51 reg = 1;
52 else
53 hang ();
54
55 /* init serial serial 1,2 */
56 IO_SYSCON1 = SYSCON1_UART1EN;
57 IO_SYSCON2 = SYSCON2_UART2EN;
58
59 reg |= UBRLCR_WRDLEN8;
60
61 IO_UBRLCR1 = reg;
62 IO_UBRLCR2 = reg;
63}
64
65
66/*
67 * Initialise the serial port with the given baudrate. The settings
68 * are always 8 data bits, no parity, 1 stop bit, no start bits.
69 *
70 */
71int serial_init (void)
72{
73 serial_setbrg ();
74
75 return (0);
76}
77
78
79/*
80 * Output a single byte to the serial port.
81 */
82void serial_putc (const char c)
83{
84 int tmo;
85
86 /* If \n, also do \r */
87 if (c == '\n')
88 serial_putc ('\r');
89
90 tmo = get_timer (0) + 1 * CFG_HZ;
91 while (IO_SYSFLG1 & SYSFLG1_UTXFF)
92 if (get_timer (0) > tmo)
93 break;
94
95 IO_UARTDR1 = c;
96}
97
98/*
99 * Read a single byte from the serial port. Returns 1 on success, 0
100 * otherwise. When the function is succesfull, the character read is
101 * written into its argument c.
102 */
103int serial_tstc (void)
104{
105 return !(IO_SYSFLG1 & SYSFLG1_URXFE);
106}
107
108/*
109 * Read a single byte from the serial port. Returns 1 on success, 0
110 * otherwise. When the function is succesfull, the character read is
111 * written into its argument c.
112 */
113int serial_getc (void)
114{
115 while (IO_SYSFLG1 & SYSFLG1_URXFE);
116
117 return IO_UARTDR1 & 0xff;
118}
119
120void
121serial_puts (const char *s)
122{
123 while (*s) {
124 serial_putc (*s++);
125 }
126}