Rev 4071 | Rev 4202 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4071 | Rev 4111 | ||
|---|---|---|---|
| Line 128... | Line 128... | ||
| 128 | */ |
128 | */ |
| 129 | SPINLOCK_INITIALIZE(sgcn_input_lock); |
129 | SPINLOCK_INITIALIZE(sgcn_input_lock); |
| 130 | 130 | ||
| 131 | 131 | ||
| 132 | /* functions referenced from definitions of I/O operations structures */ |
132 | /* functions referenced from definitions of I/O operations structures */ |
| 133 | static void sgcn_noop(chardev_t *); |
- | |
| 134 | static void sgcn_putchar(chardev_t *, const char, bool); |
133 | static void sgcn_putchar(outdev_t *, const char, bool); |
| 135 | static char sgcn_key_read(chardev_t *); |
- | |
| 136 | 134 | ||
| 137 | /** character device operations */ |
135 | /** SGCN output device operations */ |
| 138 | static chardev_operations_t sgcn_ops = { |
136 | static outdev_operations_t sgcnout_ops = { |
| 139 | .suspend = sgcn_noop, |
- | |
| 140 | .resume = sgcn_noop, |
- | |
| 141 | .read = sgcn_key_read, |
- | |
| 142 | .write = sgcn_putchar |
137 | .write = sgcn_putchar |
| 143 | }; |
138 | }; |
| 144 | 139 | ||
| 145 | /** SGCN character device */ |
140 | /** SGCN input device operations */ |
| 146 | chardev_t sgcn_io; |
141 | static indev_operations_t sgcnin_ops = { |
| - | 142 | .poll = NULL |
|
| - | 143 | }; |
|
| 147 | 144 | ||
| 148 | /** Address of the chardev, which is connected to SGCN. */ |
145 | static indev_t sgcnin; /**< SGCN input device. */ |
| 149 | static chardev_t *sgcnout; |
146 | static outdev_t sgcnout; /**< SGCN output device. */ |
| 150 | 147 | ||
| 151 | /** |
148 | /** |
| 152 | * Set some sysinfo values (SRAM address and SRAM size). |
149 | * Set some sysinfo values (SRAM address and SRAM size). |
| 153 | */ |
150 | */ |
| 154 | static void register_sram(uintptr_t sram_begin_physical) |
151 | static void register_sram(uintptr_t sram_begin_physical) |
| Line 201... | Line 198... | ||
| 201 | * This function also writes the offset of the SGCN buffer within SRAM |
198 | * This function also writes the offset of the SGCN buffer within SRAM |
| 202 | * under the sram.buffer.offset sysinfo key. |
199 | * under the sram.buffer.offset sysinfo key. |
| 203 | */ |
200 | */ |
| 204 | static void sgcn_buffer_begin_init(void) |
201 | static void sgcn_buffer_begin_init(void) |
| 205 | { |
202 | { |
| - | 203 | static bool initialized; |
|
| - | 204 | ||
| - | 205 | if (initialized) |
|
| - | 206 | return; |
|
| - | 207 | ||
| 206 | init_sram_begin(); |
208 | init_sram_begin(); |
| 207 | 209 | ||
| 208 | ASSERT(strcmp(SRAM_TOC->magic, SRAM_TOC_MAGIC) == 0); |
210 | ASSERT(strcmp(SRAM_TOC->magic, SRAM_TOC_MAGIC) == 0); |
| 209 | 211 | ||
| 210 | /* lookup TOC entry with the correct key */ |
212 | /* lookup TOC entry with the correct key */ |
| Line 217... | Line 219... | ||
| 217 | 219 | ||
| 218 | sgcn_buffer_begin = sram_begin + SRAM_TOC->keys[i].offset; |
220 | sgcn_buffer_begin = sram_begin + SRAM_TOC->keys[i].offset; |
| 219 | 221 | ||
| 220 | sysinfo_set_item_val("sram.buffer.offset", NULL, |
222 | sysinfo_set_item_val("sram.buffer.offset", NULL, |
| 221 | SRAM_TOC->keys[i].offset); |
223 | SRAM_TOC->keys[i].offset); |
| 222 | } |
224 | |
| 223 | - | ||
| 224 | /** |
- | |
| 225 | * Default suspend/resume operation for the input device. |
- | |
| 226 | */ |
- | |
| 227 | static void sgcn_noop(chardev_t *d) |
225 | initialized = true; |
| 228 | { |
- | |
| 229 | } |
226 | } |
| 230 | 227 | ||
| 231 | /** |
228 | /** |
| 232 | * Writes a single character to the SGCN (circular) output buffer |
229 | * Writes a single character to the SGCN (circular) output buffer |
| 233 | * and updates the output write pointer so that SGCN gets to know |
230 | * and updates the output write pointer so that SGCN gets to know |
| Line 269... | Line 266... | ||
| 269 | /** |
266 | /** |
| 270 | * SGCN output operation. Prints a single character to the SGCN. If the line |
267 | * SGCN output operation. Prints a single character to the SGCN. If the line |
| 271 | * feed character is written ('\n'), the carriage return character ('\r') is |
268 | * feed character is written ('\n'), the carriage return character ('\r') is |
| 272 | * written straight away. |
269 | * written straight away. |
| 273 | */ |
270 | */ |
| 274 | static void sgcn_putchar(struct chardev * cd, const char c, bool silent) |
271 | static void sgcn_putchar(outdev_t *od, const char c, bool silent) |
| 275 | { |
272 | { |
| 276 | if (!silent) { |
273 | if (!silent) { |
| 277 | spinlock_lock(&sgcn_output_lock); |
274 | spinlock_lock(&sgcn_output_lock); |
| 278 | 275 | ||
| 279 | sgcn_do_putchar(c); |
276 | sgcn_do_putchar(c); |
| Line 283... | Line 280... | ||
| 283 | spinlock_unlock(&sgcn_output_lock); |
280 | spinlock_unlock(&sgcn_output_lock); |
| 284 | } |
281 | } |
| 285 | } |
282 | } |
| 286 | 283 | ||
| 287 | /** |
284 | /** |
| 288 | * Called when actively reading the character. Not implemented yet. |
- | |
| 289 | */ |
- | |
| 290 | static char sgcn_key_read(chardev_t *d) |
- | |
| 291 | { |
- | |
| 292 | return (char) 0; |
- | |
| 293 | } |
- | |
| 294 | - | ||
| 295 | /** |
- | |
| 296 | * Grabs the input for kernel. |
285 | * Grabs the input for kernel. |
| 297 | */ |
286 | */ |
| 298 | void sgcn_grab(void) |
287 | void sgcn_grab(void) |
| 299 | { |
288 | { |
| 300 | kbd_disabled = true; |
289 | kbd_disabled = true; |
| Line 335... | Line 324... | ||
| 335 | buf_ptr = (volatile char *) |
324 | buf_ptr = (volatile char *) |
| 336 | SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr); |
325 | SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr); |
| 337 | char c = *buf_ptr; |
326 | char c = *buf_ptr; |
| 338 | *in_rdptr_ptr = (((*in_rdptr_ptr) - begin + 1) % size) + begin; |
327 | *in_rdptr_ptr = (((*in_rdptr_ptr) - begin + 1) % size) + begin; |
| 339 | 328 | ||
| 340 | if (sgcnout) |
- | |
| 341 | chardev_push_character(sgcnout, c); |
329 | indev_push_character(&sgcnin, c); |
| 342 | } |
330 | } |
| 343 | 331 | ||
| 344 | spinlock_unlock(&sgcn_input_lock); |
332 | spinlock_unlock(&sgcn_input_lock); |
| 345 | } |
333 | } |
| 346 | 334 | ||
| Line 355... | Line 343... | ||
| 355 | thread_usleep(POLL_INTERVAL); |
343 | thread_usleep(POLL_INTERVAL); |
| 356 | } |
344 | } |
| 357 | } |
345 | } |
| 358 | 346 | ||
| 359 | /** |
347 | /** |
| 360 | * A public function which initializes I/O from/to Serengeti console |
348 | * A public function which initializes input from the Serengeti console. |
| 361 | * and sets it as a default input/output. |
- | |
| 362 | */ |
349 | */ |
| 363 | void sgcn_init(chardev_t *devout) |
350 | indev_t *sgcnin_init(void) |
| 364 | { |
351 | { |
| 365 | sgcn_buffer_begin_init(); |
352 | sgcn_buffer_begin_init(); |
| 366 | 353 | ||
| 367 | kbd_type = KBD_SGCN; |
354 | kbd_type = KBD_SGCN; |
| 368 | 355 | ||
| 369 | sysinfo_set_item_val("kbd", NULL, true); |
356 | sysinfo_set_item_val("kbd", NULL, true); |
| 370 | sysinfo_set_item_val("kbd.type", NULL, KBD_SGCN); |
357 | sysinfo_set_item_val("kbd.type", NULL, KBD_SGCN); |
| 371 | sysinfo_set_item_val("fb.kind", NULL, 4); |
- | |
| 372 | 358 | ||
| 373 | thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true); |
359 | thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true); |
| 374 | if (!t) |
360 | if (!t) |
| 375 | panic("Cannot create kkbdpoll."); |
361 | panic("Cannot create kkbdpoll."); |
| 376 | thread_ready(t); |
362 | thread_ready(t); |
| 377 | 363 | ||
| 378 | chardev_initialize("sgcn_io", &sgcn_io, &sgcn_ops); |
364 | indev_initialize("sgcnin", &sgcnin, &sgcnin_ops); |
| - | 365 | ||
| 379 | stdout = &sgcn_io; |
366 | return &sgcnin; |
| - | 367 | } |
|
| - | 368 | ||
| - | 369 | /** |
|
| - | 370 | * A public function which initializes output to the Serengeti console. |
|
| - | 371 | */ |
|
| - | 372 | void sgcnout_init(void) |
|
| - | 373 | { |
|
| - | 374 | sgcn_buffer_begin_init(); |
|
| - | 375 | ||
| - | 376 | sysinfo_set_item_val("fb.kind", NULL, 4); |
|
| 380 | 377 | ||
| - | 378 | outdev_initialize("sgcnout", &sgcnout, &sgcnout_ops); |
|
| 381 | sgcnout = devout; |
379 | stdout = &sgcnout; |
| 382 | } |
380 | } |
| 383 | 381 | ||
| 384 | /** @} |
382 | /** @} |
| 385 | */ |
383 | */ |