Rev 1888 | Rev 1944 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1888 | Rev 1942 | ||
---|---|---|---|
Line 35... | Line 35... | ||
35 | #include <arch/ski/ski.h> |
35 | #include <arch/ski/ski.h> |
36 | #include <console/console.h> |
36 | #include <console/console.h> |
37 | #include <console/chardev.h> |
37 | #include <console/chardev.h> |
38 | #include <arch/interrupt.h> |
38 | #include <arch/interrupt.h> |
39 | #include <sysinfo/sysinfo.h> |
39 | #include <sysinfo/sysinfo.h> |
- | 40 | #include <arch/types.h> |
|
- | 41 | #include <typedefs.h> |
|
- | 42 | #include <ddi/device.h> |
|
- | 43 | #include <ddi/irq.h> |
|
- | 44 | #include <ipc/irq.h> |
|
- | 45 | #include <synch/spinlock.h> |
|
- | 46 | #include <arch/asm.h> |
|
- | 47 | ||
- | 48 | #define SKI_KBD_INR 0 |
|
- | 49 | ||
- | 50 | static irq_t ski_kbd_irq; |
|
- | 51 | static devno_t ski_kbd_devno; |
|
40 | 52 | ||
41 | chardev_t ski_console; |
53 | chardev_t ski_console; |
42 | chardev_t ski_uconsole; |
54 | chardev_t ski_uconsole; |
- | 55 | ||
43 | static bool kb_disable; |
56 | static bool kbd_disabled; |
44 | int kbd_uspace=0; |
- | |
45 | 57 | ||
46 | static void ski_putchar(chardev_t *d, const char ch); |
58 | static void ski_putchar(chardev_t *d, const char ch); |
47 | static int32_t ski_getchar(void); |
59 | static int32_t ski_getchar(void); |
48 | 60 | ||
49 | /** Display character on debug console |
61 | /** Display character on debug console |
Line 113... | Line 125... | ||
113 | /** Ask keyboard if a key was pressed. */ |
125 | /** Ask keyboard if a key was pressed. */ |
114 | void poll_keyboard(void) |
126 | void poll_keyboard(void) |
115 | { |
127 | { |
116 | char ch; |
128 | char ch; |
117 | static char last; |
129 | static char last; |
- | 130 | ipl_t ipl; |
|
118 | 131 | ||
- | 132 | ipl = interrupts_disable(); |
|
- | 133 | ||
119 | if (kb_disable) |
134 | if (kbd_disabled) { |
- | 135 | interrupts_restore(ipl); |
|
120 | return; |
136 | return; |
- | 137 | } |
|
- | 138 | ||
- | 139 | spinlock_lock(&ski_kbd_irq.lock); |
|
121 | 140 | ||
122 | ch = ski_getchar(); |
141 | ch = ski_getchar(); |
123 | if(ch == '\r') |
142 | if(ch == '\r') |
124 | ch = '\n'; |
143 | ch = '\n'; |
125 | if (ch){ |
144 | if (ch) { |
126 | if(kbd_uspace){ |
145 | if (ski_kbd_irq.notif_cfg.notify && ski_kbd_irq.notif_cfg.answerbox) { |
127 | chardev_push_character(&ski_uconsole, ch); |
146 | chardev_push_character(&ski_uconsole, ch); |
128 | virtual_interrupt(IRQ_KBD,NULL); |
147 | ipc_irq_send_notif(&ski_kbd_irq); |
129 | } |
- | |
130 | else { |
148 | } else { |
131 | chardev_push_character(&ski_console, ch); |
149 | chardev_push_character(&ski_console, ch); |
132 | } |
150 | } |
133 | last = ch; |
151 | last = ch; |
- | 152 | spinlock_unlock(&ski_kbd_irq.lock); |
|
- | 153 | interrupts_restore(ipl); |
|
134 | return; |
154 | return; |
135 | } |
155 | } |
136 | 156 | ||
137 | if (last){ |
157 | if (last) { |
138 | if(kbd_uspace){ |
158 | if (ski_kbd_irq.notif_cfg.notify && ski_kbd_irq.notif_cfg.answerbox) { |
139 | chardev_push_character(&ski_uconsole, 0); |
159 | chardev_push_character(&ski_uconsole, 0); |
140 | virtual_interrupt(IRQ_KBD,NULL); |
160 | ipc_irq_send_notif(&ski_kbd_irq); |
141 | } |
- | |
142 | else { |
- | |
143 | } |
161 | } |
144 | last = 0; |
162 | last = 0; |
145 | } |
163 | } |
146 | 164 | ||
- | 165 | spinlock_unlock(&ski_kbd_irq.lock); |
|
- | 166 | interrupts_restore(ipl); |
|
147 | } |
167 | } |
148 | 168 | ||
149 | /* Called from getc(). */ |
169 | /* Called from getc(). */ |
150 | static void ski_kb_enable(chardev_t *d) |
170 | static void ski_kbd_enable(chardev_t *d) |
151 | { |
171 | { |
152 | kb_disable = false; |
172 | kbd_disabled = false; |
153 | } |
173 | } |
154 | 174 | ||
155 | /* Called from getc(). */ |
175 | /* Called from getc(). */ |
156 | static void ski_kb_disable(chardev_t *d) |
176 | static void ski_kbd_disable(chardev_t *d) |
- | 177 | { |
|
- | 178 | kbd_disabled = true; |
|
- | 179 | } |
|
- | 180 | ||
- | 181 | /** Decline to service hardware IRQ. |
|
- | 182 | * |
|
- | 183 | * This is only a virtual IRQ, so always decline. |
|
- | 184 | * |
|
- | 185 | * @return Always IRQ_DECLINE. |
|
- | 186 | */ |
|
- | 187 | static irq_ownership_t ski_kbd_claim(void) |
|
157 | { |
188 | { |
158 | kb_disable = true; |
189 | return IRQ_DECLINE; |
159 | } |
190 | } |
160 | 191 | ||
161 | static chardev_operations_t ski_ops = { |
192 | static chardev_operations_t ski_ops = { |
162 | .resume = ski_kb_enable, |
193 | .resume = ski_kbd_enable, |
163 | .suspend = ski_kb_disable, |
194 | .suspend = ski_kbd_disable, |
164 | .write = ski_putchar, |
195 | .write = ski_putchar, |
165 | .read = ski_getchar_blocking |
196 | .read = ski_getchar_blocking |
166 | }; |
197 | }; |
167 | 198 | ||
168 | /** Initialize debug console |
199 | /** Initialize debug console |
Line 183... | Line 214... | ||
183 | chardev_initialize("ski_console", &ski_console, &ski_ops); |
214 | chardev_initialize("ski_console", &ski_console, &ski_ops); |
184 | chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops); |
215 | chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops); |
185 | stdin = &ski_console; |
216 | stdin = &ski_console; |
186 | stdout = &ski_console; |
217 | stdout = &ski_console; |
187 | 218 | ||
- | 219 | ski_kbd_devno = device_assign_devno(); |
|
- | 220 | ||
- | 221 | irq_initialize(&ski_kbd_irq); |
|
- | 222 | ski_kbd_irq.inr = SKI_KBD_INR; |
|
- | 223 | ski_kbd_irq.devno = ski_kbd_devno; |
|
- | 224 | ski_kbd_irq.claim = ski_kbd_claim; |
|
- | 225 | irq_register(&ski_kbd_irq); |
|
- | 226 | ||
188 | } |
227 | } |
189 | 228 | ||
190 | /** Setup console sysinfo (i.e. Keyboard IRQ) |
229 | /** Setup console sysinfo (i.e. Keyboard IRQ) |
191 | * |
230 | * |
192 | * Because sysinfo neads memory allocation/dealocation |
231 | * Because sysinfo neads memory allocation/dealocation |
Line 194... | Line 233... | ||
194 | * |
233 | * |
195 | */ |
234 | */ |
196 | void ski_set_console_sysinfo(void) |
235 | void ski_set_console_sysinfo(void) |
197 | { |
236 | { |
198 | sysinfo_set_item_val("kbd",NULL,true); |
237 | sysinfo_set_item_val("kbd", NULL, true); |
199 | sysinfo_set_item_val("kbd.irq",NULL,IRQ_KBD); |
238 | sysinfo_set_item_val("kbd.inr", NULL, SKI_KBD_INR); |
- | 239 | sysinfo_set_item_val("kbd.devno", NULL, ski_kbd_devno); |
|
- | 240 | } |
|
- | 241 | ||
- | 242 | void ski_kbd_grab(void) |
|
- | 243 | { |
|
- | 244 | ski_kbd_irq.notif_cfg.notify = false; |
|
- | 245 | } |
|
- | 246 | ||
- | 247 | void ski_kbd_release(void) |
|
- | 248 | { |
|
- | 249 | if (ski_kbd_irq.notif_cfg.answerbox) |
|
- | 250 | ski_kbd_irq.notif_cfg.notify = true; |
|
200 | } |
251 | } |
201 | 252 | ||
202 | /** @} |
253 | /** @} |
203 | */ |
254 | */ |