]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/drivers/uart/src/uart_of.cc
update
[l4.git] / l4 / pkg / drivers / uart / src / uart_of.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_of.h"
10 #include <stdio.h>
11
12 namespace L4 {
13
14   bool Uart_of::startup(unsigned long /*base*/)
15   {
16     char path[64], type[16];
17     for(phandle_t node = 0; prom_next_node(&node); ) {
18         prom_getprop(node, "device_type", type, sizeof(type));
19
20         if(strcmp(type, "serial"))
21           continue;
22
23         if(prom_call("package-to-path", 3, 1, node, path, sizeof(path)) == Of::PROM_ERROR) 
24           return false;
25
26         /* open port */
27         if((_serial = (ihandle_t)prom_call("open", 1, 1, path)) <= 0)
28           return false;
29
30         break;
31     }
32     //prom_call("exit", 0, 0);
33     return (!_serial)?false:true;
34   }
35
36   void Uart_of::shutdown()
37   {
38     prom_call("close", 1, 0, _serial);
39   }
40
41   int Uart_of::get_char(bool blocking) const
42   {
43     int c, len = 0;
44
45     while(len != 1 && blocking)
46       len = prom_call("read", 3, 1, _serial, &c, 1);
47
48     return (len)?c:-1;
49   }
50
51   int Uart_of::write(char const *s, unsigned long count) const
52   {
53     return prom_call("write", 3, 1, _serial, s, count);
54   }
55
56   void Uart_of::out_char(char c) const
57   {
58     prom_call("write", 3, 0, _serial, c, 1);
59   }
60
61   /* UNIMPLEMENTED */
62   bool Uart_of::enable_rx_irq(bool){return true;}
63   bool Uart_of::enable_tx_irq(bool){return true;}
64   bool Uart_of::change_mode(Transfer_mode, Baud_rate){return true;}
65   int  Uart_of::char_avail() const {return 1;}
66 };