OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [libmisc/] [mw-fb/] [mw_uid.c] - Blame information for rev 1026

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
/////////////////////////////////////////////////////////////////////////////
3
// /usr1/CVS/rtems/c/src/libmisc/mw-fb/mw_uid.c,v 1.4 2002/01/04 18:32:48 joel Exp
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
// mw_uid.c,v
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
#include <stdio.h>
54
#include <fcntl.h>
55
#include <sys/ioctl.h>
56
#include <errno.h>
57
#include <rtems.h>
58
 
59
#include <rtems/mw_uid.h>
60
#include <rtems/seterr.h>
61
 
62
static rtems_id   queue_id = 0;
63
static int open_count = 0;
64
 
65
/*
66
#define MW_DEBUG_ON     1
67
*/
68
 
69
/* open a message queue with the kernel */
70
int uid_open_queue( const char *q_name, int flags, size_t max_msgs )
71
{
72
   static rtems_name queue_name;
73
 
74
   /*
75
    * For the first device calling this function we would create the queue.
76
    * It is assumed that this call is done at initialization, and no concerns
77
    * regarding multi-threading is taken in consideration here.
78
    */
79
   if( !open_count )
80
   {
81
      rtems_status_code status;
82
      queue_name = rtems_build_name( q_name[0],
83
                                     q_name[1],
84
                                     q_name[2],
85
                                     q_name[3] );
86
      status = rtems_message_queue_create( queue_name,
87
                                           max_msgs,
88
                                           sizeof( struct MW_UID_MESSAGE ),
89
                                           RTEMS_FIFO | RTEMS_LOCAL,
90
                                           &queue_id );
91
      if( status != RTEMS_SUCCESSFUL )
92
      {
93
#ifdef MW_DEBUG_ON
94
        printk( "UID_Queue: error creating queue: %d\n", status );
95
#endif
96
        return -1;
97
      }
98
#ifdef MW_DEBUG_ON
99
      printk( "UID_Queue: id=%X\n", queue_id );
100
#endif
101
   }
102
   open_count++;
103
   return 0;
104
}
105
 
106
 
107
/* close message queue */
108
int uid_close_queue( void )
109
{
110
  if( open_count == 1 )
111
  {
112
     rtems_message_queue_delete( queue_id );
113
     queue_id = 0;
114
  }
115
  open_count--;
116
  return 0;
117
}
118
 
119
/* reads for a message from the device */
120
int uid_read_message( struct MW_UID_MESSAGE *m, unsigned long timeout )
121
{
122
  rtems_status_code status;
123
  rtems_unsigned32 size = 0;
124
  unsigned long micro_secs = timeout*1000;
125
  int wait = ( timeout != 0 );
126
 
127
  status = rtems_message_queue_receive( queue_id,
128
                                       (void*)m,
129
                                       &size,
130
                                       wait ? RTEMS_WAIT : RTEMS_NO_WAIT,
131
                                       TOD_MICROSECONDS_TO_TICKS(micro_secs ) );
132
 
133
  if( status == RTEMS_SUCCESSFUL )
134
  {
135
     return size;
136
  }
137
  else if( ( status == RTEMS_UNSATISFIED ) || ( status == RTEMS_TIMEOUT ) )
138
  {
139
     /* this macro returns -1 */
140
     rtems_set_errno_and_return_minus_one( ETIMEDOUT );
141
  }
142
  /* Here we have one error condition */
143
#ifdef MW_DEBUG_ON
144
  printk( "UID_Queue: error reading queue: %d\n", status );
145
#endif
146
  return -1;
147
}
148
 
149
 
150
/*
151
 * add a message to the queue of events. This method cna be used to
152
 * simulate hardware events, and it can be very handy during development
153
 * a new interface.
154
 */
155
int uid_send_message( struct MW_UID_MESSAGE *m )
156
{
157
  rtems_status_code status;
158
  status = rtems_message_queue_send( queue_id, ( void * )m,
159
                                    sizeof( struct MW_UID_MESSAGE ) );
160
  return status == RTEMS_SUCCESSFUL ? 0 : -1;
161
}
162
 
163
/*
164
 * register the device to insert events to the message
165
 * queue named as the value passed in q_name
166
 */
167
int uid_register_device( int fd, const char *q_name )
168
{
169
  return ioctl( fd, MW_UID_REGISTER_DEVICE, q_name );
170
}
171
 
172
/* tell this device to stop adding events to the queue */
173
int uid_unregister_device( int fd )
174
{
175
  return ioctl( fd, MW_UID_UNREGISTER_DEVICE, NULL );
176
}
177
 
178
/* set the keyboard */
179
int uid_set_kbd_mode( int fd, int mode, int *old_mode )
180
{
181
   if (ioctl( fd, MV_KDGKBMODE, old_mode) < 0)
182
   {
183
      return -1;
184
   }
185
   if (ioctl(fd, MV_KDSKBMODE, mode ) < 0 )
186
   {
187
      return -1;
188
   }
189
   return 0;
190
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.