3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 unsigned int init_rs232 ()
31 int baud
= CONFIG_DRV_RS232BAUDS
; // Set to 9600 baud
33 unsigned divisor
= (unsigned) (115200L / baud
);
35 outb (PORT
+ 1, 0x00); // Disable all interrupts
36 outb (PORT
+ 3, 0x80); // Enable DLAB (set baud rate divisor)
37 outb (PORT
+ 0, divisor
); // Set divisor to 3 (lo byte) 38400 baud
39 outb (PORT
+ 1, divisor
); // (hi byte)
40 outb (PORT
+ 3, 0x03); // 8 bits, no parity, one stop bit
41 outb (PORT
+ 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
42 outb (PORT
+ 4, 0x0B); // IRQs enabled, RTS/DSR set
53 return inb (PORT
+ 5) & 1;
57 char rs232_read_nonblock ()
60 int r
= serial_recieved ();
68 return (char) armbd_uart_read (0);
76 while (serial_recieved () == 0)
82 if (armbd_uart_received (0))
83 return (char) armbd_uart_read (0);
91 int is_transmit_empty ()
93 return inb (PORT
+ 5) & 0x20;
97 void rs232_write (char a
)
100 while (is_transmit_empty() == 0) {
109 armbd_uart_write (0, (unsigned char) a
);
113 bool rs232_acthandler (unsigned act
, char *block
, unsigned block_len
)
127 while (len
!= block_len
) {
128 block
[len
] = rs232_read ();
139 while (len
!= block_len
) {
140 rs232_write (block
[len
]);