]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/kernel_uart.cpp
68506b12ca2eb35c6e10ac4b5990cd83d05230b1
[l4.git] / kernel / fiasco / src / kern / kernel_uart.cpp
1 INTERFACE:
2
3 class Kernel_uart
4 {
5 public:
6   Kernel_uart();
7   static void enable_rcv_irq();
8 };
9
10 INTERFACE [serial]:
11
12 #include "uart.h"
13 #include "std_macros.h"
14
15 /**
16  * Glue between kernel and UART driver.
17  */
18 EXTENSION class Kernel_uart : public Uart
19 {
20 private:
21   /**
22    * Prototype for the UART specific startup implementation.
23    * @param uart, the instantiation to start.
24    * @param port, the com port number.
25    */
26   bool startup(unsigned port, int irq=-1);
27 };
28
29 //---------------------------------------------------------------------------
30 IMPLEMENTATION [serial]:
31
32 #include <cstring>
33 #include <cstdlib>
34 #include <cstdio>
35
36 #include "irq.h"
37 #include "irq_chip.h"
38 #include "irq_pin.h"
39 #include "uart.h"
40 #include "cmdline.h"
41 #include "config.h"
42 #include "panic.h"
43
44 PUBLIC static FIASCO_CONST
45 Uart *
46 Kernel_uart::uart()
47 {
48   static Kernel_uart c;
49   return &c;
50 }
51
52 IMPLEMENT
53 Kernel_uart::Kernel_uart()
54 {
55   char const * const cmdline = Cmdline::cmdline();
56   char *s;
57   bool ok;
58
59   unsigned n = Config::default_console_uart_baudrate;
60   Uart::TransferMode m = Uart::MODE_8N1;
61   unsigned p = Config::default_console_uart;
62   int      i = -1;
63
64   if (  (s = strstr(cmdline, " -comspeed "))
65       ||(s = strstr(cmdline, " -comspeed=")))
66     {
67       if ((n = strtoul(s + 11, 0, 0)) > 115200 || n < 1)
68         {
69           puts ("-comspeed > 115200 not supported or invalid (using 115200)!");
70           n = 115200;
71         }
72     }
73
74   if (  (s = strstr(cmdline, " -comport "))
75       ||(s = strstr(cmdline, " -comport=")))
76     p = strtoul(s + 10, 0, 0);
77
78   if ((s = strstr(cmdline, " -comirq=")))
79     i = strtoul(s + 9, 0, 0);
80
81   if (!(ok = startup(p, i)))
82     printf("Comport 0x%04x is not accepted by the uart driver!\n", p);
83
84   if (ok && !change_mode(m, n))
85     panic("Somthing is wrong with the baud rate (%d)!\n", n);
86 }
87
88
89 IMPLEMENT
90 void
91 Kernel_uart::enable_rcv_irq()
92 {
93   // we must not allocate the IRQ in the constructor but here 
94   // since the constructor is called before Dirq::Dirq() constructor
95   static Irq_debugger uart_irq;
96   if (Irq_chip::hw_chip->alloc(&uart_irq, uart()->irq()))
97     {
98       uart_irq.pin()->unmask();
99       uart()->enable_rcv_irq();
100     }
101 }
102
103 //---------------------------------------------------------------------------
104 IMPLEMENTATION [!serial]: 
105
106 IMPLEMENT inline
107 Kernel_uart::Kernel_uart()
108 {}
109
110 IMPLEMENT inline
111 void
112 Kernel_uart::enable_rcv_irq()
113 {}