6 * Platform independent UART stub.
8 class Uart : public Console
12 * Type UART transfer mode (Bits, Stopbits etc.).
14 typedef unsigned TransferMode;
19 typedef unsigned BaudRate;
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
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;
36 static unsigned const MODE_8N1 = PAR_NONE | DAT_8 | STOP_1;
37 static unsigned const MODE_7E1 = PAR_EVEN | DAT_7 | STOP_1;
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;
48 /* Interface definition - implemented in the arch part */
56 * (abstract) Shutdown the serial port.
61 * (abstract) Get the IRQ assigned to the port.
66 * (abstract) Enable rcv IRQ in UART.
68 void enable_rcv_irq();
71 * (abstract) Disable rcv IRQ in UART.
73 void disable_rcv_irq();
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.
80 bool change_mode(TransferMode m, BaudRate r);
83 * (abstract) Get the current transfer mode.
85 TransferMode get_mode();
88 * (abstract) Write str.
90 int write( char const *str, size_t len );
93 * (abstract) Read a character.
95 int getchar( bool blocking = true );
98 * (abstract) Is there anything to read?
100 int char_avail() const;
102 Mword get_attributes() const;
109 Uart::get_attributes() const
111 return UART | IN | OUT;
114 //---------------------------------------------------------------------------
117 #include "uart_base.h"
127 static L4::Uart *uart();
131 //---------------------------------------------------------------------------
132 IMPLEMENTATION [libuart]:
134 IMPLEMENT Uart::Uart()
138 IMPLEMENT Uart::~Uart()
143 PUBLIC bool Uart::startup( Address _address, unsigned /*irq*/ )
145 return uart()->startup(_address);
148 IMPLEMENT inline void Uart::shutdown()
154 IMPLEMENT inline bool Uart::change_mode(TransferMode m, BaudRate baud)
156 return uart()->change_mode(m, baud);
160 int Uart::write( const char *s, __SIZE_TYPE__ count )
162 return uart()->write(s, count);
166 int Uart::getchar( bool blocking )
168 return uart()->get_char(blocking);
173 int Uart::char_avail() const
175 return uart()->char_avail();
180 int Uart::irq() const
182 return uart()->rx_irq();
186 void Uart::enable_rcv_irq()
188 uart()->enable_rx_irq(true);
192 void Uart::disable_rcv_irq()
194 uart()->enable_rx_irq(false);