00001 /* 00002 * Copyright (c) 2005 Jakub Jermar 00003 * Copyright (c) 2009 Jiri Svoboda 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 00010 * - Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * - Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * - The name of the author may not be used to endorse or promote products 00016 * derived from this software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00019 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00020 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00021 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00022 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00023 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00024 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00025 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00026 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00027 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00039 #include <stdlib.h> 00040 #include <unistd.h> 00041 #include <kbd.h> 00042 #include <kbd_port.h> 00043 #include <sys/types.h> 00044 #include <thread.h> 00045 #include <bool.h> 00046 00047 #define SKI_GETCHAR 21 00048 00049 #define POLL_INTERVAL 10000 00050 00051 static void ski_thread_impl(void *arg); 00052 static int32_t ski_getchar(void); 00053 00054 static volatile bool polling_disabled = false; 00055 00057 int kbd_port_init(void) 00058 { 00059 thread_id_t tid; 00060 int rc; 00061 00062 rc = thread_create(ski_thread_impl, NULL, "kbd_poll", &tid); 00063 if (rc != 0) { 00064 return rc; 00065 } 00066 00067 return 0; 00068 } 00069 00070 void kbd_port_yield(void) 00071 { 00072 polling_disabled = true; 00073 } 00074 00075 void kbd_port_reclaim(void) 00076 { 00077 polling_disabled = false; 00078 } 00079 00080 void kbd_port_write(uint8_t data) 00081 { 00082 (void) data; 00083 } 00084 00086 static void ski_thread_impl(void *arg) 00087 { 00088 int32_t c; 00089 (void) arg; 00090 00091 while (1) { 00092 while (polling_disabled == false) { 00093 c = ski_getchar(); 00094 if (c == 0) 00095 break; 00096 kbd_push_scancode(c); 00097 } 00098 00099 usleep(POLL_INTERVAL); 00100 } 00101 } 00102 00110 static int32_t ski_getchar(void) 00111 { 00112 uint64_t ch; 00113 00114 asm volatile ( 00115 "mov r15 = %1\n" 00116 "break 0x80000;;\n" /* modifies r8 */ 00117 "mov %0 = r8;;\n" 00118 00119 : "=r" (ch) 00120 : "i" (SKI_GETCHAR) 00121 : "r15", "r8" 00122 ); 00123 00124 return (int32_t) ch; 00125 } 00126