]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/lib/uart/uart_leon3.cc
9b30ed9a8a0bed4691722800a84705bded2e33cc
[l4.git] / kernel / fiasco / src / lib / uart / uart_leon3.cc
1 #include "uart_leon3.h"
2
3 namespace L4
4 {
5   enum {
6     DATA_REG   = 0x00,
7     STATUS_REG = 0x04,
8     CTRL_REG   = 0x08,
9     SCALER_REG = 0x0C,
10
11     DATA_MASK  = 0x0F,
12
13     STATUS_DR  = 0x001, // data ready
14     STATUS_TS  = 0x002, // transmit shift empty
15     STATUS_TE  = 0x004, // transmit fifo empty
16     STATUS_BR  = 0x008, // BREAK received
17     STATUS_OV  = 0x010, // overrun
18     STATUS_PE  = 0x020, // parity error
19     STATUS_FE  = 0x040, // framing error
20     STATUS_TH  = 0x080, // transmit fifo half-full
21     STATUS_RH  = 0x100, // recv fifo half-full
22     STATUS_TF  = 0x200, // transmit fifo full
23     STATUS_RF  = 0x400, // recv fifo full
24
25     STATUS_TCNT_MASK  = 0x3F,
26     STATUS_TCNT_SHIFT = 20,
27     STATUS_RCNT_MASK  = 0x3F,
28     STATUS_RCNT_SHIFT = 26,
29
30     CTRL_RE    = 0x001,
31     CTRL_TE    = 0x002,
32     CTRL_RI    = 0x004,
33     CTRL_TI    = 0x008,
34     CTRL_PS    = 0x010,
35     CTRL_PE    = 0x020,
36     CTRL_FL    = 0x040,
37     CTRL_LB    = 0x080,
38     CTRL_EC    = 0x100,
39     CTRL_TF    = 0x200,
40     CTRL_RF    = 0x400,
41
42     SCALER_MASK = 0xFFF,
43   };
44
45
46   bool Uart_leon3::startup(Io_register_block const *regs)
47   {
48     _regs = regs;
49
50     return true;
51   }
52
53   void Uart_leon3::shutdown()
54   { }
55
56   bool Uart_leon3::change_mode(Transfer_mode, Baud_rate r)
57   {
58     if (r != 115200)
59       return false;
60
61     return true;
62   }
63
64   int Uart_leon3::get_char(bool blocking) const
65   {
66     while (!char_avail())
67       if (!blocking)
68         return -1;
69
70     return _regs->read<unsigned int>(DATA_REG) & DATA_MASK;
71   }
72
73   int Uart_leon3::char_avail() const
74   {
75     return 0;
76   }
77
78   void Uart_leon3::out_char(char c) const
79   {
80     while (_regs->read<unsigned int>(STATUS_REG) & STATUS_TF)
81       ;
82     _regs->write<unsigned int>(DATA_REG, c);
83   }
84
85   int Uart_leon3::write(char const *s, unsigned long count) const
86   {
87     unsigned long c = count;
88     while (c--)
89       out_char(*s++);
90
91     return count;
92   }
93 };