Changeset df6b760 in mainline
- Timestamp:
- 2010-11-26T13:31:37Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ffdd2b9
- Parents:
- d47279b
- Location:
- uspace/lib/c
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/device/char.c
rd47279b rdf6b760 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 29 /** @addtogroup libc 30 30 * @{ … … 40 40 #include <stdio.h> 41 41 42 /** Read to or write from the device using its character interface. 43 * 44 * Helper function. 45 * 46 * @param dev_phone phone to the device. 47 * @param buf the buffer for the data read from or written to the device. 48 * @param len the maximum length of the data to be read or written. 49 * @param read read from the device if true, write to it otherwise. 50 * 51 * @return non-negative number of bytes actually read from or written to the device on success, 52 * negative error number otherwise. 53 * 42 /** Read to or write from device. 43 * 44 * Helper function to read to or write from a device 45 * using its character interface. 46 * 47 * @param dev_phone Phone to the device. 48 * @param buf Buffer for the data read 49 * from or written to the device. 50 * @param len Maximum length of the data to be 51 * read or written. 52 * @param read Read from the device if true, 53 * write to it otherwise. 54 * 55 * @return Non-negative number of bytes actually read 56 * from or written to the device on success, 57 * negative error number otherwise. 58 * 54 59 */ 55 static int rw_dev(int dev_phone, void *buf, size_t len, bool read)60 static ssize_t rw_dev(int dev_phone, void *buf, size_t len, bool read) 56 61 { 57 ipc_call_t answer;58 59 62 async_serialize_start(); 60 63 64 ipc_call_t answer; 61 65 aid_t req; 62 66 int ret; 63 67 64 68 if (read) { 65 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_READ_DEV, &answer); 66 ret = async_data_read_start(dev_phone, buf, len); 69 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), 70 CHAR_READ_DEV, &answer); 71 ret = async_data_read_start(dev_phone, buf, len); 67 72 } else { 68 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_WRITE_DEV, &answer); 73 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), 74 CHAR_WRITE_DEV, &answer); 69 75 ret = async_data_write_start(dev_phone, buf, len); 70 76 } 71 77 72 78 ipcarg_t rc; 73 if (ret != EOK) { 79 if (ret != EOK) { 74 80 async_wait_for(req, &rc); 75 81 async_serialize_end(); 76 if (rc == EOK) { 77 return ret; 78 } 79 else { 80 return (int) rc; 81 } 82 if (rc == EOK) 83 return (ssize_t) ret; 84 85 return (ssize_t) rc; 82 86 } 83 87 … … 85 89 async_serialize_end(); 86 90 87 ret = (int)rc; 88 if (EOK != ret) { 89 return ret; 90 } 91 ret = (int) rc; 92 if (ret != EOK) 93 return (ssize_t) ret; 91 94 92 return IPC_GET_ARG1(answer);95 return (ssize_t) IPC_GET_ARG1(answer); 93 96 } 94 97 95 /** Read from the device using its character interface. 96 * 97 * @param dev_phone phone to the device. 98 * @param buf the output buffer for the data read from the device. 99 * @param len the maximum length of the data to be read. 100 * 101 * @return non-negative number of bytes actually read from the device on success, negative error number otherwise. 98 /** Read from device using its character interface. 99 * 100 * @param dev_phone Phone to the device. 101 * @param buf Output buffer for the data 102 * read from the device. 103 * @param len Maximum length of the data to be read. 104 * 105 * @return Non-negative number of bytes actually read 106 * from the device on success, negative error 107 * number otherwise. 108 * 102 109 */ 103 int read_dev(int dev_phone, void *buf, size_t len)104 { 110 ssize_t read_dev(int dev_phone, void *buf, size_t len) 111 { 105 112 return rw_dev(dev_phone, buf, len, true); 106 113 } 107 114 108 /** Write to the device using its character interface. 109 * 110 * @param dev_phone phone to the device. 111 * @param buf the input buffer containg the data to be written to the device. 112 * @param len the maximum length of the data to be written. 113 * 114 * @return non-negative number of bytes actually written to the device on success, negative error number otherwise. 115 /** Write to device using its character interface. 116 * 117 * @param dev_phone Phone to the device. 118 * @param buf Input buffer containg the data 119 * to be written to the device. 120 * @param len Maximum length of the data to be written. 121 * 122 * @return Non-negative number of bytes actually written 123 * to the device on success, negative error number 124 * otherwise. 125 * 115 126 */ 116 int write_dev(int dev_phone, void *buf, size_t len)127 ssize_t write_dev(int dev_phone, void *buf, size_t len) 117 128 { 118 129 return rw_dev(dev_phone, buf, len, false); 119 130 } 120 131 121 122 /** @} 132 /** @} 123 133 */ -
uspace/lib/c/include/device/char.h
rd47279b rdf6b760 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 29 /** @addtogroup libc 30 30 * @{ … … 32 32 /** @file 33 33 */ 34 34 35 35 #ifndef LIBC_DEVICE_HW_RES_H_ 36 36 #define LIBC_DEVICE_HW_RES_H_ … … 38 38 typedef enum { 39 39 CHAR_READ_DEV = 0, 40 CHAR_WRITE_DEV 40 CHAR_WRITE_DEV 41 41 } hw_res_funcs_t; 42 42 43 int read_dev(int dev_phone, void *buf, size_t len);44 int write_dev(int dev_phone, void *buf, size_t len);43 ssize_t read_dev(int dev_phone, void *buf, size_t len); 44 ssize_t write_dev(int dev_phone, void *buf, size_t len); 45 45 46 46 #endif
Note:
See TracChangeset
for help on using the changeset viewer.