source: mainline/uspace/srv/hid/char_mouse/chardev.c@ 41811af

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 41811af was 79ae36dd, checked in by Martin Decky <martin@…>, 14 years ago

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.)
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * Copyright (c) 2009 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup mouse
30 * @{
31 */
32/** @file
33 * @brief
34 */
35
36#include <ipc/char.h>
37#include <async.h>
38#include <async_obsolete.h>
39#include <vfs/vfs.h>
40#include <fcntl.h>
41#include <errno.h>
42#include <devmap.h>
43#include <devmap_obsolete.h>
44#include <char_mouse.h>
45#include <mouse_port.h>
46
47static void chardev_events(ipc_callid_t iid, ipc_call_t *icall);
48
49static int dev_phone;
50
51#define NAME "char_mouse"
52
53int mouse_port_init(void)
54{
55 devmap_handle_t handle;
56 int rc = devmap_device_get_handle("char/ps2b", &handle,
57 IPC_FLAG_BLOCKING);
58
59 if (rc != EOK) {
60 printf("%s: Failed resolving PS/2\n", NAME);
61 return rc;
62 }
63
64 dev_phone = devmap_obsolete_device_connect(handle, IPC_FLAG_BLOCKING);
65 if (dev_phone < 0) {
66 printf("%s: Failed connecting to PS/2\n", NAME);
67 return ENOENT;
68 }
69
70 /* NB: The callback connection is slotted for removal */
71 if (async_obsolete_connect_to_me(dev_phone, 0, 0, 0, chardev_events) != 0) {
72 printf(NAME ": Failed to create callback from device\n");
73 return false;
74 }
75
76 return 0;
77}
78
79void mouse_port_yield(void)
80{
81}
82
83void mouse_port_reclaim(void)
84{
85}
86
87void mouse_port_write(uint8_t data)
88{
89 async_obsolete_msg_1(dev_phone, CHAR_WRITE_BYTE, data);
90}
91
92static void chardev_events(ipc_callid_t iid, ipc_call_t *icall)
93{
94 /* Ignore parameters, the connection is already opened */
95 while (true) {
96
97 ipc_call_t call;
98 ipc_callid_t callid = async_get_call(&call);
99
100 int retval;
101
102 if (!IPC_GET_IMETHOD(call)) {
103 /* TODO: Handle hangup */
104 return;
105 }
106
107 switch (IPC_GET_IMETHOD(call)) {
108 case IPC_FIRST_USER_METHOD:
109 mouse_handle_byte(IPC_GET_ARG1(call));
110 break;
111 default:
112 retval = ENOENT;
113 }
114 async_answer_0(callid, retval);
115 }
116}
117
118/**
119 * @}
120 */
Note: See TracBrowser for help on using the repository browser.