2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2004-09-05 14:30:19 +04:00
|
|
|
// $Id: serial.h,v 1.20 2004-09-05 10:30:19 vruppert Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2004-01-17 18:51:09 +03:00
|
|
|
// Copyright (C) 2004 MandrakeSoft S.A.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
|
|
|
|
// Peter Grehan (grehan@iprg.nokia.com) coded most of this
|
|
|
|
// serial emulation.
|
|
|
|
|
|
|
|
#if BX_USE_SER_SMF
|
|
|
|
# define BX_SER_SMF static
|
2002-10-25 01:07:56 +04:00
|
|
|
# define BX_SER_THIS theSerialDevice->
|
2001-04-10 05:04:59 +04:00
|
|
|
#else
|
|
|
|
# define BX_SER_SMF
|
|
|
|
# define BX_SER_THIS this->
|
|
|
|
#endif
|
|
|
|
|
2004-01-18 03:18:44 +03:00
|
|
|
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(__GNU__) || defined(__APPLE__)
|
|
|
|
#define SERIAL_ENABLE
|
|
|
|
extern "C" {
|
|
|
|
#include <termios.h>
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#define BX_SERIAL_MAXDEV 4
|
|
|
|
|
|
|
|
#define BX_PC_CLOCK_XTL 1843200.0
|
|
|
|
|
|
|
|
#define BX_SER_RXIDLE 0
|
|
|
|
#define BX_SER_RXPOLL 1
|
|
|
|
#define BX_SER_RXWAIT 2
|
|
|
|
|
2004-01-17 18:51:09 +03:00
|
|
|
#define BX_SER_THR 0
|
|
|
|
#define BX_SER_RBR 0
|
|
|
|
#define BX_SER_IER 1
|
|
|
|
#define BX_SER_IIR 2
|
|
|
|
#define BX_SER_FCR 2
|
|
|
|
#define BX_SER_LCR 3
|
|
|
|
#define BX_SER_MCR 4
|
|
|
|
#define BX_SER_LSR 5
|
|
|
|
#define BX_SER_MSR 6
|
|
|
|
#define BX_SER_SCR 7
|
|
|
|
|
2004-07-28 23:36:42 +04:00
|
|
|
#define BX_SER_MODE_NULL 0
|
|
|
|
#define BX_SER_MODE_FILE 1
|
|
|
|
#define BX_SER_MODE_TERM 2
|
|
|
|
#define BX_SER_MODE_RAW 3
|
|
|
|
|
2003-10-31 20:23:56 +03:00
|
|
|
enum {
|
|
|
|
BX_SER_INT_IER,
|
|
|
|
BX_SER_INT_RXDATA,
|
|
|
|
BX_SER_INT_TXHOLD,
|
|
|
|
BX_SER_INT_RXLSTAT,
|
|
|
|
BX_SER_INT_MODSTAT,
|
2003-11-09 03:14:43 +03:00
|
|
|
BX_SER_INT_FIFO
|
2003-10-31 20:23:56 +03:00
|
|
|
};
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
typedef struct {
|
|
|
|
/*
|
|
|
|
* UART internal state
|
|
|
|
*/
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool ls_interrupt;
|
|
|
|
bx_bool ms_interrupt;
|
|
|
|
bx_bool rx_interrupt;
|
|
|
|
bx_bool tx_interrupt;
|
2003-11-09 03:14:43 +03:00
|
|
|
bx_bool fifo_interrupt;
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool ls_ipending;
|
|
|
|
bx_bool ms_ipending;
|
|
|
|
bx_bool rx_ipending;
|
2003-11-09 03:14:43 +03:00
|
|
|
bx_bool fifo_ipending;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2003-10-30 00:00:04 +03:00
|
|
|
Bit8u IRQ;
|
|
|
|
|
2003-11-09 03:14:43 +03:00
|
|
|
Bit8u rx_fifo_end;
|
|
|
|
Bit8u tx_fifo_end;
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
int baudrate;
|
|
|
|
int tx_timer_index;
|
|
|
|
|
|
|
|
int rx_pollstate;
|
|
|
|
int rx_timer_index;
|
2003-11-09 03:14:43 +03:00
|
|
|
int fifo_timer_index;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-07-28 23:36:42 +04:00
|
|
|
int io_mode;
|
2004-01-18 03:18:44 +03:00
|
|
|
int tty_id;
|
2004-07-28 23:36:42 +04:00
|
|
|
FILE *output;
|
2004-01-18 03:18:44 +03:00
|
|
|
|
2004-01-18 14:58:07 +03:00
|
|
|
#if USE_RAW_SERIAL
|
|
|
|
serial_raw* raw;
|
|
|
|
#elif defined(SERIAL_ENABLE)
|
2004-01-18 03:18:44 +03:00
|
|
|
struct termios term_orig, term_new;
|
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
/*
|
|
|
|
* Register definitions
|
|
|
|
*/
|
|
|
|
Bit8u rxbuffer; /* receiver buffer register (r/o) */
|
2003-09-15 00:16:25 +04:00
|
|
|
Bit8u thrbuffer; /* transmit holding register (w/o) */
|
2001-04-10 05:04:59 +04:00
|
|
|
/* Interrupt Enable Register */
|
|
|
|
struct {
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool rxdata_enable; /* 1=enable receive data interrupts */
|
|
|
|
bx_bool txhold_enable; /* 1=enable tx. holding reg. empty ints */
|
|
|
|
bx_bool rxlstat_enable; /* 1=enable rx line status interrupts */
|
|
|
|
bx_bool modstat_enable; /* 1=enable modem status interrupts */
|
2001-04-10 05:04:59 +04:00
|
|
|
} int_enable;
|
|
|
|
/* Interrupt Identification Register (r/o) */
|
|
|
|
struct {
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool ipending; /* 0=interrupt pending */
|
2001-04-10 05:04:59 +04:00
|
|
|
Bit8u int_ID; /* 3-bit interrupt ID */
|
|
|
|
} int_ident;
|
|
|
|
/* FIFO Control Register (w/o) */
|
|
|
|
struct {
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool enable; /* 1=enable tx and rx FIFOs */
|
2001-04-10 05:04:59 +04:00
|
|
|
Bit8u rxtrigger; /* 2-bit code for rx fifo trigger level */
|
|
|
|
} fifo_cntl;
|
|
|
|
/* Line Control Register (r/w) */
|
|
|
|
struct {
|
|
|
|
Bit8u wordlen_sel; /* 2-bit code for char length */
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool stopbits; /* select stop bit len */
|
|
|
|
bx_bool parity_enable; /* ... */
|
|
|
|
bx_bool evenparity_sel; /* ... */
|
|
|
|
bx_bool stick_parity; /* ... */
|
|
|
|
bx_bool break_cntl; /* 1=send break signal */
|
|
|
|
bx_bool dlab; /* divisor latch access bit */
|
2001-04-10 05:04:59 +04:00
|
|
|
} line_cntl;
|
|
|
|
/* MODEM Control Register (r/w) */
|
|
|
|
struct {
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool dtr; /* DTR output value */
|
|
|
|
bx_bool rts; /* RTS output value */
|
|
|
|
bx_bool out1; /* OUTPUT1 value */
|
|
|
|
bx_bool out2; /* OUTPUT2 value */
|
|
|
|
bx_bool local_loopback; /* 1=loopback mode */
|
2001-04-10 05:04:59 +04:00
|
|
|
} modem_cntl;
|
|
|
|
/* Line Status Register (r/w) */
|
|
|
|
struct {
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool rxdata_ready; /* 1=receiver data ready */
|
|
|
|
bx_bool overrun_error; /* 1=receive overrun detected */
|
|
|
|
bx_bool parity_error; /* 1=rx char has a bad parity bit */
|
|
|
|
bx_bool framing_error; /* 1=no stop bit detected for rx char */
|
|
|
|
bx_bool break_int; /* 1=break signal detected */
|
2003-09-15 00:16:25 +04:00
|
|
|
bx_bool thr_empty; /* 1=tx hold register (or fifo) is empty */
|
|
|
|
bx_bool tsr_empty; /* 1=shift reg and hold reg empty */
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool fifo_error; /* 1=at least 1 err condition in fifo */
|
2001-04-10 05:04:59 +04:00
|
|
|
} line_status;
|
|
|
|
/* Modem Status Register (r/w) */
|
|
|
|
struct {
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool delta_cts; /* 1=CTS changed since last read */
|
|
|
|
bx_bool delta_dsr; /* 1=DSR changed since last read */
|
|
|
|
bx_bool ri_trailedge; /* 1=RI moved from low->high */
|
|
|
|
bx_bool delta_dcd; /* 1=CD changed since last read */
|
|
|
|
bx_bool cts; /* CTS input value */
|
|
|
|
bx_bool dsr; /* DSR input value */
|
|
|
|
bx_bool ri; /* RI input value */
|
|
|
|
bx_bool dcd; /* DCD input value */
|
2001-04-10 05:04:59 +04:00
|
|
|
} modem_status;
|
|
|
|
|
|
|
|
Bit8u scratch; /* Scratch Register (r/w) */
|
2003-09-15 00:16:25 +04:00
|
|
|
Bit8u tsrbuffer; /* transmit shift register (internal) */
|
2003-11-09 03:14:43 +03:00
|
|
|
Bit8u rx_fifo[16]; /* receive FIFO (internal) */
|
|
|
|
Bit8u tx_fifo[16]; /* transmit FIFO (internal) */
|
2001-04-10 05:04:59 +04:00
|
|
|
Bit8u divisor_lsb; /* Divisor latch, least-sig. byte */
|
|
|
|
Bit8u divisor_msb; /* Divisor latch, most-sig. byte */
|
|
|
|
} bx_serial_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
class bx_serial_c : public bx_devmodel_c {
|
2001-04-10 05:04:59 +04:00
|
|
|
public:
|
|
|
|
bx_serial_c(void);
|
|
|
|
~bx_serial_c(void);
|
2002-10-25 01:07:56 +04:00
|
|
|
virtual void init(void);
|
|
|
|
virtual void reset(unsigned type);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
private:
|
2004-01-18 03:18:44 +03:00
|
|
|
bx_serial_t s[BX_SERIAL_MAXDEV];
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2003-10-30 00:00:04 +03:00
|
|
|
static void lower_interrupt(Bit8u port);
|
2003-10-31 20:23:56 +03:00
|
|
|
static void raise_interrupt(Bit8u port, int type);
|
2003-10-30 00:00:04 +03:00
|
|
|
|
2003-11-09 03:14:43 +03:00
|
|
|
static void rx_fifo_enq(Bit8u port, Bit8u data);
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
static void tx_timer_handler(void *);
|
|
|
|
BX_SER_SMF void tx_timer(void);
|
|
|
|
|
|
|
|
static void rx_timer_handler(void *);
|
|
|
|
BX_SER_SMF void rx_timer(void);
|
|
|
|
|
2003-11-09 03:14:43 +03:00
|
|
|
static void fifo_timer_handler(void *);
|
|
|
|
BX_SER_SMF void fifo_timer(void);
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);
|
|
|
|
static void write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);
|
|
|
|
#if !BX_USE_SER_SMF
|
|
|
|
Bit32u read(Bit32u address, unsigned io_len);
|
|
|
|
void write(Bit32u address, Bit32u value, unsigned io_len);
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|