source: rtems/c/src/libmisc/mw-fb/mw_uid.c @ f8a913da

4.104.114.84.95
Last change on this file since f8a913da was f8a913da, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/02 at 18:32:48

2002-01-04 Ralf Corsepius <corsepiu@…>

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