1 /////////////////////////////////////////////////////////////////////////
2 // $Id: serial.h,v 1.34 2008/05/22 08:13:22 vruppert Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2004 MandrakeSoft S.A.
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef BX_IODEV_SERIAL_H
29 #define BX_IODEV_SERIAL_H
31 // Peter Grehan (grehan@iprg.nokia.com) coded most of this
35 # define BX_SER_SMF static
36 # define BX_SER_THIS theSerialDevice->
39 # define BX_SER_THIS this->
46 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) || defined(__APPLE__) || defined(__sun__)
53 #define BX_SERIAL_MAXDEV 4
55 #define BX_PC_CLOCK_XTL 1843200.0
57 #define BX_SER_RXIDLE 0
58 #define BX_SER_RXPOLL 1
59 #define BX_SER_RXWAIT 2
72 #define BX_SER_MODE_NULL 0
73 #define BX_SER_MODE_FILE 1
74 #define BX_SER_MODE_TERM 2
75 #define BX_SER_MODE_RAW 3
76 #define BX_SER_MODE_MOUSE 4
77 #define BX_SER_MODE_SOCKET 5
78 #define BX_SER_MODE_PIPE 6
100 bx_bool tx_interrupt
;
101 bx_bool fifo_interrupt
;
105 bx_bool fifo_ipending
;
117 int fifo_timer_index
;
130 #if defined(SERIAL_ENABLE) && !defined(WIN32)
131 struct termios term_orig
, term_new
;
135 * Register definitions
137 Bit8u rxbuffer
; /* receiver buffer register (r/o) */
138 Bit8u thrbuffer
; /* transmit holding register (w/o) */
139 /* Interrupt Enable Register */
141 bx_bool rxdata_enable
; /* 1=enable receive data interrupts */
142 bx_bool txhold_enable
; /* 1=enable tx. holding reg. empty ints */
143 bx_bool rxlstat_enable
; /* 1=enable rx line status interrupts */
144 bx_bool modstat_enable
; /* 1=enable modem status interrupts */
146 /* Interrupt Identification Register (r/o) */
148 bx_bool ipending
; /* 0=interrupt pending */
149 Bit8u int_ID
; /* 3-bit interrupt ID */
151 /* FIFO Control Register (w/o) */
153 bx_bool enable
; /* 1=enable tx and rx FIFOs */
154 Bit8u rxtrigger
; /* 2-bit code for rx fifo trigger level */
156 /* Line Control Register (r/w) */
158 Bit8u wordlen_sel
; /* 2-bit code for char length */
159 bx_bool stopbits
; /* select stop bit len */
160 bx_bool parity_enable
; /* ... */
161 bx_bool evenparity_sel
; /* ... */
162 bx_bool stick_parity
; /* ... */
163 bx_bool break_cntl
; /* 1=send break signal */
164 bx_bool dlab
; /* divisor latch access bit */
166 /* MODEM Control Register (r/w) */
168 bx_bool dtr
; /* DTR output value */
169 bx_bool rts
; /* RTS output value */
170 bx_bool out1
; /* OUTPUT1 value */
171 bx_bool out2
; /* OUTPUT2 value */
172 bx_bool local_loopback
; /* 1=loopback mode */
174 /* Line Status Register (r/w) */
176 bx_bool rxdata_ready
; /* 1=receiver data ready */
177 bx_bool overrun_error
; /* 1=receive overrun detected */
178 bx_bool parity_error
; /* 1=rx char has a bad parity bit */
179 bx_bool framing_error
; /* 1=no stop bit detected for rx char */
180 bx_bool break_int
; /* 1=break signal detected */
181 bx_bool thr_empty
; /* 1=tx hold register (or fifo) is empty */
182 bx_bool tsr_empty
; /* 1=shift reg and hold reg empty */
183 bx_bool fifo_error
; /* 1=at least 1 err condition in fifo */
185 /* Modem Status Register (r/w) */
187 bx_bool delta_cts
; /* 1=CTS changed since last read */
188 bx_bool delta_dsr
; /* 1=DSR changed since last read */
189 bx_bool ri_trailedge
; /* 1=RI moved from low->high */
190 bx_bool delta_dcd
; /* 1=CD changed since last read */
191 bx_bool cts
; /* CTS input value */
192 bx_bool dsr
; /* DSR input value */
193 bx_bool ri
; /* RI input value */
194 bx_bool dcd
; /* DCD input value */
197 Bit8u scratch
; /* Scratch Register (r/w) */
198 Bit8u tsrbuffer
; /* transmit shift register (internal) */
199 Bit8u rx_fifo
[16]; /* receive FIFO (internal) */
200 Bit8u tx_fifo
[16]; /* transmit FIFO (internal) */
201 Bit8u divisor_lsb
; /* Divisor latch, least-sig. byte */
202 Bit8u divisor_msb
; /* Divisor latch, most-sig. byte */
207 class bx_serial_c
: public bx_serial_stub_c
{
210 virtual ~bx_serial_c();
211 virtual void init(void);
212 virtual void reset(unsigned type
);
213 virtual void serial_mouse_enq(int delta_x
, int delta_y
, int delta_z
, unsigned button_state
);
214 virtual void register_state(void);
217 bx_serial_t s
[BX_SERIAL_MAXDEV
];
222 int mouse_delayed_dx
;
223 int mouse_delayed_dy
;
224 int mouse_delayed_dz
;
227 Bit8u buffer
[BX_MOUSE_BUFF_SIZE
];
229 } mouse_internal_buffer
;
231 static void lower_interrupt(Bit8u port
);
232 static void raise_interrupt(Bit8u port
, int type
);
234 static void rx_fifo_enq(Bit8u port
, Bit8u data
);
236 static void tx_timer_handler(void *);
237 BX_SER_SMF
void tx_timer(void);
239 static void rx_timer_handler(void *);
240 BX_SER_SMF
void rx_timer(void);
242 static void fifo_timer_handler(void *);
243 BX_SER_SMF
void fifo_timer(void);
245 static Bit32u
read_handler(void *this_ptr
, Bit32u address
, unsigned io_len
);
246 static void write_handler(void *this_ptr
, Bit32u address
, Bit32u value
, unsigned io_len
);
248 Bit32u
read(Bit32u address
, unsigned io_len
);
249 void write(Bit32u address
, Bit32u value
, unsigned io_len
);