Subversion Repositories shark

Rev

Rev 714 | Rev 1035 | 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
 
715 giacomo 65
unsigned com_read(unsigned port, unsigned reg)
538 mauro 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
 
715 giacomo 73
void com_write(unsigned port, unsigned reg, unsigned value)
538 mauro 74
{
75
    if (port > 3 || reg > 7) return;
76
    ll_out(com_base[port]+reg,value);
77
}
78
 
79
/* Polled send/receive */
80
 
715 giacomo 81
unsigned com_send(unsigned port, BYTE b)
538 mauro 82
{
83
    while ((com_read(port,LSR) & 32) == 0);
84
    com_write(port,THR,b);
715 giacomo 85
    return 0;
538 mauro 86
}
87
 
88
unsigned com_receive(unsigned port)
89
{
90
    while ((com_read(port,LSR) & 1) == 0);
91
    return(com_read(port,RBR));
92
}
93
 
94
/* Initialize a serial channel */
95
 
96
int com_open(unsigned port,DWORD speed,BYTE parity,BYTE len,BYTE stop)
97
{
98
    unsigned long div,b_mask;
714 giacomo 99
    SYS_FLAGS f;        
100
 
101
    f = kern_fsave();
102
 
538 mauro 103
    /* Now set up the serial link */
104
    b_mask = (parity & 3) * 8 + (stop & 1) * 4 + ((len - 5) & 3);
105
    div = 115200L / speed;
106
    /* Clear serial interrupt enable register */
107
    com_write(port,IER,0);
108
    /* Empty input buffer */
109
    com_read(port,RBR);
110
    /* Activate DLAB bit for speed setting */
111
    com_write(port,LCR,0x80);
112
    /* Load baud divisor */
113
    com_write(port,0,div & 0x00FF);
114
    div >>= 8;
115
    com_write(port,1,div & 0x00FF);
116
    /* Load control word (parity,stop bit,bit len) */
117
    com_write(port,LCR,b_mask);
118
    /* Attiva OUT1 & OUT2 */
119
    com_write(port,MCR,0x0C);
120
 
714 giacomo 121
    kern_frestore(f);
538 mauro 122
 
714 giacomo 123
    return(0);
124
 
538 mauro 125
}
126
 
127
/* Close port channel & release the server */
128
 
129
int com_close(unsigned port)
130
{    
714 giacomo 131
    SYS_FLAGS f;
538 mauro 132
 
714 giacomo 133
    f = kern_fsave();
538 mauro 134
 
714 giacomo 135
    com_write(port,IER,0);
136
    com_read(port,IIR);
137
    com_read(port,RBR);
538 mauro 138
 
714 giacomo 139
    kern_frestore(f);
538 mauro 140
 
714 giacomo 141
    return(0);
538 mauro 142
}
143