[3014e2b2] | 1 | /*
|
---|
| 2 | * Copyright (c) 2005 Jakub Jermar
|
---|
[9be360ee] | 3 | * Copyright (c) 2011 Jiri Svoboda
|
---|
[3014e2b2] | 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 |
|
---|
| 39 | #include <stdlib.h>
|
---|
| 40 | #include <unistd.h>
|
---|
| 41 | #include <kbd.h>
|
---|
| 42 | #include <kbd_port.h>
|
---|
| 43 | #include <sys/types.h>
|
---|
| 44 | #include <thread.h>
|
---|
[ccd1a14] | 45 | #include <bool.h>
|
---|
[3014e2b2] | 46 |
|
---|
[9be360ee] | 47 | static int ski_port_init(kbd_dev_t *);
|
---|
[b1bdc7a4] | 48 | static void ski_port_yield(void);
|
---|
| 49 | static void ski_port_reclaim(void);
|
---|
| 50 | static void ski_port_write(uint8_t data);
|
---|
| 51 |
|
---|
| 52 | kbd_port_ops_t ski_port = {
|
---|
| 53 | .init = ski_port_init,
|
---|
| 54 | .yield = ski_port_yield,
|
---|
| 55 | .reclaim = ski_port_reclaim,
|
---|
| 56 | .write = ski_port_write
|
---|
| 57 | };
|
---|
| 58 |
|
---|
[9be360ee] | 59 | static kbd_dev_t *kbd_dev;
|
---|
| 60 |
|
---|
[3014e2b2] | 61 | #define SKI_GETCHAR 21
|
---|
| 62 |
|
---|
| 63 | #define POLL_INTERVAL 10000
|
---|
| 64 |
|
---|
[36e9cd1] | 65 | static void ski_thread_impl(void *arg);
|
---|
[3014e2b2] | 66 | static int32_t ski_getchar(void);
|
---|
| 67 |
|
---|
[ccd1a14] | 68 | static volatile bool polling_disabled = false;
|
---|
| 69 |
|
---|
[3014e2b2] | 70 | /** Initialize Ski port driver. */
|
---|
[9be360ee] | 71 | static int ski_port_init(kbd_dev_t *kdev)
|
---|
[3014e2b2] | 72 | {
|
---|
| 73 | thread_id_t tid;
|
---|
| 74 | int rc;
|
---|
| 75 |
|
---|
[9be360ee] | 76 | kbd_dev = kdev;
|
---|
| 77 |
|
---|
[3014e2b2] | 78 | rc = thread_create(ski_thread_impl, NULL, "kbd_poll", &tid);
|
---|
| 79 | if (rc != 0) {
|
---|
| 80 | return rc;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | return 0;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[b1bdc7a4] | 86 | static void ski_port_yield(void)
|
---|
[ccd1a14] | 87 | {
|
---|
| 88 | polling_disabled = true;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[b1bdc7a4] | 91 | static void ski_port_reclaim(void)
|
---|
[ccd1a14] | 92 | {
|
---|
| 93 | polling_disabled = false;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[b1bdc7a4] | 96 | static void ski_port_write(uint8_t data)
|
---|
[c145bc2] | 97 | {
|
---|
| 98 | (void) data;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[3014e2b2] | 101 | /** Thread to poll Ski for keypresses. */
|
---|
[36e9cd1] | 102 | static void ski_thread_impl(void *arg)
|
---|
[3014e2b2] | 103 | {
|
---|
| 104 | int32_t c;
|
---|
| 105 | (void) arg;
|
---|
| 106 |
|
---|
| 107 | while (1) {
|
---|
[ccd1a14] | 108 | while (polling_disabled == false) {
|
---|
[9df34ee] | 109 | c = ski_getchar();
|
---|
[692b30dc] | 110 | if (c == 0)
|
---|
| 111 | break;
|
---|
[1875a0c] | 112 | kbd_push_data(kbd_dev, c);
|
---|
[9df34ee] | 113 | }
|
---|
[3014e2b2] | 114 |
|
---|
| 115 | usleep(POLL_INTERVAL);
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | /** Ask Ski if a key was pressed.
|
---|
| 120 | *
|
---|
| 121 | * Use SSC (Simulator System Call) to get character from the debug console.
|
---|
| 122 | * This call is non-blocking.
|
---|
| 123 | *
|
---|
| 124 | * @return ASCII code of pressed key or 0 if no key pressed.
|
---|
| 125 | */
|
---|
| 126 | static int32_t ski_getchar(void)
|
---|
| 127 | {
|
---|
| 128 | uint64_t ch;
|
---|
| 129 |
|
---|
[b1bdc7a4] | 130 | #ifdef UARCH_ia64
|
---|
[3014e2b2] | 131 | asm volatile (
|
---|
| 132 | "mov r15 = %1\n"
|
---|
| 133 | "break 0x80000;;\n" /* modifies r8 */
|
---|
| 134 | "mov %0 = r8;;\n"
|
---|
| 135 |
|
---|
| 136 | : "=r" (ch)
|
---|
| 137 | : "i" (SKI_GETCHAR)
|
---|
| 138 | : "r15", "r8"
|
---|
| 139 | );
|
---|
[b1bdc7a4] | 140 | #else
|
---|
| 141 | ch = 0;
|
---|
| 142 | #endif
|
---|
[3014e2b2] | 143 | return (int32_t) ch;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | /** @}
|
---|
| 147 | */
|
---|