Changeset 41811af in mainline for uspace/lib/c/generic/device/char_dev.c
- Timestamp:
- 2011-06-10T10:14:26Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ab547063
- Parents:
- 9536e6e (diff), 390d80d (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/device/char_dev.c
r9536e6e r41811af 45 45 * using its character interface. 46 46 * 47 * @param dev_phone Phoneto the device.48 * @param buf 49 * @param size 50 * @param read 47 * @param sess Session to the device. 48 * @param buf Buffer for the data read from or written to the device. 49 * @param size Maximum size of data (in bytes) to be read or written. 50 * @param read Read from the device if true, write to it otherwise. 51 51 * 52 * @return Non-negative number of bytes actually read from or 53 * written to the device on success, negative error number 54 * otherwise. 52 * @return Non-negative number of bytes actually read from or 53 * written to the device on success, negative error number 54 * otherwise. 55 * 55 56 */ 56 static ssize_t char_dev_rw( int dev_phone, void *buf, size_t size, bool read)57 static ssize_t char_dev_rw(async_sess_t *sess, void *buf, size_t size, bool read) 57 58 { 58 async_serialize_start();59 60 59 ipc_call_t answer; 61 60 aid_t req; 62 61 int ret; 63 62 63 async_exch_t *exch = async_exchange_begin(sess); 64 64 65 if (read) { 65 req = async_send_1( dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE),66 req = async_send_1(exch, DEV_IFACE_ID(CHAR_DEV_IFACE), 66 67 CHAR_DEV_READ, &answer); 67 ret = async_data_read_start( dev_phone, buf, size);68 ret = async_data_read_start(exch, buf, size); 68 69 } else { 69 req = async_send_1( dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE),70 req = async_send_1(exch, DEV_IFACE_ID(CHAR_DEV_IFACE), 70 71 CHAR_DEV_WRITE, &answer); 71 ret = async_data_write_start( dev_phone, buf, size);72 ret = async_data_write_start(exch, buf, size); 72 73 } 74 75 async_exchange_end(exch); 73 76 74 77 sysarg_t rc; 75 78 if (ret != EOK) { 76 79 async_wait_for(req, &rc); 77 async_serialize_end();78 80 if (rc == EOK) 79 81 return (ssize_t) ret; … … 83 85 84 86 async_wait_for(req, &rc); 85 async_serialize_end();86 87 87 88 ret = (int) rc; … … 94 95 /** Read from character device. 95 96 * 96 * @param dev_phone Phoneto the device.97 * @param buf 98 * @param size 97 * @param sess Session to the device. 98 * @param buf Output buffer for the data read from the device. 99 * @param size Maximum size (in bytes) of the data to be read. 99 100 * 100 * @return Non-negative number of bytes actually read from the 101 * device on success, negative error number otherwise. 101 * @return Non-negative number of bytes actually read from the 102 * device on success, negative error number otherwise. 103 * 102 104 */ 103 ssize_t char_dev_read( int dev_phone, void *buf, size_t size)105 ssize_t char_dev_read(async_sess_t *sess, void *buf, size_t size) 104 106 { 105 return char_dev_rw( dev_phone, buf, size, true);107 return char_dev_rw(sess, buf, size, true); 106 108 } 107 109 108 110 /** Write to character device. 109 111 * 110 * @param dev_phone Phoneto the device.111 * @param buf 112 * 113 * @param size 112 * @param sess Session to the device. 113 * @param buf Input buffer containg the data to be written to the 114 * device. 115 * @param size Maximum size (in bytes) of the data to be written. 114 116 * 115 * @return Non-negative number of bytes actually written to the 116 * device on success, negative error number otherwise. 117 * @return Non-negative number of bytes actually written to the 118 * device on success, negative error number otherwise. 119 * 117 120 */ 118 ssize_t char_dev_write( int dev_phone, void *buf, size_t size)121 ssize_t char_dev_write(async_sess_t *sess, void *buf, size_t size) 119 122 { 120 return char_dev_rw( dev_phone, buf, size, false);123 return char_dev_rw(sess, buf, size, false); 121 124 } 122 125
Note:
See TracChangeset
for help on using the changeset viewer.