Changeset 085bd54 in mainline for kbd/generic/kbd.c


Ignore:
Timestamp:
2006-06-06T15:16:08Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63bb83e
Parents:
d7eafd8
Message:

Revised ipc. Now it is preferrable to use only functions from async.h, they
take care of correct buffering, waiting for answers etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kbd/generic/kbd.c

    rd7eafd8 r085bd54  
    3939#include <libadt/fifo.h>
    4040#include <key_buffer.h>
     41#include <async.h>
    4142
    4243#define NAME "KBD"
     44
     45int cons_connected = 0;
     46int phone2cons = -1;
     47keybuffer_t keybuffer; 
     48
     49static void irq_handler(ipc_callid_t iid, ipc_call_t *call)
     50{
     51        int chr;
     52       
     53        if (cons_connected && phone2cons != -1) {
     54                /* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */
     55                kbd_arch_process(&keybuffer, IPC_GET_ARG2(*call));
     56               
     57                while (!keybuffer_empty(&keybuffer)) {
     58                        if (!keybuffer_pop(&keybuffer, (int *)&chr))
     59                                break;
     60
     61                        async_msg(phone2cons, KBD_PUSHCHAR, chr);
     62                }
     63        }
     64}
     65
     66static void console_connection(ipc_callid_t iid, ipc_call_t *icall)
     67{
     68        ipc_callid_t callid;
     69        ipc_call_t call;
     70        int retval;
     71
     72        if (cons_connected) {
     73                ipc_answer_fast(iid, ELIMIT, 0, 0);
     74                return;
     75        }
     76        cons_connected = 1;
     77        ipc_answer_fast(iid, 0, 0, 0);
     78
     79        while (1) {
     80                callid = async_get_call(&call);
     81                switch (IPC_GET_METHOD(call)) {
     82                case IPC_M_PHONE_HUNGUP:
     83                        cons_connected = 0;
     84                        ipc_hangup(phone2cons);
     85                        phone2cons = -1;
     86                        ipc_answer_fast(callid, 0,0,0);
     87                        return;
     88                case IPC_M_CONNECT_TO_ME:
     89                        if (phone2cons != -1) {
     90                                retval = ELIMIT;
     91                                break;
     92                        }
     93                        phone2cons = IPC_GET_ARG3(call);
     94                        retval = 0;
     95                        break;
     96                }
     97                ipc_answer_fast(callid, retval, 0, 0);
     98        }       
     99}
     100
    43101
    44102int main(int argc, char **argv)
     
    50108        ipcarg_t phoneid;
    51109        char connected = 0;
    52         keybuffer_t keybuffer; 
    53110        ipcarg_t retval, arg1, arg2;
    54        
    55         //open("null",0);
    56         //open("stdout",0);
    57111       
    58112        /* Initialize arch dependent parts */
     
    68122        if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead)) != 0) {
    69123                return -1;
    70         };
    71         while (1) {
    72                 callid = ipc_wait_for_call(&call);
    73                 switch (IPC_GET_METHOD(call)) {
    74                         case IPC_M_PHONE_HUNGUP:
    75                                 connected = 0;
    76                                 retval = 0;
    77                                 break;
    78                         case IPC_M_CONNECT_ME_TO:
    79                                 /* Only one connected client allowed */
    80                                 if (connected) {
    81                                         retval = ELIMIT;
    82                                 } else {
    83                                         retval = 0;
    84                                         connected = 1;
    85                                 }
    86                                 break;
    87                         case IPC_M_CONNECT_TO_ME:
    88                                 phoneid = IPC_GET_ARG3(call);
    89                                 retval = 0;
    90                                 break;
     124        }
    91125
    92                         case IPC_M_INTERRUPT:
    93                                 if (connected) {
    94                                         int chr;
    95                                         /* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */
    96                                         kbd_arch_process(&keybuffer, IPC_GET_ARG2(call));
     126        async_set_client_connection(console_connection);
     127        async_set_interrupt_received(irq_handler);
     128        async_manager();
    97129
    98                                         retval = 0;
    99                                        
    100 
    101                                         while (!keybuffer_empty(&keybuffer)) {
    102                                                 if (!keybuffer_pop(&keybuffer, (int *)&chr)) {
    103                                                         break;
    104                                                 }
    105                                                 {
    106                                                         arg1=chr;
    107                                                         send_call(phoneid, KBD_PUSHCHAR, arg1);
    108                                                 }   
    109                                         }
    110 
    111                                 }
    112                                 break;
    113                         default:
    114                                 retval = ENOENT;
    115                                 break;
    116                 }
    117 
    118                 if (! (callid & IPC_CALLID_NOTIFICATION)) {
    119                         ipc_answer_fast(callid, retval, arg1, arg2);
    120                 }
    121         }
    122130}
    123 
Note: See TracChangeset for help on using the changeset viewer.