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