home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / ISC365 / SERIAL.H < prev    next >
C/C++ Source or Header  |  1993-07-08  |  5KB  |  144 lines

  1. ///////////////////////////////////////////////////////////////////////////
  2. //                                                                       //
  3. //            File: serial.h                                             //
  4. //                  (project version).                                   //
  5. //            started on: 5/2/92                                         //
  6. //                                                                       //
  7. ///////////////////////////////////////////////////////////////////////////
  8. //                                                                       //
  9. //                                                                       //                                                                     //
  10. ///////////////////////////////////////////////////////////////////////////
  11.  
  12. #ifndef __SERIAL_H
  13. #define __SERIAL_H
  14.  
  15. #include "public.h" // definitions.
  16. #include "buff.h"     // BUFF
  17. #include "isc.h"      // ISC
  18.  
  19. class SERIAL_PORT : public ISC {
  20.  
  21. protected:
  22.           // base baud rate (devide this with requested baud rate and send to UART).
  23.           static const unsigned long BAUD_CONST;
  24.  
  25.           // data about ports and interrupts
  26.           //
  27.           enum PORT {DATA=0, IER, BAUDLOW= 0,BAUDHIGH, IID,
  28.                      LCR, MCR, LSR, MSR}; // port structure...
  29.           enum INT_ID {NO_INT_ACTIVE= 1, MODEM_STATUS_INT= 0,
  30.                        TX_INT= 2, RX_INT= 4, LINE_STATUS_INT= 6};
  31.           enum PIC_PORT {PIC_DATA= 0, PIC_IMR};
  32.  
  33.           // do_send private vars.
  34.           // will be initialized in activate()...
  35.           unsigned do_send_recursive_count;
  36.           BOOLEAN do_send_recursive_flag;
  37.  
  38.           // com parameters.
  39.           //
  40.           unsigned com_port;
  41.           unsigned com_int;
  42.           unsigned com_pic_port;
  43.           unsigned char com_imr_mask;
  44.  
  45.           BUFF in_buff, out_buff; // buffers.
  46.  
  47.           // if true  :- may send out.
  48.           // if false :- flow inhibited.
  49.  
  50.           BOOLEAN flow_enabled;
  51.  
  52.           BOOLEAN InitFlag;
  53.  
  54.           // sets up imr.
  55.           //
  56.           inline void set_imr(void);
  57.  
  58.           // sends eoi to the pic.
  59.           //
  60.           inline void eoi(void);
  61.  
  62.           // communication interrupt.
  63.           //
  64.           virtual void isr(void);
  65.  
  66.           // function that sets flow_enabled.
  67.           //
  68.           virtual inline void flow_check();
  69.           virtual inline BOOLEAN flow_set(BYTE in_byte) { return FALSE;};
  70.  
  71.           // send top byte out.
  72.           // - overload this function for enabling/disabling of stream io
  73.           //            if (not enabled- do not call hook back, if it is
  74.           //            call back - be sure to have an interrupt or something
  75.           //            that calls this function when sending might be
  76.           //            allowed.
  77.           //
  78.           virtual void do_send(void);
  79.  
  80.           // msr_int - is called when something in the modem status has changed
  81.           //         after this function is called- the isr attempts to send
  82.           //         data through.
  83.           // - overload this function to do more specific things in case a
  84.           //   specific modem control changes (Ring, DCD, DSR, CTS).
  85.           //
  86.           virtual void msr_int(const BYTE /* msr */) {};
  87.  
  88.           // function that extends the port initialization.
  89.           //      called when serial port initializes, for CLASS dependent
  90.           //      init.
  91.           //
  92.           virtual void extended_init() {};
  93.  
  94.           // this function gets called when a BREAK has been received.
  95.           //
  96.           virtual void com_break() {};
  97.  
  98.           // this function gets called when a framing error, parity error,
  99.           // of overrun error has been received.
  100.           virtual void com_error();
  101.  
  102.  
  103.  
  104. public:
  105.        // constructor which does nothing.
  106.        SERIAL_PORT();
  107.  
  108.        // constructor for non-standard com port.
  109.        //
  110.        SERIAL_PORT (const unsigned port_num, const unsigned irq_line_num,
  111.                    const unsigned int_num, const unsigned pic_port_num);
  112.  
  113.        // setup constructor.
  114.        void activate(const unsigned port_num, const unsigned irq_line_num,
  115.             const unsigned int_num, const unsigned pic_port_num);
  116.  
  117.        // constructor for com1-com4
  118.        //
  119.        SERIAL_PORT (const unsigned com_num);
  120.  
  121.        // setup constructor.
  122.        //
  123.        void activate(const unsigned com_num);
  124.  
  125.        ~SERIAL_PORT();
  126.  
  127.        // access out.
  128.  
  129.        virtual OPERATION operator >> (BYTE& in_byte);
  130.        virtual OPERATION operator << (const BYTE out_byte);
  131.        virtual OPERATION operator >  (BYTE& peek_byte);
  132.        inline unsigned output_buff_len(void);
  133.        inline unsigned input_buff_len(void);
  134.        inline void empty_io_buffers(void);
  135.        inline void set_controls(BYTE mcr);
  136.  
  137.        void set_up_port(const long baud_rate,const BYTE word_len,
  138.                         const BYTE parity, const BYTE stop_bits);
  139.  
  140.  
  141. };
  142.  
  143. #endif /* __SERIAL_H */
  144.