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