Changeset ac307b2 in mainline for uspace/srv/hid/input/port/chardev.c


Ignore:
Timestamp:
2017-11-25T11:12:23Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
98cb5e0d
Parents:
f571ca49 (diff), 0851a3d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into callcaps

File:
1 edited

Legend:

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

    rf571ca49 rac307b2  
    3535 */
    3636
    37 #include <ipc/char.h>
    3837#include <async.h>
     38#include <errno.h>
     39#include <fibril.h>
     40#include <io/chardev.h>
    3941#include <loc.h>
    40 #include <errno.h>
    4142#include <stdio.h>
    4243#include "../input.h"
     
    4445#include "../kbd.h"
    4546
    46 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);
     47static int kbd_port_fibril(void *);
    4748
    4849static int chardev_port_init(kbd_dev_t *);
    49 static void chardev_port_write(uint8_t data);
     50static void chardev_port_write(uint8_t);
    5051
    5152kbd_port_ops_t chardev_port = {
     
    5657static kbd_dev_t *kbd_dev;
    5758static async_sess_t *dev_sess;
     59static chardev_t *chardev;
    5860
    5961/** List of devices to try connecting to. */
     
    7072{
    7173        service_id_t service_id;
    72         async_exch_t *exch;
    7374        unsigned int i;
     75        fid_t fid;
    7476        int rc;
    7577       
     
    9698        }
    9799       
    98         exch = async_exchange_begin(dev_sess);
    99         if (exch == NULL) {
    100                 printf("%s: Failed starting exchange with device\n", NAME);
     100        rc = chardev_open(dev_sess, &chardev);
     101        if (rc != EOK) {
     102                printf("%s: Failed opening character device\n", NAME);
    101103                async_hangup(dev_sess);
    102104                return ENOMEM;
    103105        }
    104106       
    105         port_id_t port;
    106         rc = async_create_callback_port(exch, INTERFACE_CHAR_CB, 0, 0,
    107             kbd_port_events, NULL, &port);
    108        
    109         async_exchange_end(exch);
    110        
    111         if (rc != 0) {
    112                 printf("%s: Failed to create callback from device\n", NAME);
     107        fid = fibril_create(kbd_port_fibril, NULL);
     108        if (fid == 0) {
     109                printf("%s: Failed creating fibril\n", NAME);
     110                chardev_close(chardev);
    113111                async_hangup(dev_sess);
    114                 return -1;
     112                return ENOMEM;
    115113        }
     114
     115        fibril_add_ready(fid);
    116116       
    117117        printf("%s: Found input device '%s'\n", NAME, in_devs[i]);
     
    121121static void chardev_port_write(uint8_t data)
    122122{
    123         async_exch_t *exch = async_exchange_begin(dev_sess);
    124         if (exch == NULL) {
    125                 printf("%s: Failed starting exchange with device\n", NAME);
     123        int rc;
     124        size_t nwr;
     125
     126        rc = chardev_write(chardev, &data, sizeof(data), &nwr);
     127        if (rc != EOK || nwr != sizeof(data)) {
     128                printf("%s: Failed writing to character device\n", NAME);
    126129                return;
    127         }
    128 
    129         async_msg_1(exch, CHAR_WRITE_BYTE, data);
    130         async_exchange_end(exch);
    131 }
    132 
    133 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    134 {
    135         /* Ignore parameters, the connection is already opened */
    136         while (true) {
    137 
    138                 ipc_call_t call;
    139                 ipc_callid_t callid = async_get_call(&call);
    140                
    141                 if (!IPC_GET_IMETHOD(call)) {
    142                         /* TODO: Handle hangup */
    143                         return;
    144                 }
    145 
    146                 int retval = EOK;
    147 
    148                 switch (IPC_GET_IMETHOD(call)) {
    149                 case CHAR_NOTIF_BYTE:
    150                         kbd_push_data(kbd_dev, IPC_GET_ARG1(call));
    151                         break;
    152                 default:
    153                         retval = ENOENT;
    154                 }
    155                 async_answer_0(callid, retval);
    156130        }
    157131}
    158132
     133static int kbd_port_fibril(void *arg)
     134{
     135        int rc;
     136        size_t nread;
     137        uint8_t b;
     138
     139        while (true) {
     140                rc = chardev_read(chardev, &b, sizeof(b), &nread);
     141                if (rc != EOK || nread != sizeof(b)) {
     142                        printf("%s: Error reading data", NAME);
     143                        continue;
     144                }
     145
     146                kbd_push_data(kbd_dev, b);
     147        }
     148
     149        return 0;
     150}
    159151
    160152/**
Note: See TracChangeset for help on using the changeset viewer.