⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pc8250.h

📁 DOS下采用中断接收数据的串口通讯的例子,很难找到的好东西!
💻 H
字号:
//
//  PC8250.H
//
//  Source code from:
//
//  Serial Communications: A C++ Developer's Guide, 2nd Edition
//  by Mark Nelson, IDG Books, 1999
//
//  Please see the book for information on usage.
//
//  This header file has all of the definitions and prototypes
//  needed to use the PC8250 class.  This file should be included
//  by any code that needs to access this class.  For an example,
//  see the PC8250 test program, TEST232.CPP.
//

#ifndef _PC8250_DOT_H
#define _PC8250_DOT_H

#include "rs232.h"
#include "queue.h"
#include "pcirq.h"
#include "_8250.h"

// A few type definitions used with this class.

enum PC8250Error {
        PC8250_UART_NOT_FOUND        = RS232_NEXT_FREE_ERROR,
        PC8250_NEXT_FREE_ERROR,
        PC8250_HANDSHAKE_LINE_IN_USE = RS232_NEXT_FREE_WARNING,
        PC8250_NEXT_FREE_WARNING };

enum UARTType { UART_8250, UART_16550, UART_UNKNOWN };

enum handshaking_bits {  dtr_dsr = 1, rts_cts = 2, xon_xoff = 4 };

class PC8250;

// The ISR data is contained in a conventional C structure instead of
// a class.  The ISR is much easier to work with as a normal C function
// instead of a member function, and as such it wants to work with
// structures instead of classes.

struct isr_data_block {
    int uart;
    UARTType uart_type;
    volatile int overflow;
    volatile int tx_running;
    volatile unsigned int rx_int_count;
    volatile unsigned int tx_int_count;
    volatile unsigned int ms_int_count;
    volatile unsigned int ls_int_count;
    volatile unsigned int line_status;
    unsigned int handshaking;
    volatile unsigned int blocking;
    volatile unsigned int blocked;
    volatile int send_handshake_char;
    volatile unsigned int modem_status;
    Queue TXQueue;
    Queue RXQueue;
};

// The Handler class is used when multiple ports share an
// interrupt, such as on a multiport board or a Microchannel bus.

class Handler {
    public :
        virtual RS232Error AddPort( RS232PortName port_name,
                                    struct isr_data_block *data ) = 0;
        virtual void DeletePort( RS232PortName port_name ) = 0;
};

class PC8250 : public RS232
{
    private :
        struct isr_data_block *isr_data;
        enum irq_name irq;
        int interrupt_number;
        int first_debug_output_line;
        int fifo_setting;
        Handler *interrupt_handler;

        void check_uart( void );
        void read_settings( void );
        RS232Error write_settings( void );
        void set_uart_address_and_irq( Handler *handler,
                                       int uart_address,
                                       irq_name irq_line );
        virtual int read_buffer( char *buffer,
                                 unsigned int count );
        virtual int write_buffer( char *buffer,
                                  unsigned int count = -1 );
        virtual int read_byte( void );
        virtual int write_byte( int c );
        void check_rx_handshaking( void );

    public :
        PC8250( enum RS232PortName port_name,
                long baud_rate = UNCHANGED,
                char parity = UNCHANGED,
                int word_length = UNCHANGED,
                int stop_bits = UNCHANGED,
                int dtr = SET,
                int rts = SET,
                int xon_xoff = DISABLE,
                int rts_cts = DISABLE,
                int dtr_dsr = DISABLE,
                Handler *handler = 0,
                int uart_address = 0,
                irq_name irq_line = ILLEGAL_IRQ );
        virtual ~PC8250( void );
        virtual RS232Error Set( long baud_rate = UNCHANGED,
                                int parity = UNCHANGED,
                                int word_length = UNCHANGED,
                                int stop_bits = UNCHANGED );
        virtual int TXSpaceFree( void );
        virtual int RXSpaceUsed( void );
        virtual int Break( long milliseconds = 300 );
        virtual int Cd( void );
        virtual int Ri( void );
        virtual int Cts( void );
        virtual int Dsr( void );
        virtual int ParityError( int clear = UNCHANGED );
        virtual int BreakDetect( int clear = UNCHANGED );
        virtual int FramingError( int clear = UNCHANGED );
        virtual int HardwareOverrunError( int clear = UNCHANGED );
        virtual int SoftwareOverrunError( int clear = UNCHANGED );
        virtual int XonXoffHandshaking( int setting = UNCHANGED );
        virtual int RtsCtsHandshaking( int setting = UNCHANGED );
        virtual int DtrDsrHandshaking( int setting = UNCHANGED );
        virtual int Dtr( int setting = UNCHANGED );
        virtual int Rts( int setting = UNCHANGED );
        virtual int PeekBuffer( void *buffer, unsigned int count );
        virtual int RXSpaceFree( void );
        virtual int TXSpaceUsed( void );
        virtual int FlushRXBuffer( void );
        virtual int FlushTXBuffer( void );
        virtual char * ErrorName( int error );
        virtual int FormatDebugOutput( char *buffer = 0,
                                       int line_number = -1 );
};

#endif // #ifndef _PC8250_DOT_H

// ************************ END OF PC8250.H ***********************


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -