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