Rev 538 | Rev 715 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
538 | mauro | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * Massimiliano Giorgi <massy@gandalf.sssup.it> |
||
11 | * Luca Abeni <luca@gandalf.sssup.it> |
||
12 | * (see the web pages for full authors list) |
||
13 | * |
||
14 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
15 | * |
||
16 | * http://www.sssup.it |
||
17 | * http://retis.sssup.it |
||
18 | * http://shark.sssup.it |
||
19 | */ |
||
20 | |||
21 | /* |
||
22 | * Copyright (C) 2000 Paolo Gai |
||
23 | * |
||
24 | * This program is free software; you can redistribute it and/or modify |
||
25 | * it under the terms of the GNU General Public License as published by |
||
26 | * the Free Software Foundation; either version 2 of the License, or |
||
27 | * (at your option) any later version. |
||
28 | * |
||
29 | * This program is distributed in the hope that it will be useful, |
||
30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
32 | * GNU General Public License for more details. |
||
33 | * |
||
34 | * You should have received a copy of the GNU General Public License |
||
35 | * along with this program; if not, write to the Free Software |
||
36 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
37 | * |
||
38 | */ |
||
39 | |||
40 | /* Serial communication device */ |
||
41 | /* This implementation is capable of handling 4 distinct COM ports */ |
||
42 | /* The COM port settings are the standard PC settings: */ |
||
43 | /* PORT ADDRESS IRQ */ |
||
44 | /* 1 0x3F8 4 */ |
||
45 | /* 2 0x2F8 3 */ |
||
46 | /* 3 0x3E8 4 */ |
||
47 | /* 4 0x2E8 2 */ |
||
48 | |||
49 | /* By Massy |
||
50 | * I have modified the fast handler routines to support serial |
||
51 | * mouse better (see below) |
||
52 | */ |
||
53 | |||
54 | #include <kernel/kern.h> |
||
55 | #include <drivers/scom.h> |
||
56 | |||
57 | /* Base address for each standard COM link */ |
||
58 | static unsigned com_base[] = {0x03F8,0x02F8,0x03E8,0x02E8}; |
||
59 | |||
60 | /* Used for decoding the IIR status */ |
||
61 | const int IIRbits[] = {MS_CHANGED,TX_EMPTY,RX_FULL,LS_CHANGED}; |
||
62 | |||
63 | /* Register level access functions */ |
||
64 | |||
65 | unsigned com_read(unsigned port,unsigned reg) |
||
66 | { |
||
67 | unsigned b; |
||
68 | if (port > 3 || reg > 7) return(0); |
||
69 | b = ll_in(com_base[port]+reg); |
||
70 | return(b); |
||
71 | } |
||
72 | |||
73 | void com_write(unsigned port,unsigned reg,unsigned value) |
||
74 | { |
||
75 | if (port > 3 || reg > 7) return; |
||
76 | ll_out(com_base[port]+reg,value); |
||
77 | } |
||
78 | |||
79 | /* Polled send/receive */ |
||
80 | |||
81 | void com_send(unsigned port,BYTE b) |
||
82 | { |
||
83 | while ((com_read(port,LSR) & 32) == 0); |
||
84 | com_write(port,THR,b); |
||
85 | } |
||
86 | |||
87 | unsigned com_receive(unsigned port) |
||
88 | { |
||
89 | while ((com_read(port,LSR) & 1) == 0); |
||
90 | return(com_read(port,RBR)); |
||
91 | } |
||
92 | |||
93 | /* Initialize a serial channel */ |
||
94 | |||
95 | int com_open(unsigned port,DWORD speed,BYTE parity,BYTE len,BYTE stop) |
||
96 | { |
||
97 | unsigned long div,b_mask; |
||
714 | giacomo | 98 | SYS_FLAGS f; |
99 | |||
100 | f = kern_fsave(); |
||
101 | |||
538 | mauro | 102 | /* Now set up the serial link */ |
103 | b_mask = (parity & 3) * 8 + (stop & 1) * 4 + ((len - 5) & 3); |
||
104 | div = 115200L / speed; |
||
105 | /* Clear serial interrupt enable register */ |
||
106 | com_write(port,IER,0); |
||
107 | /* Empty input buffer */ |
||
108 | com_read(port,RBR); |
||
109 | /* Activate DLAB bit for speed setting */ |
||
110 | com_write(port,LCR,0x80); |
||
111 | /* Load baud divisor */ |
||
112 | com_write(port,0,div & 0x00FF); |
||
113 | div >>= 8; |
||
114 | com_write(port,1,div & 0x00FF); |
||
115 | /* Load control word (parity,stop bit,bit len) */ |
||
116 | com_write(port,LCR,b_mask); |
||
117 | /* Attiva OUT1 & OUT2 */ |
||
118 | com_write(port,MCR,0x0C); |
||
119 | |||
714 | giacomo | 120 | kern_frestore(f); |
538 | mauro | 121 | |
714 | giacomo | 122 | return(0); |
123 | |||
538 | mauro | 124 | } |
125 | |||
126 | /* Close port channel & release the server */ |
||
127 | |||
128 | int com_close(unsigned port) |
||
129 | { |
||
714 | giacomo | 130 | SYS_FLAGS f; |
538 | mauro | 131 | |
714 | giacomo | 132 | f = kern_fsave(); |
538 | mauro | 133 | |
714 | giacomo | 134 | com_write(port,IER,0); |
135 | com_read(port,IIR); |
||
136 | com_read(port,RBR); |
||
538 | mauro | 137 | |
714 | giacomo | 138 | kern_frestore(f); |
538 | mauro | 139 | |
714 | giacomo | 140 | return(0); |
538 | mauro | 141 | } |
142 |