Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

uart.h

Go to the documentation of this file.
00001 // AUTOMATICALLY GENERATED -- DO NOT EDIT!         -*- c++ -*-
00002 
00003 #ifndef uart_h
00004 #define uart_h
00005 
00006 #include "console.h"
00007 
00008 #include "types.h"
00009 
00010 //
00011 // INTERFACE definition follows 
00012 //
00013 
00014 
00018 class Uart 
00019   : public Console
00020 {
00021 public:
00025   typedef unsigned TransferMode;
00026 
00030   typedef unsigned BaudRate;
00031 
00032   /* These constants must be defined in the 
00033      arch part of the uart. To define them there
00034      has the advantage of most efficent definition
00035      for the hardware.
00036 
00037   static unsigned const PAR_NONE = xxx;
00038   static unsigned const PAR_EVEN = xxx;
00039   static unsigned const PAR_ODD  = xxx;
00040   static unsigned const DAT_5    = xxx;
00041   static unsigned const DAT_6    = xxx;
00042   static unsigned const DAT_7    = xxx;
00043   static unsigned const DAT_8    = xxx;
00044   static unsigned const STOP_1   = xxx;
00045   static unsigned const STOP_2   = xxx;
00046 
00047   static unsigned const MODE_8N1 = PAR_NONE | DAT_8 | STOP_1;
00048   static unsigned const MODE_7E1 = PAR_EVEN | DAT_7 | STOP_1;
00049 
00050   // these two values are to leave either mode
00051   // or baud rate unchanged on a call to change_mode
00052   static unsigned const MODE_NC  = xxx;
00053   static unsigned const BAUD_NC  = xxx;
00054 
00055   */
00056 
00057 public:
00058   /* Interface definition - implemented in the arch part */
00060   Uart();
00061 
00063   ~Uart();
00064 
00068   void shutdown();
00069 
00073   int const irq() const;
00074 
00078   void enable_rcv_irq();
00079 
00083   void disable_rcv_irq();
00084 
00090   bool change_mode(TransferMode m, BaudRate r);
00091 
00095   TransferMode get_mode();
00096 
00100   int write( char const *str, size_t len );
00101 
00105   int getchar( bool blocking = true );
00106 
00110   int char_avail() const;
00111 
00112   Mword get_attributes() const;
00113 private:
00114 
00115 public:
00116   enum {
00117     Base_rate     = 115200,
00118     Base_ier_bits = 0,
00119   };
00120 private:
00121 
00122 public:
00123 
00129   bool startup(Address port, int irq);
00130 
00131   enum {
00132     PAR_NONE = 0x00,
00133     PAR_EVEN = 0x18,
00134     PAR_ODD  = 0x08,
00135     DAT_5    = 0x00,
00136     DAT_6    = 0x01,
00137     DAT_7    = 0x02,
00138     DAT_8    = 0x03,
00139     STOP_1   = 0x00,
00140     STOP_2   = 0x04,
00141 
00142     MODE_8N1 = PAR_NONE | DAT_8 | STOP_1,
00143     MODE_7E1 = PAR_EVEN | DAT_7 | STOP_1,
00144 
00145   // these two values are to leave either mode
00146   // or baud rate unchanged on a call to change_mode
00147     MODE_NC  = 0x1000000,
00148     BAUD_NC  = 0x1000000,
00149 
00150   };
00151 
00152 private:
00153 
00154   enum Registers {
00155     TRB      = 0, // Transmit/Receive Buffer  (read/write)
00156     BRD_LOW  = 0, // Baud Rate Divisor LSB if bit 7 of LCR is set  (read/write)
00157     IER      = 1, // Interrupt Enable Register  (read/write)
00158     BRD_HIGH = 1, // Baud Rate Divisor MSB if bit 7 of LCR is set  (read/write)
00159     IIR      = 2, // Interrupt Identification Register  (read only)
00160     FCR      = 2, // 16550 FIFO Control Register  (write only)
00161     LCR      = 3, // Line Control Register  (read/write)
00162     MCR      = 4, // Modem Control Register  (read/write)
00163     LSR      = 5, // Line Status Register  (read only)
00164     MSR      = 6, // Modem Status Register  (read only)
00165     SPR      = 7, // Scratch Pad Register  (read/write)
00166   };
00167 
00168   Address port;
00169   int _irq;
00170 
00171 
00172 private:  
00173   inline void outb( Unsigned8 b, Registers reg );
00174   
00175   inline Unsigned8 inb( Registers reg ) const;
00176   
00177   inline void mcr( Unsigned8 b );
00178   
00179   inline Unsigned8 mcr() const;
00180   
00181   inline void fcr( Unsigned8 b );
00182   
00183   inline void lcr( Unsigned8 b );
00184   
00185   inline Unsigned8 lcr() const;
00186   
00187   inline void ier( Unsigned8 b );
00188   
00189   inline Unsigned8 ier() const;
00190   
00191   inline Unsigned8 iir() const;
00192   
00193   inline Unsigned8 msr() const;
00194   
00195   inline Unsigned8 lsr() const;
00196   
00197   inline void trb( Unsigned8 b );
00198   
00199   inline Unsigned8 trb() const;
00200   
00201   bool valid();
00202 };
00203 
00204 //
00205 // IMPLEMENTATION includes follow (for use by inline functions)
00206 //
00207 
00208 
00209 #include "io.h"
00210 
00211 //
00212 // IMPLEMENTATION of inline functions (and needed classes)
00213 //
00214 
00215 
00216 
00217 
00218 inline void Uart::outb( Unsigned8 b, Registers reg )
00219 {
00220   Io::out8(b,port+reg);
00221 }
00222 
00223 
00224 
00225 inline Unsigned8 Uart::inb( Registers reg ) const
00226 {
00227   return Io::in8(port+reg);
00228 }
00229 
00230 
00231 
00232 inline void Uart::ier( Unsigned8 b )
00233 {
00234   outb(b, IER);
00235 }
00236 
00237 
00238 
00239 inline Unsigned8 Uart::ier() const
00240 {
00241   return inb(IER);
00242 }
00243 
00244 
00245 
00246 inline int const Uart::irq() const
00247 {
00248   return _irq;
00249 }
00250 
00251 
00252 
00253 inline void Uart::disable_rcv_irq()
00254 {
00255   ier(ier() & ~1);
00256 }
00257 
00258 
00259 
00260 inline void Uart::enable_rcv_irq()
00261 {
00262   ier(ier() | 1);
00263 }
00264 
00265 #endif // uart_h

Generated on Mon Sep 26 14:20:12 2005 for Fiasco by  doxygen 1.4.2