source: rtems/cpukit/libmisc/mw-fb/mw_uid.c @ 2cc9367

4.104.114.84.95
Last change on this file since 2cc9367 was 550c3df7, checked in by Ralf Corsepius <ralf.corsepius@…>, on Jul 8, 2003 at 8:39:16 AM

2003-07-08 Ralf Corsepius <corsepiu@…>

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