Changeset 79ae36dd in mainline for uspace/srv/hid/kbd/port/chardev.c


Ignore:
Timestamp:
2011-06-08T19:01:55Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eff68e
Parents:
764d71e
Message:

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/kbd/port/chardev.c

    r764d71e r79ae36dd  
    3030 * @ingroup kbd
    3131 * @{
    32  */ 
     32 */
    3333/** @file
    3434 * @brief Chardev keyboard port driver.
     
    3737#include <ipc/char.h>
    3838#include <async.h>
     39#include <async_obsolete.h>
    3940#include <kbd_port.h>
    4041#include <kbd.h>
    41 #include <vfs/vfs.h>
    42 #include <sys/stat.h>
    43 #include <fcntl.h>
     42#include <devmap.h>
     43#include <devmap_obsolete.h>
    4444#include <errno.h>
     45#include <stdio.h>
     46
     47#define NAME  "kbd/chardev"
    4548
    4649static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall);
     
    4851static int dev_phone;
    4952
    50 #define NAME "kbd"
    51 
    5253/** List of devices to try connecting to. */
    5354static const char *in_devs[] = {
    54         "/dev/char/ps2a",
    55         "/dev/char/s3c24ser"
     55        "char/ps2a",
     56        "char/s3c24ser"
    5657};
    5758
    58 static const int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);
     59static const unsigned int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);
    5960
    6061int kbd_port_init(void)
    6162{
    62         int input_fd;
    63         int i;
    64 
    65         input_fd = -1;
     63        devmap_handle_t handle;
     64        unsigned int i;
     65        int rc;
     66       
    6667        for (i = 0; i < num_devs; i++) {
    67                 struct stat s;
    68 
    69                 if (stat(in_devs[i], &s) == EOK)
     68                rc = devmap_device_get_handle(in_devs[i], &handle, 0);
     69                if (rc == EOK)
    7070                        break;
    7171        }
    72 
     72       
    7373        if (i >= num_devs) {
    74                 printf(NAME ": Could not find any suitable input device.\n");
     74                printf("%s: Could not find any suitable input device\n", NAME);
    7575                return -1;
    7676        }
    77 
    78         input_fd = open(in_devs[i], O_RDONLY);
    79         if (input_fd < 0) {
    80                 printf(NAME ": failed opening device %s (%d).\n", in_devs[i],
    81                     input_fd);
    82                 return -1;
     77       
     78        dev_phone = devmap_obsolete_device_connect(handle, IPC_FLAG_BLOCKING);
     79        if (dev_phone < 0) {
     80                printf("%s: Failed connecting to device\n", NAME);
     81                return ENOENT;
    8382        }
    84 
    85         dev_phone = fd_phone(input_fd);
    86         if (dev_phone < 0) {
    87                 printf(NAME ": Failed connecting to device\n");
    88                 return -1;
    89         }
    90 
     83       
    9184        /* NB: The callback connection is slotted for removal */
    92         if (async_connect_to_me(dev_phone, 0, 0, 0, kbd_port_events) != 0) {
     85        if (async_obsolete_connect_to_me(dev_phone, 0, 0, 0, kbd_port_events) != 0) {
    9386                printf(NAME ": Failed to create callback from device\n");
    9487                return -1;
     
    108101void kbd_port_write(uint8_t data)
    109102{
    110         async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);
     103        async_obsolete_msg_1(dev_phone, CHAR_WRITE_BYTE, data);
    111104}
    112105
     
    118111                ipc_call_t call;
    119112                ipc_callid_t callid = async_get_call(&call);
     113               
     114                if (!IPC_GET_IMETHOD(call)) {
     115                        /* TODO: Handle hangup */
     116                        return;
     117                }
    120118
    121119                int retval;
    122120
    123121                switch (IPC_GET_IMETHOD(call)) {
    124                 case IPC_M_PHONE_HUNGUP:
    125                         /* TODO: Handle hangup */
    126                         return;
    127122                case CHAR_NOTIF_BYTE:
    128123                        kbd_push_scancode(IPC_GET_ARG1(call));
Note: See TracChangeset for help on using the changeset viewer.