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