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