]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/kernel_uart.cpp
update
[l4.git] / kernel / fiasco / src / kern / kernel_uart.cpp
1 INTERFACE:
2
3 class Kernel_uart
4 {
5 public:
6   enum Init_mode
7   {
8     Init_before_mmu,
9     Init_after_mmu
10   };
11   Kernel_uart();
12   static void enable_rcv_irq();
13 };
14
15 INTERFACE [serial]:
16
17 #include "uart.h"
18 #include "std_macros.h"
19
20 /**
21  * Glue between kernel and UART driver.
22  */
23 EXTENSION class Kernel_uart : public Uart
24 {
25 private:
26   /**
27    * Prototype for the UART specific startup implementation.
28    * @param uart, the instantiation to start.
29    * @param port, the com port number.
30    */
31   bool startup(unsigned port, int irq=-1);
32 };
33
34 //---------------------------------------------------------------------------
35 IMPLEMENTATION [serial]:
36
37 #include <cstring>
38 #include <cstdlib>
39 #include <cstdio>
40
41 #include "filter_console.h"
42 #include "irq_chip.h"
43 #include "irq_mgr.h"
44 #include "kdb_ke.h"
45 #include "kernel_console.h"
46 #include "uart.h"
47 #include "config.h"
48 #include "kip.h"
49 #include "koptions.h"
50 #include "panic.h"
51 #include "vkey.h"
52
53 static Static_object<Filter_console> _fcon;
54 static Static_object<Kernel_uart> _kernel_uart;
55
56 PUBLIC static FIASCO_CONST
57 Uart *
58 Kernel_uart::uart()
59 { return _kernel_uart; }
60
61 PUBLIC static
62 bool
63 Kernel_uart::init(Init_mode init_mode = Init_before_mmu)
64 {
65   if ((int)init_mode != Bsp_init_mode)
66     return false;
67
68   if (Koptions::o()->opt(Koptions::F_noserial)) // do not use serial uart
69     return true;
70
71   _kernel_uart.construct();
72   _fcon.construct(_kernel_uart);
73
74   Kconsole::console()->register_console(_fcon, 0);
75   return true;
76 }
77
78 IMPLEMENT
79 Kernel_uart::Kernel_uart()
80 {
81   unsigned           n = Config::default_console_uart_baudrate;
82   Uart::TransferMode m = Uart::MODE_8N1;
83   unsigned long long p = Config::default_console_uart;
84   int                i = -1;
85
86   if (Koptions::o()->opt(Koptions::F_uart_baud))
87     n = Koptions::o()->uart.baud;
88
89   if (Koptions::o()->opt(Koptions::F_uart_base))
90     p = Koptions::o()->uart.base_address;
91
92   if (Koptions::o()->opt(Koptions::F_uart_irq))
93     i = Koptions::o()->uart.irqno;
94
95   if (!startup(p, i))
96     printf("Comport/base 0x%04llx is not accepted by the uart driver!\n", p);
97   else if (!change_mode(m, n))
98     panic("Somthing is wrong with the baud rate (%d)!\n", n);
99 }
100
101
102 class Kuart_irq : public Irq_base
103 {
104 public:
105   Kuart_irq() { hit_func = &handler_wrapper<Kuart_irq>; }
106   void switch_mode(unsigned) {}
107   void handle(Upstream_irq const *ui)
108   {
109     mask_and_ack();
110     ui->ack();
111     unmask();
112     if (!Vkey::check_())
113       kdb_ke("IRQ ENTRY");
114   }
115 };
116
117
118 IMPLEMENT
119 void
120 Kernel_uart::enable_rcv_irq()
121 {
122   static Kuart_irq uart_irq;
123   if (Irq_mgr::mgr->alloc(&uart_irq, uart()->irq()))
124     {
125       uart_irq.unmask();
126       uart()->enable_rcv_irq();
127     }
128 }
129
130 //---------------------------------------------------------------------------
131 IMPLEMENTATION [!serial]:
132
133 PUBLIC static
134 bool
135 Kernel_uart::init(Init_mode = Init_before_mmu)
136 { return false; }
137
138 IMPLEMENT inline
139 Kernel_uart::Kernel_uart()
140 {}
141
142 IMPLEMENT inline
143 void
144 Kernel_uart::enable_rcv_irq()
145 {}