[3014e2b2] | 1 | /*
|
---|
| 2 | * Copyright (c) 2005 Jakub Jermar
|
---|
| 3 | * Copyright (c) 2009 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 |
|
---|
| 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 |
|
---|
| 47 | #define SKI_GETCHAR 21
|
---|
| 48 |
|
---|
| 49 | #define POLL_INTERVAL 10000
|
---|
| 50 |
|
---|
[36e9cd1] | 51 | static void ski_thread_impl(void *arg);
|
---|
[3014e2b2] | 52 | static int32_t ski_getchar(void);
|
---|
| 53 |
|
---|
[ccd1a14] | 54 | static volatile bool polling_disabled = false;
|
---|
| 55 |
|
---|
[3014e2b2] | 56 | /** Initialize Ski port driver. */
|
---|
| 57 | int kbd_port_init(void)
|
---|
| 58 | {
|
---|
| 59 | thread_id_t tid;
|
---|
| 60 | int rc;
|
---|
| 61 |
|
---|
| 62 | rc = thread_create(ski_thread_impl, NULL, "kbd_poll", &tid);
|
---|
| 63 | if (rc != 0) {
|
---|
| 64 | return rc;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | return 0;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[ccd1a14] | 70 | void kbd_port_yield(void)
|
---|
| 71 | {
|
---|
| 72 | polling_disabled = true;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | void kbd_port_reclaim(void)
|
---|
| 76 | {
|
---|
| 77 | polling_disabled = false;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[c145bc2] | 80 | void kbd_port_write(uint8_t data)
|
---|
| 81 | {
|
---|
| 82 | (void) data;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[3014e2b2] | 85 | /** Thread to poll Ski for keypresses. */
|
---|
[36e9cd1] | 86 | static void ski_thread_impl(void *arg)
|
---|
[3014e2b2] | 87 | {
|
---|
| 88 | int32_t c;
|
---|
| 89 | (void) arg;
|
---|
| 90 |
|
---|
| 91 | while (1) {
|
---|
[ccd1a14] | 92 | while (polling_disabled == false) {
|
---|
[9df34ee] | 93 | c = ski_getchar();
|
---|
[692b30dc] | 94 | if (c == 0)
|
---|
| 95 | break;
|
---|
[3014e2b2] | 96 | kbd_push_scancode(c);
|
---|
[9df34ee] | 97 | }
|
---|
[3014e2b2] | 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 | asm volatile (
|
---|
| 115 | "mov r15 = %1\n"
|
---|
| 116 | "break 0x80000;;\n" /* modifies r8 */
|
---|
| 117 | "mov %0 = r8;;\n"
|
---|
| 118 |
|
---|
| 119 | : "=r" (ch)
|
---|
| 120 | : "i" (SKI_GETCHAR)
|
---|
| 121 | : "r15", "r8"
|
---|
| 122 | );
|
---|
| 123 |
|
---|
| 124 | return (int32_t) ch;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | /** @}
|
---|
| 128 | */
|
---|