Subversion Repositories HelenOS

Compare Revisions

Regard whitespace Rev 1343 → Rev 1344

/uspace/trunk/kbd/include/key_buffer.h
34,6 → 34,7
void key_buffer_free(void);
void key_buffer_init(void);
int key_buffer_available(void);
int key_buffer_empty(void);
void key_buffer_push(char key);
int key_buffer_pop(char *c);
 
/uspace/trunk/kbd/generic/kbd.c
53,8 → 53,9
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");
82,14 → 83,18
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);
retval = 0;
break;
case IPC_M_CONNECT_TO_ME:
98,6 → 103,7
break;
case IPC_M_CONNECT_ME_TO:
// printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call));
/* Only one connected client allowed */
if (connected) {
retval = ELIMIT;
} else {
107,14 → 113,24
break;
case IPC_M_INTERRUPT:
if (connected) {
/* recode scancode and store it into key buffer */
kbd_arch_process(IPC_GET_ARG2(call));
}
//printf("%s: GOT INTERRUPT: %c\n", NAME, IPC_GET_ARG2(call));
if (!callers_counter)
 
/* 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--;
if (!key_buffer_pop((char *)&arg1)) {
printf("%s: KeyBuffer empty but it should not be.\n");
break;
/* Small trick - interrupt does not need answer so we can change callid to caller awaiting key */
callers_counter--;
callid = fifo_pop(callers_buffer);
}
ipc_answer_fast(fifo_pop(callers_buffer), retval, arg1, arg2);
}
}
break;
case KBD_GETCHAR:
// printf("%s: Getchar: ", NAME);
retval = 0;
137,9 → 153,10
retval = ENOENT;
break;
}
 
if (! (callid & IPC_CALLID_NOTIFICATION)) {
// printf("%s: Answering\n", NAME);
ipc_answer_fast(callid, retval, arg1, arg2);
}
}
}
 
/uspace/trunk/kbd/generic/key_buffer.c
29,11 → 29,13
#include <key_buffer.h>
#include <fifo.h>
 
#define KBD_BUFFER_SIZE 128
#define KBD_BUFFER_SIZE 128 /**< Size of buffer for pressed keys */
 
FIFO_INITIALIZE_STATIC(buffer, char, KBD_BUFFER_SIZE);
fifo_count_t buffer_items;
FIFO_INITIALIZE_STATIC(buffer, char, KBD_BUFFER_SIZE); /**< Fifo for storing pressed keys */
fifo_count_t buffer_items; /**< Counter of used items for prevent fifo overflow */
 
/** Clear key buffer.
*/
void key_buffer_free(void)
{
buffer_items = 0;
40,12 → 42,17
buffer.head = buffer.tail = 0;
}
 
/** Key buffer initialization.
*
*/
void key_buffer_init(void)
{
key_buffer_free();
}
 
/**
/** Get free space in buffer.
* This function is useful for processing some scancodes that are translated
* to more than one character.
* @return empty buffer space
*/
int key_buffer_available(void)
53,9 → 60,20
return KBD_BUFFER_SIZE - buffer_items;
}
 
/**
* @return nonzero, if buffer is not empty.
*/
int key_buffer_empty(void)
{
return (buffer_items == 0);
}
 
/** Push key to key buffer.
* If buffer is full, character is ignored.
* @param key code of stored key
*/
void key_buffer_push(char key)
{
/* TODO: somebody may wait for key */
if (buffer_items < KBD_BUFFER_SIZE) {
fifo_push(buffer, key);
buffer_items++;
63,7 → 81,7
}
 
/** Pop character from buffer.
* @param c
* @param c pointer to space where to store character from buffer.
* @return zero on empty buffer, nonzero else
*/
int key_buffer_pop(char *c)