Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / kernel / drivers / char / rs232 / rs232.c
blobd39a5a3beb38c4d78d323f87c8c0c9a31254b66c
1 /*
2 * ZeX/OS
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/>.
22 #include <build.h>
23 #include <config.h>
24 #include <system.h>
25 #include <arch/io.h>
26 #include <rs232.h>
28 unsigned int init_rs232 ()
30 #ifdef ARCH_i386
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
38 divisor >>= 8;
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
43 #endif
44 #ifdef ARCH_arm
46 #endif
47 return 1;
50 int serial_recieved()
52 #ifdef ARCH_i386
53 return inb (PORT + 5) & 1;
54 #endif
57 char rs232_read_nonblock ()
59 #ifdef ARCH_i386
60 int r = serial_recieved ();
62 if (r == 0)
63 return 0;
65 return inb (PORT);
66 #endif
67 #ifdef ARCH_arm
68 return (char) armbd_uart_read (0);
69 #endif
73 char rs232_read ()
75 #ifdef ARCH_i386
76 while (serial_recieved () == 0)
77 schedule ();
79 return inb (PORT);
80 #endif
81 #ifdef ARCH_arm
82 if (armbd_uart_received (0))
83 return (char) armbd_uart_read (0);
84 else
85 return 0;
87 #endif
90 #ifdef ARCH_i386
91 int is_transmit_empty ()
93 return inb (PORT + 5) & 0x20;
95 #endif
97 void rs232_write (char a)
99 #ifdef ARCH_i386
100 while (is_transmit_empty() == 0) {
101 schedule ();
102 continue;
105 outb (PORT, a);
106 #endif
108 #ifdef ARCH_arm
109 armbd_uart_write (0, (unsigned char) a);
110 #endif
113 bool rs232_acthandler (unsigned act, char *block, unsigned block_len)
115 switch (act) {
116 case DEV_ACT_INIT:
118 init_rs232 ();
120 return 1;
122 break;
123 case DEV_ACT_READ:
125 unsigned len = 0;
127 while (len != block_len) {
128 block[len] = rs232_read ();
129 len ++;
132 return 1;
134 break;
135 case DEV_ACT_WRITE:
137 unsigned len = 0;
139 while (len != block_len) {
140 rs232_write (block[len]);
141 len ++;
144 return 1;
146 break;
149 return 0;