source: rtems/cpukit/libmisc/mw-fb/mw_uid.c @ 152b1e3

4.104.114.84.95
Last change on this file since 152b1e3 was 152b1e3, checked in by Joel Sherrill <joel.sherrill@…>, on 08/30/00 at 08:21:24

2000-08-26 Rosimildo da Silva <rdasilva@…>

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