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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [kbd/] [arm/] [ipaq/] [current/] [src/] [ipaq_kbd.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      ipaq_kbd.c
4
//
5
//      Keypad driver for the Compaq iPAQ
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 Free Software Foundation, 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      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    gthomas
43
// Contributors: gthomas
44
// Date:         2001-03-15
45
// Purpose:      
46
// Description:  Keypad driver for Compaq IPAQ
47
//
48
//####DESCRIPTIONEND####
49
//
50
//==========================================================================
51
 
52
 
53
#include <pkgconf/devs_kbd_ipaq.h>
54
 
55
#include <cyg/kernel/kapi.h>
56
#include <cyg/hal/hal_io.h>
57
#include <cyg/hal/hal_arch.h>
58
#include <cyg/hal/drv_api.h>
59
#include <cyg/hal/hal_intr.h>
60
#include <cyg/hal/hal_sa11x0.h>
61
#include <cyg/hal/ipaq.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
#include <cyg/hal/atmel_support.h>
71
 
72
// Functions in this module
73
 
74
static Cyg_ErrNo kbd_read(cyg_io_handle_t handle,
75
                          void *buffer,
76
                          cyg_uint32 *len);
77
static cyg_bool  kbd_select(cyg_io_handle_t handle,
78
                            cyg_uint32 which,
79
                            cyg_addrword_t info);
80
static Cyg_ErrNo kbd_set_config(cyg_io_handle_t handle,
81
                                cyg_uint32 key,
82
                                const void *buffer,
83
                                cyg_uint32 *len);
84
static Cyg_ErrNo kbd_get_config(cyg_io_handle_t handle,
85
                                cyg_uint32 key,
86
                                void *buffer,
87
                                cyg_uint32 *len);
88
static bool      kbd_init(struct cyg_devtab_entry *tab);
89
static Cyg_ErrNo kbd_lookup(struct cyg_devtab_entry **tab,
90
                            struct cyg_devtab_entry *st,
91
                            const char *name);
92
 
93
CHAR_DEVIO_TABLE(ipaq_kbd_handlers,
94
                 NULL,                                   // Unsupported write() function
95
                 kbd_read,
96
                 kbd_select,
97
                 kbd_get_config,
98
                 kbd_set_config);
99
 
100
CHAR_DEVTAB_ENTRY(ipaq_kbd_device,
101
                  CYGDAT_DEVS_KBD_IPAQ_NAME,
102
                  NULL,                                   // Base device name
103
                  &ipaq_kbd_handlers,
104
                  kbd_init,
105
                  kbd_lookup,
106
                  NULL);                                  // Private data pointer
107
 
108
#define MAX_EVENTS CYGNUM_DEVS_KBD_IPAQ_EVENT_BUFFER_SIZE
109
static int   num_events;
110
static int   _event_put, _event_get;
111
static unsigned char _events[MAX_EVENTS];
112
 
113
static bool _is_open = false;
114
 
115
//
116
// Note: this routine is called from the Atmel processing DSR
117
//
118
static void
119
kbd_handler(atmel_pkt *pkt)
120
{
121
    unsigned char *dp = pkt->data;
122
    unsigned char *ev;
123
 
124
//    diag_printf("KBD = %x\n", dp[1]);
125
    if (num_events < MAX_EVENTS) {
126
        num_events++;
127
        ev = &_events[_event_put++];
128
        if (_event_put == MAX_EVENTS) {
129
            _event_put = 0;
130
        }
131
        *ev = dp[1];
132
        if (kbd_select_active) {
133
            kbd_select_active = false;
134
            cyg_selwakeup(&kbd_select_info);
135
        }
136
    }
137
}
138
 
139
static Cyg_ErrNo
140
kbd_read(cyg_io_handle_t handle,
141
         void *buffer,
142
         cyg_uint32 *len)
143
{
144
    unsigned char *ev;
145
    int tot = *len;
146
    unsigned char *bp = (unsigned char *)buffer;
147
 
148
    cyg_scheduler_lock();  // Prevent interaction with DSR code
149
    while (tot >= sizeof(*ev)) {
150
        if (num_events > 0) {
151
            ev = &_events[_event_get++];
152
            if (_event_get == MAX_EVENTS) {
153
                _event_get = 0;
154
            }
155
            memcpy(bp, ev, sizeof(*ev));
156
            bp += sizeof(*ev);
157
            tot -= sizeof(*ev);
158
            num_events--;
159
        } else {
160
            break;  // No more events
161
        }
162
    }
163
    cyg_scheduler_unlock(); // Allow DSRs again
164
    *len -= tot;
165
    return ENOERR;
166
}
167
 
168
static cyg_bool
169
kbd_select(cyg_io_handle_t handle,
170
           cyg_uint32 which,
171
           cyg_addrword_t info)
172
{
173
    if (which == CYG_FREAD) {
174
        cyg_scheduler_lock();  // Prevent interaction with DSR code
175
        if (num_events > 0) {
176
            cyg_scheduler_unlock();  // Reallow interaction with DSR code
177
            return true;
178
        }
179
        if (!kbd_select_active) {
180
            kbd_select_active = true;
181
            cyg_selrecord(info, &kbd_select_info);
182
        }
183
        cyg_scheduler_unlock();  // Reallow interaction with DSR code
184
    }
185
    return false;
186
}
187
 
188
static Cyg_ErrNo
189
kbd_set_config(cyg_io_handle_t handle,
190
               cyg_uint32 key,
191
               const void *buffer,
192
               cyg_uint32 *len)
193
{
194
    return EINVAL;
195
}
196
 
197
static Cyg_ErrNo
198
kbd_get_config(cyg_io_handle_t handle,
199
               cyg_uint32 key,
200
               void *buffer,
201
               cyg_uint32 *len)
202
{
203
    return EINVAL;
204
}
205
 
206
static bool
207
kbd_init(struct cyg_devtab_entry *tab)
208
{
209
    cyg_selinit(&kbd_select_info);
210
    return true;
211
}
212
 
213
static Cyg_ErrNo
214
kbd_lookup(struct cyg_devtab_entry **tab,
215
           struct cyg_devtab_entry *st,
216
           const char *name)
217
{
218
    if (!_is_open) {
219
        _is_open = true;
220
        atmel_register(ATMEL_CMD_KEYBD, kbd_handler);
221
        atmel_interrupt_mode(true);
222
    }
223
    return ENOERR;
224
}

powered by: WebSVN 2.1.0

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