4 * BRIEF MODULE DESCRIPTION
5 * Low Level Serial Port control for use
6 * with the Galileo EVB64120A MIPS eval board and
7 * its on board two channel 16552 Uart.
9 * Copyright (C) 2000 RidgeRun, Inc.
10 * Author: RidgeRun, Inc.
11 * glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
21 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * You should have received a copy of the GNU General Public License along
30 * with this program; if not, write to the Free Software Foundation, Inc.,
31 * 675 Mass Ave, Cambridge, MA 02139, USA.
36 // Serial CHANNELS - 0 is the bottom connector of evb64120A.
37 // (The one that maps to the "B" channel of the
39 // 1 is the top connector of evb64120A.
40 // (The one that maps to the "A" channel of the
42 int DEBUG_CHANNEL = 0; // See Note Above
43 int CONSOLE_CHANNEL = 1; // See Note Above
45 #define DUART 0xBD000000 /* Base address of Uart. */
46 #define CHANNELOFFSET 0x20 /* DUART+CHANNELOFFSET gets you to the ChanA
47 register set of the 16552 Uart device.
48 DUART+0 gets you to the ChanB register set.
50 #define DUART_DELTA 0x4
51 #define FIFO_ENABLE 0x07
52 #define INT_ENABLE 0x04 /* default interrupt mask */
73 #define ACCESS_DELAY 0x10000
75 /******************************
78 ******************************/
79 int inreg(int channel, int reg)
83 *((volatile unsigned char *) DUART +
84 (channel * CHANNELOFFSET) + (reg * DUART_DELTA));
88 /******************************
91 ******************************/
92 void outreg(int channel, int reg, unsigned char val)
94 *((volatile unsigned char *) DUART + (channel * CHANNELOFFSET)
95 + (reg * DUART_DELTA)) = val;
98 /******************************
101 Initialize the device driver.
102 ******************************/
103 void serial_init(int channel)
106 * Configure active port, (CHANNELOFFSET already set.)
108 * Set 8 bits, 1 stop bit, no parity.
110 * LCR<7> 0 divisor latch access bit
111 * LCR<6> 0 break control (1=send break)
112 * LCR<5> 0 stick parity (0=space, 1=mark)
113 * LCR<4> 0 parity even (0=odd, 1=even)
114 * LCR<3> 0 parity enable (1=enabled)
115 * LCR<2> 0 # stop bits (0=1, 1=1.5)
116 * LCR<1:0> 11 bits per character(00=5, 01=6, 10=7, 11=8)
118 outreg(channel, LCR, 0x3);
120 outreg(channel, FCR, FIFO_ENABLE); /* Enable the FIFO */
122 outreg(channel, IER, INT_ENABLE); /* Enable appropriate interrupts */
125 /******************************
129 ******************************/
130 void serial_set(int channel, unsigned long baud)
132 unsigned char sav_lcr;
135 * Enable access to the divisor latches by setting DLAB in LCR.
138 sav_lcr = inreg(channel, LCR);
144 outreg(channel, LCR, LCR_DLAB | sav_lcr);
145 // outreg(DLL,(XTAL/(16*2*(baud))-2));
146 outreg(channel, DLL, XTAL / (16 * baud));
147 // outreg(DLM,(XTAL/(16*2*(baud))-2)>>8);
148 outreg(channel, DLM, (XTAL / (16 * baud)) >> 8);
151 * Note: Set baud rate, hardcoded here for rate of 115200
152 * since became unsure of above "baud rate" algorithm (??).
154 outreg(channel, LCR, 0x83);
155 outreg(channel, DLM, 0x00); // See note above
156 outreg(channel, DLL, 0x02); // See note above.
157 outreg(channel, LCR, 0x03);
161 * Restore line control register
163 outreg(channel, LCR, sav_lcr);
167 /******************************
170 Transmit a character.
171 ******************************/
172 void serial_putc(int channel, int c)
174 while ((inreg(channel, LSR) & LSR_THRE) == 0);
175 outreg(channel, THR, c);
178 /******************************
181 Read a received character if one is
182 available. Return -1 otherwise.
183 ******************************/
184 int serial_getc(int channel)
186 if (inreg(channel, LSR) & LSR_DR) {
187 return inreg(channel, RBR);
192 /******************************
195 Used by embedded gdb client. (example; gdb-stub.c)
196 ******************************/
200 while ((val = serial_getc(DEBUG_CHANNEL)) == -1); // loop until we get a character in.
204 /******************************
207 Used by embedded gdb target. (example; gdb-stub.c)
208 ******************************/
209 void putDebugChar(char c)
211 serial_putc(DEBUG_CHANNEL, (int) c);