]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/lib/uart/uart_16550.h
Update
[l4.git] / kernel / fiasco / src / lib / uart / uart_16550.h
1 /*
2  * (c) 2008-2012 Adam Lackorznynski <adam@os.inf.tu-dresden.de>
3  *               Alexander Warg <alexander.warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #pragma once
11
12 #include "uart_base.h"
13
14 namespace L4
15 {
16   class Uart_16550 : public Uart
17   {
18   protected:
19     enum Registers
20     {
21       TRB      = 0x00, // Transmit/Receive Buffer  (read/write)
22       BRD_LOW  = 0x00, // Baud Rate Divisor LSB if bit 7 of LCR is set  (read/write)
23       IER      = 0x01, // Interrupt Enable Register  (read/write)
24       BRD_HIGH = 0x01, // Baud Rate Divisor MSB if bit 7 of LCR is set  (read/write)
25       IIR      = 0x02, // Interrupt Identification Register  (read only)
26       FCR      = 0x02, // 16550 FIFO Control Register  (write only)
27       LCR      = 0x03, // Line Control Register  (read/write)
28       MCR      = 0x04, // Modem Control Register  (read/write)
29       LSR      = 0x05, // Line Status Register  (read only)
30       MSR      = 0x06, // Modem Status Register  (read only)
31       SPR      = 0x07, // Scratch Pad Register  (read/write)
32     };
33
34     enum Register_value
35     {
36       IIR_BUSY = 7,
37     };
38
39   public:
40     enum
41       {
42         PAR_NONE = 0x00,
43         PAR_EVEN = 0x18,
44         PAR_ODD  = 0x08,
45         DAT_5    = 0x00,
46         DAT_6    = 0x01,
47         DAT_7    = 0x02,
48         DAT_8    = 0x03,
49         STOP_1   = 0x00,
50         STOP_2   = 0x04,
51
52         MODE_8N1 = PAR_NONE | DAT_8 | STOP_1,
53         MODE_7E1 = PAR_EVEN | DAT_7 | STOP_1,
54
55         // these two values are to leave either mode
56         // or baud rate unchanged on a call to change_mode
57         MODE_NC  = 0x1000000,
58         BAUD_NC  = 0x1000000,
59
60         Base_rate_x86 = 115200,
61         Base_rate_pxa = 921600,
62       };
63
64     enum Init_flags
65     {
66       F_skip_init = 1,
67     };
68
69     explicit Uart_16550(unsigned long base_rate, unsigned char init_flags = 0,
70                         unsigned char ier_bits = 0,
71                         unsigned char mcr_bits = 0, unsigned char fcr_bits = 0)
72     : _base_rate(base_rate), _init_flags(init_flags), _mcr_bits(mcr_bits),
73       _ier_bits(ier_bits), _fcr_bits(fcr_bits)
74     {}
75
76     bool startup(Io_register_block const *regs);
77     void shutdown();
78     bool change_mode(Transfer_mode m, Baud_rate r);
79     int get_char(bool blocking = true) const;
80     int char_avail() const;
81     inline void out_char(char c) const;
82     int write(char const *s, unsigned long count) const;
83     bool enable_rx_irq(bool enable = true);
84
85   private:
86     unsigned long _base_rate;
87     unsigned char _init_flags;
88     unsigned char _mcr_bits;
89     unsigned char _ier_bits;
90     unsigned char _fcr_bits;
91   };
92 }