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.1 2000/08/30 08:21:24 joel |
---|
17 | // 2000-08-26 Rosimildo da Silva <rdasilva@connecttel.com> |
---|
18 | // |
---|
19 | // * Added generic Micro FrameBuffer interface for MicroWindows. |
---|
20 | // This interface allows MicroWindows to under RTEMS. A sample |
---|
21 | // driver has been developed for the pc386 BSP. See |
---|
22 | // pc386/fb_vga.c as a sample. |
---|
23 | // * Added Uniform Input Device interface for MicroWindows. |
---|
24 | // See PC386 bsp for sample drivers for mouse and keyboard (console). |
---|
25 | // * mw-bf: New directory. |
---|
26 | // * Makefile.am, configure.in, wrapup/Makefile.am: Account for mw-fb. |
---|
27 | // * mw-fb/Makefile.am: New file. |
---|
28 | // * mw-fb/mw_fb.c: New file. |
---|
29 | // * mw-fb/mw_fb.h: New file. |
---|
30 | // * mw-fb/mw_uid.c: New file. |
---|
31 | // * mw-fb/mw_uid.h: New file. |
---|
32 | // |
---|
33 | // |
---|
34 | ///////////////////////////////////////////////////////////////////////////// |
---|
35 | */ |
---|
36 | #include <stdio.h> |
---|
37 | #include <fcntl.h> |
---|
38 | #include <sys/ioctl.h> |
---|
39 | #include <errno.h> |
---|
40 | #include <rtems.h> |
---|
41 | #include <bsp.h> |
---|
42 | |
---|
43 | #include <rtems/mw_uid.h> |
---|
44 | #include <rtems/seterr.h> |
---|
45 | |
---|
46 | static rtems_id queue_id = 0; |
---|
47 | static int open_count = 0; |
---|
48 | |
---|
49 | /* |
---|
50 | #define MW_DEBUG_ON 1 |
---|
51 | */ |
---|
52 | |
---|
53 | /* open a message queue with the kernel */ |
---|
54 | int uid_open_queue( const char *q_name, int flags, size_t max_msgs ) |
---|
55 | { |
---|
56 | static rtems_name queue_name; |
---|
57 | |
---|
58 | /* |
---|
59 | * For the first device calling this function we would create the queue. |
---|
60 | * It is assumed that this call is done at initialization, and no concerns |
---|
61 | * regarding multi-threading is taken in consideration here. |
---|
62 | */ |
---|
63 | if( !open_count ) |
---|
64 | { |
---|
65 | rtems_status_code status; |
---|
66 | queue_name = rtems_build_name( q_name[0], |
---|
67 | q_name[1], |
---|
68 | q_name[2], |
---|
69 | q_name[3] ); |
---|
70 | status = rtems_message_queue_create( queue_name, |
---|
71 | max_msgs, |
---|
72 | sizeof( struct MW_UID_MESSAGE ), |
---|
73 | RTEMS_FIFO | RTEMS_LOCAL, |
---|
74 | &queue_id ); |
---|
75 | if( status != RTEMS_SUCCESSFUL ) |
---|
76 | { |
---|
77 | #ifdef MW_DEBUG_ON |
---|
78 | printk( "UID_Queue: error creating queue: %d\n", status ); |
---|
79 | #endif |
---|
80 | return -1; |
---|
81 | } |
---|
82 | #ifdef MW_DEBUG_ON |
---|
83 | printk( "UID_Queue: id=%X\n", queue_id ); |
---|
84 | #endif |
---|
85 | } |
---|
86 | open_count++; |
---|
87 | return 0; |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | /* close message queue */ |
---|
92 | int uid_close_queue( void ) |
---|
93 | { |
---|
94 | if( open_count == 1 ) |
---|
95 | { |
---|
96 | rtems_message_queue_delete( queue_id ); |
---|
97 | queue_id = 0; |
---|
98 | } |
---|
99 | open_count--; |
---|
100 | return 0; |
---|
101 | } |
---|
102 | |
---|
103 | /* reads for a message from the device */ |
---|
104 | int uid_read_message( struct MW_UID_MESSAGE *m, unsigned long timeout ) |
---|
105 | { |
---|
106 | rtems_status_code status; |
---|
107 | rtems_unsigned32 size = 0; |
---|
108 | unsigned long micro_secs = timeout*1000; |
---|
109 | int wait = ( timeout != 0 ); |
---|
110 | |
---|
111 | status = rtems_message_queue_receive( queue_id, |
---|
112 | (void*)m, |
---|
113 | &size, |
---|
114 | wait ? RTEMS_WAIT : RTEMS_NO_WAIT, |
---|
115 | TOD_MICROSECONDS_TO_TICKS(micro_secs ) ); |
---|
116 | |
---|
117 | if( status == RTEMS_SUCCESSFUL ) |
---|
118 | { |
---|
119 | return size; |
---|
120 | } |
---|
121 | else if( ( status == RTEMS_UNSATISFIED ) || ( status == RTEMS_TIMEOUT ) ) |
---|
122 | { |
---|
123 | /* this macro returns -1 */ |
---|
124 | set_errno_and_return_minus_one( ETIMEDOUT ); |
---|
125 | } |
---|
126 | /* Here we have one error condition */ |
---|
127 | #ifdef MW_DEBUG_ON |
---|
128 | printk( "UID_Queue: error reading queue: %d\n", status ); |
---|
129 | #endif |
---|
130 | return -1; |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | /* |
---|
135 | * add a message to the queue of events. This method cna be used to |
---|
136 | * simulate hardware events, and it can be very handy during development |
---|
137 | * a new interface. |
---|
138 | */ |
---|
139 | int uid_send_message( struct MW_UID_MESSAGE *m ) |
---|
140 | { |
---|
141 | rtems_status_code status; |
---|
142 | status = rtems_message_queue_send( queue_id, ( void * )m, |
---|
143 | sizeof( struct MW_UID_MESSAGE ) ); |
---|
144 | return status == RTEMS_SUCCESSFUL ? 0 : -1; |
---|
145 | } |
---|
146 | |
---|
147 | /* |
---|
148 | * register the device to insert events to the message |
---|
149 | * queue named as the value passed in q_name |
---|
150 | */ |
---|
151 | int uid_register_device( int fd, const char *q_name ) |
---|
152 | { |
---|
153 | return ioctl( fd, MW_UID_REGISTER_DEVICE, q_name ); |
---|
154 | } |
---|
155 | |
---|
156 | /* tell this device to stop adding events to the queue */ |
---|
157 | int uid_unregister_device( int fd ) |
---|
158 | { |
---|
159 | return ioctl( fd, MW_UID_UNREGISTER_DEVICE, NULL ); |
---|
160 | } |
---|
161 | |
---|
162 | /* set the keyboard */ |
---|
163 | int uid_set_kbd_mode( int fd, int mode, int *old_mode ) |
---|
164 | { |
---|
165 | if (ioctl( fd, MV_KDGKBMODE, old_mode) < 0) |
---|
166 | { |
---|
167 | return -1; |
---|
168 | } |
---|
169 | if (ioctl(fd, MV_KDSKBMODE, mode ) < 0 ) |
---|
170 | { |
---|
171 | return -1; |
---|
172 | } |
---|
173 | return 0; |
---|
174 | } |
---|