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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [devs/] [kbd/] [arm/] [aaed2000/] [v2_0/] [src/] [aaed2000_kbd.c] - Blame information for rev 420

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      aaed2000_kbd.c
4
//
5
//      Keyboard driver for the Agilent AAED2000
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):    gthomas
44
// Contributors: gthomas
45
// Date:         2002-03-11
46
// Purpose:      
47
// Description:  Keyboardd driver for Agilent AAED2000
48
//
49
//####DESCRIPTIONEND####
50
//
51
//==========================================================================
52
 
53
 
54
#include <pkgconf/devs_kbd_aaed2000.h>
55
 
56
#include <cyg/kernel/kapi.h>
57
#include <cyg/hal/hal_io.h>
58
#include <cyg/hal/hal_arch.h>
59
#include <cyg/hal/drv_api.h>
60
#include <cyg/hal/hal_intr.h>
61
#include <cyg/hal/aaed2000.h>
62
#include <cyg/infra/cyg_type.h>
63
#include <cyg/infra/cyg_ass.h>
64
 
65
#include <cyg/fileio/fileio.h>  // For select() functionality
66
static cyg_selinfo      kbd_select_info;
67
static cyg_bool         kbd_select_active;
68
 
69
#include <cyg/io/devtab.h>
70
 
71
// Functions in this module
72
 
73
static Cyg_ErrNo kbd_read(cyg_io_handle_t handle,
74
                          void *buffer,
75
                          cyg_uint32 *len);
76
static cyg_bool  kbd_select(cyg_io_handle_t handle,
77
                            cyg_uint32 which,
78
                            cyg_addrword_t info);
79
static Cyg_ErrNo kbd_set_config(cyg_io_handle_t handle,
80
                                cyg_uint32 key,
81
                                const void *buffer,
82
                                cyg_uint32 *len);
83
static Cyg_ErrNo kbd_get_config(cyg_io_handle_t handle,
84
                                cyg_uint32 key,
85
                                void *buffer,
86
                                cyg_uint32 *len);
87
static bool      kbd_init(struct cyg_devtab_entry *tab);
88
static Cyg_ErrNo kbd_lookup(struct cyg_devtab_entry **tab,
89
                            struct cyg_devtab_entry *st,
90
                            const char *name);
91
 
92
CHAR_DEVIO_TABLE(aaed2000_kbd_handlers,
93
                 NULL,                                   // Unsupported write() function
94
                 kbd_read,
95
                 kbd_select,
96
                 kbd_get_config,
97
                 kbd_set_config);
98
 
99
CHAR_DEVTAB_ENTRY(aaed2000_kbd_device,
100
                  CYGDAT_DEVS_KBD_AAED2000_NAME,
101
                  NULL,                                   // Base device name
102
                  &aaed2000_kbd_handlers,
103
                  kbd_init,
104
                  kbd_lookup,
105
                  NULL);                                  // Private data pointer
106
 
107
#define MAX_EVENTS CYGNUM_DEVS_KBD_AAED2000_EVENT_BUFFER_SIZE
108
static int   num_events;
109
static int   _event_put, _event_get;
110
static unsigned char _events[MAX_EVENTS];
111
 
112
static bool _is_open = false;
113
 
114
#define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
115
static char kbd_scan_stack[STACK_SIZE];
116
static cyg_thread kbd_scan_thread_data;
117
static cyg_handle_t kbd_scan_thread_handle;
118
#define SCAN_FREQ 20 // Hz
119
//#define SCAN_FREQ 5 // Hz
120
#define SCAN_DELAY ((1000/SCAN_FREQ)/10)
121
 
122
static void
123
kbd_scan(cyg_addrword_t param)
124
{
125
    unsigned char ch;
126
    unsigned char *ev;
127
 
128
    diag_printf("Keyboard scan\n");
129
    while (true) {
130
        cyg_thread_delay(SCAN_DELAY);
131
        if (aaed2000_KeyboardTest()) {
132
            ch = aaed2000_KeyboardGetc();
133
            if (num_events < MAX_EVENTS) {
134
                num_events++;
135
                ev = &_events[_event_put++];
136
                if (_event_put == MAX_EVENTS) {
137
                    _event_put = 0;
138
                }
139
                *ev = ch;
140
                if (kbd_select_active) {
141
                    kbd_select_active = false;
142
                    cyg_selwakeup(&kbd_select_info);
143
                }
144
            }
145
        }
146
    }
147
}
148
 
149
static Cyg_ErrNo
150
kbd_read(cyg_io_handle_t handle,
151
         void *buffer,
152
         cyg_uint32 *len)
153
{
154
    unsigned char *ev;
155
    int tot = *len;
156
    unsigned char *bp = (unsigned char *)buffer;
157
 
158
    cyg_scheduler_lock();  // Prevent interaction with DSR code
159
    while (tot >= sizeof(*ev)) {
160
        if (num_events > 0) {
161
            ev = &_events[_event_get++];
162
            if (_event_get == MAX_EVENTS) {
163
                _event_get = 0;
164
            }
165
            memcpy(bp, ev, sizeof(*ev));
166
            bp += sizeof(*ev);
167
            tot -= sizeof(*ev);
168
            num_events--;
169
        } else {
170
            break;  // No more events
171
        }
172
    }
173
    cyg_scheduler_unlock(); // Allow DSRs again
174
    diag_dump_buf(buffer, tot);
175
    *len -= tot;
176
    return ENOERR;
177
}
178
 
179
static cyg_bool
180
kbd_select(cyg_io_handle_t handle,
181
           cyg_uint32 which,
182
           cyg_addrword_t info)
183
{
184
    if (which == CYG_FREAD) {
185
        cyg_scheduler_lock();  // Prevent interaction with DSR code
186
        if (num_events > 0) {
187
            cyg_scheduler_unlock();  // Reallow interaction with DSR code
188
            return true;
189
        }
190
        if (!kbd_select_active) {
191
            kbd_select_active = true;
192
            cyg_selrecord(info, &kbd_select_info);
193
        }
194
        cyg_scheduler_unlock();  // Reallow interaction with DSR code
195
    }
196
    return false;
197
}
198
 
199
static Cyg_ErrNo
200
kbd_set_config(cyg_io_handle_t handle,
201
               cyg_uint32 key,
202
               const void *buffer,
203
               cyg_uint32 *len)
204
{
205
    return EINVAL;
206
}
207
 
208
static Cyg_ErrNo
209
kbd_get_config(cyg_io_handle_t handle,
210
               cyg_uint32 key,
211
               void *buffer,
212
               cyg_uint32 *len)
213
{
214
    return EINVAL;
215
}
216
 
217
static bool
218
kbd_init(struct cyg_devtab_entry *tab)
219
{
220
    cyg_selinit(&kbd_select_info);
221
    return true;
222
}
223
 
224
static Cyg_ErrNo
225
kbd_lookup(struct cyg_devtab_entry **tab,
226
           struct cyg_devtab_entry *st,
227
           const char *name)
228
{
229
    if (!_is_open) {
230
        _is_open = true;
231
        cyg_thread_create(1,                       // Priority
232
                          kbd_scan,                // entry
233
                          0,                       // entry parameter
234
                          "Keyboard scan",         // Name
235
                          &kbd_scan_stack[0],      // Stack
236
                          STACK_SIZE,              // Size
237
                          &kbd_scan_thread_handle, // Handle
238
                          &kbd_scan_thread_data    // Thread data structure
239
        );
240
        cyg_thread_resume(kbd_scan_thread_handle);    // Start it
241
    }
242
    return ENOERR;
243
}
244
 
245
 
246
 

powered by: WebSVN 2.1.0

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