00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include <ipc/dev_iface.h>
00036 #include <device/char_dev.h>
00037 #include <errno.h>
00038 #include <async.h>
00039 #include <malloc.h>
00040 #include <stdio.h>
00041
00056 static ssize_t char_dev_rw(int dev_phone, void *buf, size_t size, bool read)
00057 {
00058 async_serialize_start();
00059
00060 ipc_call_t answer;
00061 aid_t req;
00062 int ret;
00063
00064 if (read) {
00065 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE),
00066 CHAR_DEV_READ, &answer);
00067 ret = async_data_read_start(dev_phone, buf, size);
00068 } else {
00069 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE),
00070 CHAR_DEV_WRITE, &answer);
00071 ret = async_data_write_start(dev_phone, buf, size);
00072 }
00073
00074 sysarg_t rc;
00075 if (ret != EOK) {
00076 async_wait_for(req, &rc);
00077 async_serialize_end();
00078 if (rc == EOK)
00079 return (ssize_t) ret;
00080
00081 return (ssize_t) rc;
00082 }
00083
00084 async_wait_for(req, &rc);
00085 async_serialize_end();
00086
00087 ret = (int) rc;
00088 if (ret != EOK)
00089 return (ssize_t) ret;
00090
00091 return (ssize_t) IPC_GET_ARG1(answer);
00092 }
00093
00103 ssize_t char_dev_read(int dev_phone, void *buf, size_t size)
00104 {
00105 return char_dev_rw(dev_phone, buf, size, true);
00106 }
00107
00118 ssize_t char_dev_write(int dev_phone, void *buf, size_t size)
00119 {
00120 return char_dev_rw(dev_phone, buf, size, false);
00121 }
00122