1 | /* |
---|
2 | * RTEMS for Nintendo DS console driver. |
---|
3 | * |
---|
4 | * Copyright (c) 2008 by Renaud Voltz <renaud.voltz@gmail.com> |
---|
5 | * Matthieu Bucchianeri <mbucchia@gmail.com> |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * |
---|
10 | * http://www.rtems.org/license/LICENSE |
---|
11 | */ |
---|
12 | |
---|
13 | #include <bsp.h> |
---|
14 | #include <nds.h> |
---|
15 | #include <rtems/libio.h> |
---|
16 | #include <nds/arm9/console.h> |
---|
17 | #include <sys/iosupport.h> |
---|
18 | |
---|
19 | #include <rtems/mw_uid.h> |
---|
20 | |
---|
21 | /* |
---|
22 | * enables testsuite output to desmume. this is used to pass the rtems |
---|
23 | * testsuite. |
---|
24 | * comment the following line to disable (recommended). |
---|
25 | */ |
---|
26 | |
---|
27 | //#define TESTSUITE |
---|
28 | |
---|
29 | /* |
---|
30 | * printk support. |
---|
31 | */ |
---|
32 | |
---|
33 | /* from NDS support library */ |
---|
34 | extern void consolePrintChar(char c); |
---|
35 | void |
---|
36 | nds_putch (char c) |
---|
37 | { |
---|
38 | #ifdef TESTSUITE |
---|
39 | __asm__ volatile ("swi $0x1"); |
---|
40 | #endif |
---|
41 | consolePrintChar (c); |
---|
42 | } |
---|
43 | |
---|
44 | static volatile char ch = 0; |
---|
45 | |
---|
46 | void |
---|
47 | console_push (char c) |
---|
48 | { |
---|
49 | ch = c; |
---|
50 | } |
---|
51 | |
---|
52 | int |
---|
53 | nds_getch (void) |
---|
54 | { |
---|
55 | char c; |
---|
56 | |
---|
57 | while (ch == 0); |
---|
58 | c = ch; |
---|
59 | ch = 0; |
---|
60 | return c; |
---|
61 | } |
---|
62 | |
---|
63 | BSP_output_char_function_type BSP_output_char = nds_putch; |
---|
64 | BSP_polling_getchar_function_type BSP_poll_char = nds_getch; |
---|
65 | |
---|
66 | /* |
---|
67 | * console write operation. |
---|
68 | */ |
---|
69 | |
---|
70 | static ssize_t |
---|
71 | nds_write (int minor, const char *buf, size_t len) |
---|
72 | { |
---|
73 | int count; |
---|
74 | |
---|
75 | for (count = 0; count < len; count++) { |
---|
76 | nds_putch (buf[count]); |
---|
77 | } |
---|
78 | |
---|
79 | return 0; |
---|
80 | } |
---|
81 | |
---|
82 | /* |
---|
83 | * console read operation. |
---|
84 | */ |
---|
85 | |
---|
86 | static int |
---|
87 | nds_read (int minor) |
---|
88 | { |
---|
89 | return nds_getch (); |
---|
90 | } |
---|
91 | |
---|
92 | /* |
---|
93 | * from touchscreen/parser.c |
---|
94 | */ |
---|
95 | |
---|
96 | void register_kbd_msg_queue (char *q_name); |
---|
97 | void unregister_kbd_msg_queue (void); |
---|
98 | |
---|
99 | /* |
---|
100 | * Console driver |
---|
101 | */ |
---|
102 | |
---|
103 | rtems_device_driver |
---|
104 | console_initialize (rtems_device_major_number major, |
---|
105 | rtems_device_minor_number minor, void *arg) |
---|
106 | { |
---|
107 | rtems_status_code status; |
---|
108 | |
---|
109 | printk ("[+] console started\n"); |
---|
110 | |
---|
111 | rtems_termios_initialize (); |
---|
112 | |
---|
113 | status = rtems_io_register_name ("/dev/console", major, 0); |
---|
114 | if (status != RTEMS_SUCCESSFUL) { |
---|
115 | printk ("[!] error registering console\n"); |
---|
116 | rtems_fatal_error_occurred (status); |
---|
117 | } |
---|
118 | |
---|
119 | return (RTEMS_SUCCESSFUL); |
---|
120 | } |
---|
121 | |
---|
122 | rtems_device_driver |
---|
123 | console_open (rtems_device_major_number major, |
---|
124 | rtems_device_minor_number minor, void *arg) |
---|
125 | { |
---|
126 | rtems_status_code status; |
---|
127 | static rtems_termios_callbacks cb = { |
---|
128 | NULL, /* firstOpen */ |
---|
129 | NULL, /* lastClose */ |
---|
130 | nds_read, /* pollRead */ |
---|
131 | nds_write, /* write */ |
---|
132 | NULL, /* setAttributes */ |
---|
133 | NULL, /* stopRemoteTx */ |
---|
134 | NULL, /* startRemoteTx */ |
---|
135 | 0 /* 1 = outputUsesInterrupts */ |
---|
136 | }; |
---|
137 | |
---|
138 | status = rtems_termios_open (major, minor, arg, &cb); |
---|
139 | if (status != RTEMS_SUCCESSFUL) |
---|
140 | printk ("[!] error opening console\n"); |
---|
141 | |
---|
142 | return (status); |
---|
143 | } |
---|
144 | |
---|
145 | rtems_device_driver |
---|
146 | console_close (rtems_device_major_number major, |
---|
147 | rtems_device_minor_number minor, void *arg) |
---|
148 | { |
---|
149 | rtems_device_driver res = RTEMS_SUCCESSFUL; |
---|
150 | |
---|
151 | res = rtems_termios_close (arg); |
---|
152 | |
---|
153 | return res; |
---|
154 | } |
---|
155 | |
---|
156 | rtems_device_driver |
---|
157 | console_read (rtems_device_major_number major, |
---|
158 | rtems_device_minor_number minor, void *arg) |
---|
159 | { |
---|
160 | return rtems_termios_read (arg); |
---|
161 | } |
---|
162 | |
---|
163 | rtems_device_driver |
---|
164 | console_write (rtems_device_major_number major, |
---|
165 | rtems_device_minor_number minor, void *arg) |
---|
166 | { |
---|
167 | return rtems_termios_write (arg); |
---|
168 | } |
---|
169 | |
---|
170 | rtems_device_driver |
---|
171 | console_control (rtems_device_major_number major, |
---|
172 | rtems_device_minor_number minor, void *arg) |
---|
173 | { |
---|
174 | rtems_libio_ioctl_args_t *args = arg; |
---|
175 | |
---|
176 | switch (args->command) { |
---|
177 | case MW_UID_REGISTER_DEVICE: |
---|
178 | register_kbd_msg_queue (args->buffer); |
---|
179 | break; |
---|
180 | case MW_UID_UNREGISTER_DEVICE: |
---|
181 | unregister_kbd_msg_queue (); |
---|
182 | break; |
---|
183 | default: |
---|
184 | return rtems_termios_ioctl (arg); |
---|
185 | } |
---|
186 | args->ioctl_return = 0; |
---|
187 | |
---|
188 | return RTEMS_SUCCESSFUL; |
---|
189 | } |
---|