source: rtems/cpukit/libmisc/mw-fb/mw_uid.c @ 130291f

4.104.114.84.95
Last change on this file since 130291f was 4a14b7be, checked in by Joel Sherrill <joel.sherrill@…>, on 11/30/00 at 14:36:46

2000-11-30 Joel Sherrill <joel@…>

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