]> 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 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
11 namespace L4
12 {
13   enum {
14     DLL_REG  = 0x00,
15     RHR_REG  = 0x00,
16     THR_REG  = 0x00,
17     IER_REG  = 0x04,
18     DLH_REG  = 0x04,
19     LCD_REG  = 0x08,
20     LSR_REG  = 0x14,
21     SSR_REG  = 0x44,
22     SYSC_REG = 0x54,
23     SYSS_REG = 0x58,
24
25     LCD_REG_CHAR_LENGTH_5BIT       = 0 << 0,
26     LCD_REG_CHAR_LENGTH_6BIT       = 1 << 0,
27     LCD_REG_CHAR_LENGTH_7BIT       = 2 << 0,
28     LCD_REG_CHAR_LENGTH_8BIT       = 3 << 0,
29     LCD_REG_CHAR_NB_STOP_2         = 1 << 2,
30     LCD_REG_CHAR_PARITY_EN         = 1 << 3,
31     LCD_REG_CHAR_PARITY_TYPE1_EVEN = 1 << 4,
32
33     LSR_REG_RX_FIFO_E_AVAIL        = 1 << 0,
34     LSR_REG_TX_FIFO_E_EMPTY        = 1 << 5,
35
36     SSR_REG_TX_FIFO_FULL           = 1 << 0,
37
38     SYSC_REG_SOFTRESET             = 1 << 1,
39
40     SYSC_REG_RESETDONE             = 1 << 0,
41   };
42
43
44   unsigned long Uart_omap35x::rd(unsigned long reg) const
45   {
46     volatile unsigned long *r = (unsigned long*)(_base + reg);
47     return *r;
48   }
49
50   void Uart_omap35x::wr(unsigned long reg, unsigned long val) const
51   {
52     volatile unsigned long *r = (unsigned long*)(_base + reg);
53     *r = val;
54   }
55
56   bool Uart_omap35x::startup(unsigned long base)
57   {
58     _base = base;
59
60     // Reset UART
61     //wr(SYSC_REG, rd(SYSC_REG) | SYSC_REG_SOFTRESET);
62     //while (!(rd(SYSS_REG) & SYSC_REG_RESETDONE))
63     //  ;
64
65     return true;
66   }
67
68   void Uart_omap35x::shutdown()
69   {
70   }
71
72   bool Uart_omap35x::enable_rx_irq(bool enable)
73   {
74     wr(IER_REG, enable ? 1 : 0);
75     return true;
76   }
77   bool Uart_omap35x::enable_tx_irq(bool /*enable*/) { return false; }
78   bool Uart_omap35x::change_mode(Transfer_mode, Baud_rate r)
79   {
80     if (r != 115200)
81       return false;
82
83     return true;
84   }
85
86   int Uart_omap35x::get_char(bool blocking) const
87   {
88     while (!char_avail())
89       if (!blocking)
90         return -1;
91
92     return rd(RHR_REG);
93   }
94
95   int Uart_omap35x::char_avail() const
96   {
97     return rd(LSR_REG) & LSR_REG_RX_FIFO_E_AVAIL;
98   }
99
100   void Uart_omap35x::out_char(char c) const
101   {
102     wr(THR_REG, c);
103     while (!(rd(LSR_REG) & LSR_REG_TX_FIFO_E_EMPTY))
104       ;
105   }
106
107   int Uart_omap35x::write(char const *s, unsigned long count) const
108   {
109     unsigned long c = count;
110     while (c)
111       {
112         if (*s == 10)
113           out_char(13);
114         out_char(*s++);
115         --c;
116       }
117   //  while (rd(UART01x_FR) & UART01x_FR_BUSY)
118    //   ;
119
120     return count;
121   }
122
123 };
124