]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/drivers-frst/uart/src/uart_omap35x.cc
Update
[l4.git] / l4 / pkg / drivers-frst / uart / src / uart_omap35x.cc
1 /*
2  * (c) 2009-2012 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  */
9 #include "uart_omap35x.h"
10 #include "poll_timeout_counter.h"
11
12 namespace L4
13 {
14   enum {
15     DLL_REG  = 0x00,
16     RHR_REG  = 0x00,
17     THR_REG  = 0x00,
18     IER_REG  = 0x04,
19     DLH_REG  = 0x04,
20     LCD_REG  = 0x08,
21     LSR_REG  = 0x14,
22     SSR_REG  = 0x44,
23     SYSC_REG = 0x54,
24     SYSS_REG = 0x58,
25
26     LCD_REG_CHAR_LENGTH_5BIT       = 0 << 0,
27     LCD_REG_CHAR_LENGTH_6BIT       = 1 << 0,
28     LCD_REG_CHAR_LENGTH_7BIT       = 2 << 0,
29     LCD_REG_CHAR_LENGTH_8BIT       = 3 << 0,
30     LCD_REG_CHAR_NB_STOP_2         = 1 << 2,
31     LCD_REG_CHAR_PARITY_EN         = 1 << 3,
32     LCD_REG_CHAR_PARITY_TYPE1_EVEN = 1 << 4,
33
34     LSR_REG_RX_FIFO_E_AVAIL        = 1 << 0,
35     LSR_REG_TX_FIFO_E_EMPTY        = 1 << 5,
36
37     SSR_REG_TX_FIFO_FULL           = 1 << 0,
38
39     SYSC_REG_SOFTRESET             = 1 << 1,
40
41     SYSC_REG_RESETDONE             = 1 << 0,
42   };
43
44
45   bool Uart_omap35x::startup(Io_register_block const *regs)
46   {
47     _regs = regs;
48
49     // Reset UART
50     //_regs->write<unsigned int>(SYSC_REG, _regs->read<unsigned int>(SYSC_REG) | SYSC_REG_SOFTRESET);
51     // Poll_timeout_counter i(3000000);
52     //while (i.test(!(_regs->read<unsigned int>(SYSS_REG) & SYSC_REG_RESETDONE)))
53     //  ;
54
55     return true;
56   }
57
58   void Uart_omap35x::shutdown()
59   {
60   }
61
62   bool Uart_omap35x::enable_rx_irq(bool enable)
63   {
64     _regs->write<unsigned int>(IER_REG, enable ? 1 : 0);
65     return true;
66   }
67   bool Uart_omap35x::change_mode(Transfer_mode, Baud_rate r)
68   {
69     if (r != 115200)
70       return false;
71
72     return true;
73   }
74
75   int Uart_omap35x::get_char(bool blocking) const
76   {
77     while (!char_avail())
78       if (!blocking)
79         return -1;
80
81     return _regs->read<unsigned int>(RHR_REG);
82   }
83
84   int Uart_omap35x::char_avail() const
85   {
86     return _regs->read<unsigned int>(LSR_REG) & LSR_REG_RX_FIFO_E_AVAIL;
87   }
88
89   void Uart_omap35x::out_char(char c) const
90   {
91     _regs->write<unsigned int>(THR_REG, c);
92     Poll_timeout_counter i(3000000);
93     while (i.test(!(_regs->read<unsigned int>(LSR_REG) & LSR_REG_TX_FIFO_E_EMPTY)))
94       ;
95   }
96
97   int Uart_omap35x::write(char const *s, unsigned long count) const
98   {
99     unsigned long c = count;
100     while (c--)
101       out_char(*s++);
102 #if 0
103     Poll_timeout_counter i(3000000);
104     while (i.test(_regs->read<unsigned int>(UART01x_FR) & UART01x_FR_BUSY))
105      ;
106 #endif
107
108     return count;
109   }
110
111 };
112