| 1 | /*
|
|---|
| 2 | * Copyright (c) 2005 Jakub Jermar
|
|---|
| 3 | * Copyright (c) 2011 Jiri Svoboda
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | *
|
|---|
| 10 | * - Redistributions of source code must retain the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | * documentation and/or other materials provided with the distribution.
|
|---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | * derived from this software without specific prior written permission.
|
|---|
| 17 | *
|
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | /** @addtogroup kbd_port
|
|---|
| 31 | * @ingroup kbd
|
|---|
| 32 | * @{
|
|---|
| 33 | */
|
|---|
| 34 | /** @file
|
|---|
| 35 | * @brief Ski console keyboard port driver.
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <stdlib.h>
|
|---|
| 39 | #include <unistd.h>
|
|---|
| 40 | #include <sys/types.h>
|
|---|
| 41 | #include <thread.h>
|
|---|
| 42 | #include <stdbool.h>
|
|---|
| 43 | #include "../kbd_port.h"
|
|---|
| 44 | #include "../kbd.h"
|
|---|
| 45 |
|
|---|
| 46 | static int ski_port_init(kbd_dev_t *);
|
|---|
| 47 | static void ski_port_write(uint8_t data);
|
|---|
| 48 |
|
|---|
| 49 | kbd_port_ops_t ski_port = {
|
|---|
| 50 | .init = ski_port_init,
|
|---|
| 51 | .write = ski_port_write
|
|---|
| 52 | };
|
|---|
| 53 |
|
|---|
| 54 | static kbd_dev_t *kbd_dev;
|
|---|
| 55 |
|
|---|
| 56 | #define SKI_GETCHAR 21
|
|---|
| 57 |
|
|---|
| 58 | #define POLL_INTERVAL 10000
|
|---|
| 59 |
|
|---|
| 60 | static void ski_thread_impl(void *arg);
|
|---|
| 61 | static int32_t ski_getchar(void);
|
|---|
| 62 |
|
|---|
| 63 | /** Initialize Ski port driver. */
|
|---|
| 64 | static int ski_port_init(kbd_dev_t *kdev)
|
|---|
| 65 | {
|
|---|
| 66 | thread_id_t tid;
|
|---|
| 67 | int rc;
|
|---|
| 68 |
|
|---|
| 69 | kbd_dev = kdev;
|
|---|
| 70 |
|
|---|
| 71 | rc = thread_create(ski_thread_impl, NULL, "kbd_poll", &tid);
|
|---|
| 72 | if (rc != 0) {
|
|---|
| 73 | return rc;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | return 0;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | static void ski_port_write(uint8_t data)
|
|---|
| 80 | {
|
|---|
| 81 | (void) data;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | /** Thread to poll Ski for keypresses. */
|
|---|
| 85 | static void ski_thread_impl(void *arg)
|
|---|
| 86 | {
|
|---|
| 87 | int32_t c;
|
|---|
| 88 | (void) arg;
|
|---|
| 89 |
|
|---|
| 90 | while (1) {
|
|---|
| 91 | while (1) {
|
|---|
| 92 | c = ski_getchar();
|
|---|
| 93 | if (c == 0)
|
|---|
| 94 | break;
|
|---|
| 95 |
|
|---|
| 96 | kbd_push_data(kbd_dev, c);
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | usleep(POLL_INTERVAL);
|
|---|
| 100 | }
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | /** Ask Ski if a key was pressed.
|
|---|
| 104 | *
|
|---|
| 105 | * Use SSC (Simulator System Call) to get character from the debug console.
|
|---|
| 106 | * This call is non-blocking.
|
|---|
| 107 | *
|
|---|
| 108 | * @return ASCII code of pressed key or 0 if no key pressed.
|
|---|
| 109 | */
|
|---|
| 110 | static int32_t ski_getchar(void)
|
|---|
| 111 | {
|
|---|
| 112 | uint64_t ch;
|
|---|
| 113 |
|
|---|
| 114 | #ifdef UARCH_ia64
|
|---|
| 115 | asm volatile (
|
|---|
| 116 | "mov r15 = %1\n"
|
|---|
| 117 | "break 0x80000;;\n" /* modifies r8 */
|
|---|
| 118 | "mov %0 = r8;;\n"
|
|---|
| 119 |
|
|---|
| 120 | : "=r" (ch)
|
|---|
| 121 | : "i" (SKI_GETCHAR)
|
|---|
| 122 | : "r15", "r8"
|
|---|
| 123 | );
|
|---|
| 124 | #else
|
|---|
| 125 | ch = 0;
|
|---|
| 126 | #endif
|
|---|
| 127 | return (int32_t) ch;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | /** @}
|
|---|
| 131 | */
|
|---|