Changeset ca97cad in mainline for uspace/lib/libc
- Timestamp:
- 2010-05-06T11:42:55Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ab1aa871
- Parents:
- ba95e8f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/device/char.c
rba95e8f rca97cad 40 40 #include <stdio.h> 41 41 42 43 int read_dev(int dev_phone, void *buf, size_t len) 44 { 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 * 54 */ 55 static int rw_dev(int dev_phone, void *buf, size_t len, bool read) 56 { 45 57 ipc_call_t answer; 46 58 47 59 async_serialize_start(); 48 60 49 aid_t req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_READ_DEV, &answer); 61 aid_t req; 62 int rc; 50 63 51 int rc = async_data_read_start(dev_phone, buf, len); 64 if (read) { 65 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_READ_DEV, &answer); 66 rc = async_data_read_start(dev_phone, buf, len); 67 } else { 68 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_WRITE_DEV, &answer); 69 rc = async_data_write_start(dev_phone, buf, len); 70 } 52 71 53 72 if (rc != EOK) { … … 70 89 } 71 90 72 return IPC_GET_ARG1(answer); 91 return IPC_GET_ARG1(answer); 73 92 } 74 93 94 /** Read from the device using its character interface. 95 * 96 * @param dev_phone phone to the device. 97 * @param buf the output buffer for the data read from the device. 98 * @param len the maximum length of the data to be read. 99 * 100 * @return non-negative number of bytes actually read from the device on success, negative error number otherwise. 101 */ 102 int read_dev(int dev_phone, void *buf, size_t len) 103 { 104 return rw_dev(dev_phone, buf, len, true); 105 } 106 107 /** Write to the device using its character interface. 108 * 109 * @param dev_phone phone to the device. 110 * @param buf the input buffer containg the data to be written to the device. 111 * @param len the maximum length of the data to be written. 112 * 113 * @return non-negative number of bytes actually written to the device on success, negative error number otherwise. 114 */ 75 115 int write_dev(int dev_phone, void *buf, size_t len) 76 116 { 77 // TODO 78 return 0; 117 return rw_dev(dev_phone, buf, len, false); 79 118 } 80 119
Note:
See TracChangeset
for help on using the changeset viewer.