Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 1444 → Rev 1445

//uspace/trunk/kbd/include/kbd.h
29,7 → 29,7
#ifndef __KBD_H__
#define __KBD_H__
 
#define KBD_GETCHAR 1024
#define KBD_PUSHCHAR 1024
 
#endif
 
//uspace/trunk/kbd/generic/kbd.c
35,29 → 35,24
#include <errno.h>
#include <arch/kbd.h>
#include <kbd.h>
#include <libadt/fifo.h>
#include <key_buffer.h>
#include <libadt/fifo.h>
 
#define NAME "KBD"
 
#define KBD_REQUEST_MAX 32 /**< Maximum requests buffered until keypress */
 
void hello(void *private, int retval, ipc_call_t *data) {
printf("%s: got answer from console with retval %d.\n", NAME, retval);
}
int main(int argc, char **argv)
{
ipc_call_t call;
ipc_callid_t callid;
char connected = 0;
int res;
int c;
ipcarg_t phonead;
int phoneid;
char connected = 0;
ipcarg_t retval, arg1, arg2;
 
/* Counter of unsatisfied calls */
fifo_count_t callers_counter = 0;
/* Fifo with callid's of unsatisfied calls requred for answer */
FIFO_INITIALIZE_STATIC(callers_buffer, ipc_callid_t, KBD_REQUEST_MAX);
 
printf("Uspace kbd service started.\n");
 
/* Initialize arch dependent parts */
82,19 → 77,8
// printf("%s:Call phone=%lX..", NAME, call.in_phone_hash);
switch (IPC_GET_METHOD(call)) {
case IPC_M_PHONE_HUNGUP:
if (connected) {
/* If nobody's connected, clear keybuffer and dont store new keys */
if (--connected == 0) {
callers_counter = 0;
callers_buffer.head = callers_buffer.tail = 0;
key_buffer_free();
}
printf("%s: Phone hung up.\n", NAME);
} else {
printf("%s: Oops, got phone hung up, but nobody connected.\n", NAME);
}
printf("%s: Phone hung up.\n", NAME);
connected = 0;
retval = 0;
break;
case IPC_M_CONNECT_ME_TO:
107,43 → 91,35
connected = 1;
}
break;
case IPC_M_CONNECT_TO_ME:
phoneid = IPC_GET_ARG3(call);
retval = 0;
break;
 
case IPC_M_INTERRUPT:
if (connected) {
/* recode scancode and store it into key buffer */
/* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */
kbd_arch_process(IPC_GET_ARG2(call));
//printf("%s: GOT INTERRUPT: %c\n", NAME, IPC_GET_ARG2(call));
 
//printf("%s: GOT INTERRUPT: %c\n", NAME, key);
 
/* Some callers could awaiting keypress - if its true, we have to send keys to them.
* One interrupt can store more than one key into buffer. */
retval = 0;
arg2 = 0xbeef;
while ((callers_counter) && (!key_buffer_empty())) {
callers_counter--;
 
while (!key_buffer_empty()) {
if (!key_buffer_pop((char *)&arg1)) {
printf("%s: KeyBuffer empty but it should not be.\n");
printf("%s: KeyBuffer is empty but it should not be.\n");
break;
}
ipc_answer_fast(fifo_pop(callers_buffer), retval, arg1, arg2);
/*FIXME: detection of closed connection */
ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, 0, &hello);
}
 
}
printf("%s: Interrupt processed.\n", NAME);
break;
case KBD_GETCHAR:
// printf("%s: Getchar: ", NAME);
retval = 0;
arg1 = 0;
if (!key_buffer_pop((char *)&arg1)) {
if (callers_counter < KBD_REQUEST_MAX) {
callers_counter++;
fifo_push(callers_buffer, callid);
} else {
retval = ELIMIT;
}
continue;
};
arg2 = 0xbeef;
// printf("GetChar return %c\n", arg1);
break;
default:
printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
retval = ENOENT;