home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / ISC366.ZIP / SERIAL / EXAMPLES / SERIAL.H < prev    next >
Text File  |  1993-09-01  |  6KB  |  151 lines

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