Rev 4060 | Rev 4220 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4060 | Rev 4114 | ||
---|---|---|---|
Line 41... | Line 41... | ||
41 | #include <synch/spinlock.h> |
41 | #include <synch/spinlock.h> |
42 | #include <arch/asm.h> |
42 | #include <arch/asm.h> |
43 | #include <arch/drivers/kbd.h> |
43 | #include <arch/drivers/kbd.h> |
44 | #include <arch.h> |
44 | #include <arch.h> |
45 | 45 | ||
46 | static chardev_t *skiout; |
46 | static indev_t skiin; /**< Ski input device. */ |
47 | - | ||
48 | static chardev_t ski_stdout; |
47 | static outdev_t skiout; /**< Ski output device. */ |
49 | 48 | ||
50 | static bool kbd_disabled; |
49 | static bool kbd_disabled; |
51 | 50 | ||
52 | /** Display character on debug console |
51 | /** Display character on debug console |
53 | * |
52 | * |
Line 55... | Line 54... | ||
55 | * display character on debug console. |
54 | * display character on debug console. |
56 | * |
55 | * |
57 | * @param d Character device. |
56 | * @param d Character device. |
58 | * @param ch Character to be printed. |
57 | * @param ch Character to be printed. |
59 | */ |
58 | */ |
60 | static void ski_putchar(chardev_t *d, const char ch, bool silent) |
59 | static void ski_putchar(outdev_t *d, const char ch, bool silent) |
61 | { |
60 | { |
62 | if (!silent) { |
61 | if (!silent) { |
63 | asm volatile ( |
62 | asm volatile ( |
64 | "mov r15 = %0\n" |
63 | "mov r15 = %0\n" |
65 | "mov r32 = %1\n" /* r32 is in0 */ |
64 | "mov r32 = %1\n" /* r32 is in0 */ |
Line 72... | Line 71... | ||
72 | if (ch == '\n') |
71 | if (ch == '\n') |
73 | ski_putchar(d, '\r', false); |
72 | ski_putchar(d, '\r', false); |
74 | } |
73 | } |
75 | } |
74 | } |
76 | 75 | ||
77 | static chardev_operations_t ski_ops = { |
76 | static indev_operations_t skiin_ops = { |
- | 77 | .poll = NULL |
|
- | 78 | }; |
|
- | 79 | ||
- | 80 | static outdev_operations_t skiout_ops = { |
|
78 | .write = ski_putchar |
81 | .write = ski_putchar |
79 | }; |
82 | }; |
80 | 83 | ||
81 | /** Ask debug console if a key was pressed. |
84 | /** Ask debug console if a key was pressed. |
82 | * |
85 | * |
Line 106... | Line 109... | ||
106 | 109 | ||
107 | /** Ask keyboard if a key was pressed. */ |
110 | /** Ask keyboard if a key was pressed. */ |
108 | static void poll_keyboard(void) |
111 | static void poll_keyboard(void) |
109 | { |
112 | { |
110 | char ch; |
113 | char ch; |
111 | ipl_t ipl; |
- | |
112 | 114 | ||
113 | ipl = interrupts_disable(); |
- | |
114 | - | ||
115 | if (kbd_disabled) { |
115 | if (kbd_disabled) |
116 | interrupts_restore(ipl); |
- | |
117 | return; |
116 | return; |
118 | } |
- | |
119 | - | ||
120 | ch = ski_getchar(); |
117 | ch = ski_getchar(); |
121 | if(ch == '\r') |
118 | if(ch == '\r') |
122 | ch = '\n'; |
119 | ch = '\n'; |
123 | if (ch && skiout) { |
120 | if (ch) { |
124 | chardev_push_character(skiout, ch); |
121 | indev_push_character(&skiin, ch); |
125 | interrupts_restore(ipl); |
- | |
126 | return; |
122 | return; |
127 | } |
123 | } |
128 | - | ||
129 | interrupts_restore(ipl); |
- | |
130 | } |
124 | } |
131 | 125 | ||
132 | #define POLL_INTERVAL 10000 /* 10 ms */ |
126 | #define POLL_INTERVAL 10000 /* 10 ms */ |
133 | 127 | ||
134 | /** Kernel thread for polling keyboard. */ |
128 | /** Kernel thread for polling keyboard. */ |
Line 145... | Line 139... | ||
145 | /** Initialize debug console |
139 | /** Initialize debug console |
146 | * |
140 | * |
147 | * Issue SSC (Simulator System Call) to |
141 | * Issue SSC (Simulator System Call) to |
148 | * to open debug console. |
142 | * to open debug console. |
149 | */ |
143 | */ |
150 | void ski_console_init(chardev_t *devout) |
144 | static void ski_init(void) |
151 | { |
145 | { |
- | 146 | static bool initialized; |
|
- | 147 | ||
- | 148 | if (initialized) |
|
- | 149 | return; |
|
- | 150 | ||
152 | asm volatile ( |
151 | asm volatile ( |
153 | "mov r15 = %0\n" |
152 | "mov r15 = %0\n" |
154 | "break 0x80000\n" |
153 | "break 0x80000\n" |
155 | : |
154 | : |
156 | : "i" (SKI_INIT_CONSOLE) |
155 | : "i" (SKI_INIT_CONSOLE) |
157 | : "r15", "r8" |
156 | : "r15", "r8" |
158 | ); |
157 | ); |
- | 158 | ||
- | 159 | initialized = true; |
|
- | 160 | } |
|
159 | 161 | ||
160 | skiout = devout; |
162 | indev_t *skiin_init(void) |
161 | chardev_initialize("ski_stdout", &ski_stdout, &ski_ops); |
- | |
- | 163 | { |
|
162 | stdout = &ski_stdout; |
164 | ski_init(); |
163 | 165 | ||
- | 166 | indev_initialize("skiin", &skiin, &skiin_ops); |
|
164 | thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true); |
167 | thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true); |
165 | if (!t) |
168 | if (t) |
166 | panic("Cannot create kkbdpoll."); |
169 | thread_ready(t); |
- | 170 | else |
|
167 | thread_ready(t); |
171 | return NULL; |
168 | 172 | ||
169 | sysinfo_set_item_val("kbd", NULL, true); |
173 | sysinfo_set_item_val("kbd", NULL, true); |
170 | sysinfo_set_item_val("kbd.type", NULL, KBD_SKI); |
174 | sysinfo_set_item_val("kbd.type", NULL, KBD_SKI); |
171 | 175 | ||
- | 176 | return &skiin; |
|
- | 177 | } |
|
- | 178 | ||
- | 179 | ||
- | 180 | void skiout_init(void) |
|
- | 181 | { |
|
- | 182 | ski_init(); |
|
- | 183 | ||
- | 184 | outdev_initialize("skiout", &skiout, &skiout_ops); |
|
- | 185 | stdout = &skiout; |
|
- | 186 | ||
172 | sysinfo_set_item_val("fb", NULL, false); |
187 | sysinfo_set_item_val("fb", NULL, false); |
173 | } |
188 | } |
174 | 189 | ||
175 | void ski_kbd_grab(void) |
190 | void ski_kbd_grab(void) |
176 | { |
191 | { |