]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/drivers/uart.cpp
update
[l4.git] / kernel / fiasco / src / drivers / uart.cpp
1 INTERFACE:
2
3 #include "console.h"
4
5 /**
6  * Platform independent UART stub.
7  */
8 class Uart : public Console
9 {
10 public:
11   /**
12    * Type UART transfer mode (Bits, Stopbits etc.).
13    */
14   typedef unsigned TransferMode;
15
16   /**
17    * Type for baud rate.
18    */
19   typedef unsigned BaudRate;
20
21   /* These constants must be defined in the 
22      arch part of the uart. To define them there
23      has the advantage of most efficent definition
24      for the hardware.
25
26   static unsigned const PAR_NONE = xxx;
27   static unsigned const PAR_EVEN = xxx;
28   static unsigned const PAR_ODD  = xxx;
29   static unsigned const DAT_5    = xxx;
30   static unsigned const DAT_6    = xxx;
31   static unsigned const DAT_7    = xxx;
32   static unsigned const DAT_8    = xxx;
33   static unsigned const STOP_1   = xxx;
34   static unsigned const STOP_2   = xxx;
35
36   static unsigned const MODE_8N1 = PAR_NONE | DAT_8 | STOP_1;
37   static unsigned const MODE_7E1 = PAR_EVEN | DAT_7 | STOP_1;
38
39   // these two values are to leave either mode
40   // or baud rate unchanged on a call to change_mode
41   static unsigned const MODE_NC  = xxx;
42   static unsigned const BAUD_NC  = xxx;
43
44   */
45
46
47 public:
48   /* Interface definition - implemented in the arch part */
49   /// ctor
50   Uart();
51
52   /// dtor
53   ~Uart();
54
55   /**
56    * (abstract) Shutdown the serial port.
57    */
58   void shutdown();
59
60   /**
61    * (abstract) Get the IRQ assigned to the port.
62    */
63   int irq() const;
64
65   /**
66    * (abstract) Enable rcv IRQ in UART.
67    */
68   void enable_rcv_irq();
69
70   /**
71    * (abstract) Disable rcv IRQ in UART.
72    */
73   void disable_rcv_irq();
74   
75   /**
76    * (abstract) Change transfer mode or speed.
77    * @param m the new mode for the transfer, or MODE_NC for no mode change.
78    * @param r the new baud rate, or BAUD_NC, for no speed change.
79    */
80   bool change_mode(TransferMode m, BaudRate r);
81
82   /**
83    * (abstract) Get the current transfer mode.
84    */
85   TransferMode get_mode();
86
87   /**
88    * (abstract) Write str.
89    */
90   int write( char const *str, size_t len );
91
92   /**
93    * (abstract) Read a character.
94    */
95   int getchar( bool blocking = true );
96
97   /**
98    * (abstract) Is there anything to read?
99    */
100   int char_avail() const;
101   
102   Mword get_attributes() const;
103 };
104
105 IMPLEMENTATION:
106
107 IMPLEMENT
108 Mword
109 Uart::get_attributes() const
110 {
111   return UART | IN | OUT;
112 }
113
114 //---------------------------------------------------------------------------
115 INTERFACE [libuart]:
116
117 #include "uart_base.h"
118
119 EXTENSION class Uart
120 {
121 public:
122   enum 
123   {
124     MODE_8N1 = 1,
125   };
126 protected:
127   static L4::Uart *uart();
128 };
129
130
131 //---------------------------------------------------------------------------
132 IMPLEMENTATION [libuart]:
133
134 IMPLEMENT Uart::Uart()
135 {
136 }
137
138 IMPLEMENT Uart::~Uart()
139 {
140 }
141
142
143 PUBLIC bool Uart::startup( Address _address, unsigned /*irq*/ ) 
144 {
145   return uart()->startup(_address);
146 }
147
148 IMPLEMENT inline void Uart::shutdown()
149 {
150   uart()->shutdown();
151 }
152
153
154 IMPLEMENT inline bool Uart::change_mode(TransferMode m, BaudRate baud)
155 {
156   return uart()->change_mode(m, baud);
157 }
158
159 IMPLEMENT inline
160 int Uart::write( const char *s, __SIZE_TYPE__ count )
161 {
162   return uart()->write(s, count);
163 }
164
165 IMPLEMENT inline
166 int Uart::getchar( bool blocking )
167 {
168   return uart()->get_char(blocking);
169 }
170
171
172 IMPLEMENT inline
173 int Uart::char_avail() const
174 {
175   return uart()->char_avail();
176 }
177
178
179 IMPLEMENT inline
180 int Uart::irq() const
181 {
182   return uart()->rx_irq();
183 }
184
185 IMPLEMENT 
186 void Uart::enable_rcv_irq()
187 {
188   uart()->enable_rx_irq(true);
189 }
190
191 IMPLEMENT
192 void Uart::disable_rcv_irq()
193 {
194   uart()->enable_rx_irq(false);
195 }
196
197