1 | /* |
---|
2 | ///////////////////////////////////////////////////////////////////////////// |
---|
3 | // $Header$ |
---|
4 | // |
---|
5 | // Copyright (c) 2000 - Rosimildo da Silva |
---|
6 | // |
---|
7 | // MODULE DESCRIPTION: |
---|
8 | // This module implements the input devices interface used by MicroWindows |
---|
9 | // in an embedded system environment. |
---|
10 | // It uses the RTEMS message queue as the repository for the messages posted |
---|
11 | // by the devices registered. |
---|
12 | // |
---|
13 | // MODIFICATION/HISTORY: |
---|
14 | // |
---|
15 | // $Log$ |
---|
16 | // Revision 1.6 2004/03/26 06:59:18 ralf |
---|
17 | // 2004-03-26 Ralf Corsepius <ralf_corsepius@rtems.org> |
---|
18 | // |
---|
19 | // * libmisc/capture/capture-cli.c, libmisc/capture/capture.c, |
---|
20 | // libmisc/capture/capture.h, libmisc/cpuuse/cpuuse.c, |
---|
21 | // libmisc/devnull/devnull.c, libmisc/fsmount/fsmount.h, |
---|
22 | // libmisc/monitor/mon-config.c, libmisc/monitor/mon-dname.c, |
---|
23 | // libmisc/monitor/mon-driver.c, libmisc/monitor/mon-extension.c, |
---|
24 | // libmisc/monitor/mon-itask.c, libmisc/monitor/mon-monitor.c, |
---|
25 | // libmisc/monitor/mon-mpci.c, libmisc/monitor/mon-object.c, |
---|
26 | // libmisc/monitor/mon-prmisc.c, libmisc/monitor/mon-queue.c, |
---|
27 | // libmisc/monitor/mon-server.c, libmisc/monitor/mon-symbols.c, |
---|
28 | // libmisc/monitor/monitor.h, libmisc/monitor/symbols.h, |
---|
29 | // libmisc/mw-fb/mw_uid.c, libmisc/rtmonuse/rtmonuse.c, |
---|
30 | // libmisc/serdbg/serdbg.h, libmisc/serdbg/serdbgio.c, |
---|
31 | // libmisc/serdbg/termios_printk.c, libmisc/serdbg/termios_printk.h, |
---|
32 | // libmisc/shell/shell.c, libmisc/shell/shell.h, libmisc/stackchk/check.c, |
---|
33 | // libmisc/stackchk/internal.h: Convert to using c99 fixed size types. |
---|
34 | // |
---|
35 | // Revision 1.5 2003/07/08 08:38:48 ralf |
---|
36 | // 2003-07-08 Ralf Corsepius <corsepiu@faw.uni-ulm.de> |
---|
37 | // |
---|
38 | // * capture/capture-cli.c: Add config-header support. |
---|
39 | // * capture/capture.c: Add config-header support. |
---|
40 | // * cpuuse/cpuuse.c: Add config-header support. |
---|
41 | // * devnull/devnull.c: Add config-header support. |
---|
42 | // * dummy/dummy.c: Add config-header support. |
---|
43 | // * dumpbuf/dumpbuf.c: Add config-header support. |
---|
44 | // * monitor/mon-command.c: Add config-header support. |
---|
45 | // * monitor/mon-config.c: Add config-header support. |
---|
46 | // * monitor/mon-dname.c: Add config-header support. |
---|
47 | // * monitor/mon-driver.c: Add config-header support. |
---|
48 | // * monitor/mon-extension.c: Add config-header support. |
---|
49 | // * monitor/mon-itask.c: Add config-header support. |
---|
50 | // * monitor/mon-manager.c: Add config-header support. |
---|
51 | // * monitor/mon-monitor.c: Add config-header support. |
---|
52 | // * monitor/mon-mpci.c: Add config-header support. |
---|
53 | // * monitor/mon-object.c: Add config-header support. |
---|
54 | // * monitor/mon-prmisc.c: Add config-header support. |
---|
55 | // * monitor/mon-queue.c: Add config-header support. |
---|
56 | // * monitor/mon-server.c: Add config-header support. |
---|
57 | // * monitor/mon-symbols.c: Add config-header support. |
---|
58 | // * monitor/mon-task.c: Add config-header support. |
---|
59 | // * mw-fb/mw_fb.c: Add config-header support. |
---|
60 | // * mw-fb/mw_uid.c: Add config-header support. |
---|
61 | // * rtmonuse/rtmonuse.c: Add config-header support. |
---|
62 | // * serdbg/serdbg.c: Add config-header support. |
---|
63 | // * serdbg/serdbgio.c: Add config-header support. |
---|
64 | // * serdbg/termios_printk.c: Add config-header support. |
---|
65 | // * shell/cmds.c: Add config-header support. |
---|
66 | // * stackchk/check.c: Add config-header support. |
---|
67 | // * untar/untar.c: Add config-header support. |
---|
68 | // |
---|
69 | // Revision 1.4 2002/01/04 18:32:48 joel |
---|
70 | // 2002-01-04 Ralf Corsepius <corsepiu@faw.uni-ulm.de> |
---|
71 | // |
---|
72 | // * mw-fb/mw_uid.c: Apply rtems_set_errno_and_return_minus_one. |
---|
73 | // |
---|
74 | // Revision 1.3 2000/11/30 14:36:46 joel |
---|
75 | // 2000-11-30 Joel Sherrill <joel@OARcorp.com> |
---|
76 | // |
---|
77 | // * mw-fb/mw_uid.c: Removed unnecessary dependency on <bsp.h>. |
---|
78 | // |
---|
79 | // Revision 1.2 2000/08/30 17:12:55 joel |
---|
80 | // 2000-08-30 Joel Sherrill <joel@OARcorp.com> |
---|
81 | // |
---|
82 | // * Many files: Moved posix/include/rtems/posix/seterr.h to |
---|
83 | // score/include/rtems/seterr.h so it would be available within |
---|
84 | // all APIs. |
---|
85 | // |
---|
86 | // Revision 1.1 2000/08/30 08:21:24 joel |
---|
87 | // 2000-08-26 Rosimildo da Silva <rdasilva@connecttel.com> |
---|
88 | // |
---|
89 | // * Added generic Micro FrameBuffer interface for MicroWindows. |
---|
90 | // This interface allows MicroWindows to under RTEMS. A sample |
---|
91 | // driver has been developed for the pc386 BSP. See |
---|
92 | // pc386/fb_vga.c as a sample. |
---|
93 | // * Added Uniform Input Device interface for MicroWindows. |
---|
94 | // See PC386 bsp for sample drivers for mouse and keyboard (console). |
---|
95 | // * mw-bf: New directory. |
---|
96 | // * Makefile.am, configure.in, wrapup/Makefile.am: Account for mw-fb. |
---|
97 | // * mw-fb/Makefile.am: New file. |
---|
98 | // * mw-fb/mw_fb.c: New file. |
---|
99 | // * mw-fb/mw_fb.h: New file. |
---|
100 | // * mw-fb/mw_uid.c: New file. |
---|
101 | // * mw-fb/mw_uid.h: New file. |
---|
102 | // |
---|
103 | // |
---|
104 | ///////////////////////////////////////////////////////////////////////////// |
---|
105 | */ |
---|
106 | |
---|
107 | #ifdef HAVE_CONFIG_H |
---|
108 | #include "config.h" |
---|
109 | #endif |
---|
110 | |
---|
111 | #include <stdio.h> |
---|
112 | #include <fcntl.h> |
---|
113 | #include <sys/ioctl.h> |
---|
114 | #include <errno.h> |
---|
115 | #include <rtems.h> |
---|
116 | |
---|
117 | #include <rtems/mw_uid.h> |
---|
118 | #include <rtems/seterr.h> |
---|
119 | |
---|
120 | static rtems_id queue_id = 0; |
---|
121 | static int open_count = 0; |
---|
122 | |
---|
123 | /* |
---|
124 | #define MW_DEBUG_ON 1 |
---|
125 | */ |
---|
126 | |
---|
127 | /* open a message queue with the kernel */ |
---|
128 | int uid_open_queue( const char *q_name, int flags, size_t max_msgs ) |
---|
129 | { |
---|
130 | static rtems_name queue_name; |
---|
131 | |
---|
132 | /* |
---|
133 | * For the first device calling this function we would create the queue. |
---|
134 | * It is assumed that this call is done at initialization, and no concerns |
---|
135 | * regarding multi-threading is taken in consideration here. |
---|
136 | */ |
---|
137 | if( !open_count ) |
---|
138 | { |
---|
139 | rtems_status_code status; |
---|
140 | queue_name = rtems_build_name( q_name[0], |
---|
141 | q_name[1], |
---|
142 | q_name[2], |
---|
143 | q_name[3] ); |
---|
144 | status = rtems_message_queue_create( queue_name, |
---|
145 | max_msgs, |
---|
146 | sizeof( struct MW_UID_MESSAGE ), |
---|
147 | RTEMS_FIFO | RTEMS_LOCAL, |
---|
148 | &queue_id ); |
---|
149 | if( status != RTEMS_SUCCESSFUL ) |
---|
150 | { |
---|
151 | #ifdef MW_DEBUG_ON |
---|
152 | printk( "UID_Queue: error creating queue: %d\n", status ); |
---|
153 | #endif |
---|
154 | return -1; |
---|
155 | } |
---|
156 | #ifdef MW_DEBUG_ON |
---|
157 | printk( "UID_Queue: id=%X\n", queue_id ); |
---|
158 | #endif |
---|
159 | } |
---|
160 | open_count++; |
---|
161 | return 0; |
---|
162 | } |
---|
163 | |
---|
164 | |
---|
165 | /* close message queue */ |
---|
166 | int uid_close_queue( void ) |
---|
167 | { |
---|
168 | if( open_count == 1 ) |
---|
169 | { |
---|
170 | rtems_message_queue_delete( queue_id ); |
---|
171 | queue_id = 0; |
---|
172 | } |
---|
173 | open_count--; |
---|
174 | return 0; |
---|
175 | } |
---|
176 | |
---|
177 | /* reads for a message from the device */ |
---|
178 | int uid_read_message( struct MW_UID_MESSAGE *m, unsigned long timeout ) |
---|
179 | { |
---|
180 | rtems_status_code status; |
---|
181 | uint32_t size = 0; |
---|
182 | unsigned long micro_secs = timeout*1000; |
---|
183 | int wait = ( timeout != 0 ); |
---|
184 | |
---|
185 | status = rtems_message_queue_receive( queue_id, |
---|
186 | (void*)m, |
---|
187 | &size, |
---|
188 | wait ? RTEMS_WAIT : RTEMS_NO_WAIT, |
---|
189 | TOD_MICROSECONDS_TO_TICKS(micro_secs ) ); |
---|
190 | |
---|
191 | if( status == RTEMS_SUCCESSFUL ) |
---|
192 | { |
---|
193 | return size; |
---|
194 | } |
---|
195 | else if( ( status == RTEMS_UNSATISFIED ) || ( status == RTEMS_TIMEOUT ) ) |
---|
196 | { |
---|
197 | /* this macro returns -1 */ |
---|
198 | rtems_set_errno_and_return_minus_one( ETIMEDOUT ); |
---|
199 | } |
---|
200 | /* Here we have one error condition */ |
---|
201 | #ifdef MW_DEBUG_ON |
---|
202 | printk( "UID_Queue: error reading queue: %d\n", status ); |
---|
203 | #endif |
---|
204 | return -1; |
---|
205 | } |
---|
206 | |
---|
207 | |
---|
208 | /* |
---|
209 | * add a message to the queue of events. This method cna be used to |
---|
210 | * simulate hardware events, and it can be very handy during development |
---|
211 | * a new interface. |
---|
212 | */ |
---|
213 | int uid_send_message( struct MW_UID_MESSAGE *m ) |
---|
214 | { |
---|
215 | rtems_status_code status; |
---|
216 | status = rtems_message_queue_send( queue_id, ( void * )m, |
---|
217 | sizeof( struct MW_UID_MESSAGE ) ); |
---|
218 | return status == RTEMS_SUCCESSFUL ? 0 : -1; |
---|
219 | } |
---|
220 | |
---|
221 | /* |
---|
222 | * register the device to insert events to the message |
---|
223 | * queue named as the value passed in q_name |
---|
224 | */ |
---|
225 | int uid_register_device( int fd, const char *q_name ) |
---|
226 | { |
---|
227 | return ioctl( fd, MW_UID_REGISTER_DEVICE, q_name ); |
---|
228 | } |
---|
229 | |
---|
230 | /* tell this device to stop adding events to the queue */ |
---|
231 | int uid_unregister_device( int fd ) |
---|
232 | { |
---|
233 | return ioctl( fd, MW_UID_UNREGISTER_DEVICE, NULL ); |
---|
234 | } |
---|
235 | |
---|
236 | /* set the keyboard */ |
---|
237 | int uid_set_kbd_mode( int fd, int mode, int *old_mode ) |
---|
238 | { |
---|
239 | if (ioctl( fd, MV_KDGKBMODE, old_mode) < 0) |
---|
240 | { |
---|
241 | return -1; |
---|
242 | } |
---|
243 | if (ioctl(fd, MV_KDSKBMODE, mode ) < 0 ) |
---|
244 | { |
---|
245 | return -1; |
---|
246 | } |
---|
247 | return 0; |
---|
248 | } |
---|