Changeset 43f698b in mainline for uspace/lib/usb/src/pipes.c
- Timestamp:
- 2011-01-30T21:41:53Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 54b5625
- Parents:
- 6865243c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/pipes.c
r6865243c r43f698b 45 45 #include <usb/pipes.h> 46 46 #include <errno.h> 47 #include <assert.h> 48 #include <usb/usbdrv.h> 49 50 #define _PREPARE_TARGET(varname, pipe) \ 51 usb_target_t varname = { \ 52 .address = (pipe)->wire->address, \ 53 .endpoint = (pipe)->endpoint_no \ 54 } 47 55 48 56 /** Initialize connection to USB device. … … 55 63 device_t *device) 56 64 { 57 return ENOTSUP; 65 assert(connection); 66 assert(device); 67 68 int rc; 69 devman_handle_t hc_handle; 70 usb_address_t my_address; 71 72 rc = usb_drv_find_hc(device, &hc_handle); 73 if (rc != EOK) { 74 return rc; 75 } 76 77 int hc_phone = devman_device_connect(hc_handle, 0); 78 if (hc_phone < 0) { 79 return hc_phone; 80 } 81 82 my_address = usb_drv_get_my_address(hc_phone, device); 83 if (my_address < 0) { 84 return my_address; 85 } 86 87 connection->hc_handle = hc_handle; 88 connection->address = my_address; 89 return EOK; 58 90 } 59 91 … … 72 104 usb_transfer_type_t transfer_type, usb_direction_t direction) 73 105 { 74 return ENOTSUP; 106 assert(pipe); 107 assert(connection); 108 109 pipe->wire = connection; 110 pipe->hc_phone = -1; 111 pipe->endpoint_no = endpoint_no; 112 pipe->transfer_type = transfer_type; 113 pipe->direction = direction; 114 115 return EOK; 75 116 } 76 117 … … 85 126 usb_device_connection_t *connection) 86 127 { 87 return ENOTSUP; 128 assert(pipe); 129 assert(connection); 130 131 int rc = usb_endpoint_pipe_initialize(pipe, connection, 132 0, USB_TRANSFER_CONTROL, USB_DIRECTION_BOTH); 133 134 return rc; 88 135 } 89 136 … … 106 153 int usb_endpoint_pipe_start_session(usb_endpoint_pipe_t *pipe) 107 154 { 108 return ENOTSUP; 155 assert(pipe); 156 157 if (pipe->hc_phone >= 0) { 158 return EBUSY; 159 } 160 161 int phone = devman_device_connect(pipe->wire->hc_handle, 0); 162 if (phone < 0) { 163 return phone; 164 } 165 166 pipe->hc_phone = phone; 167 168 return EOK; 109 169 } 110 170 … … 119 179 int usb_endpoint_pipe_end_session(usb_endpoint_pipe_t *pipe) 120 180 { 121 return ENOTSUP; 181 assert(pipe); 182 183 if (pipe->hc_phone < 0) { 184 return ENOENT; 185 } 186 187 int rc = ipc_hangup(pipe->hc_phone); 188 if (rc != EOK) { 189 return rc; 190 } 191 192 pipe->hc_phone = -1; 193 194 return EOK; 122 195 } 123 196 … … 134 207 void *buffer, size_t size, size_t *size_transfered) 135 208 { 136 return ENOTSUP; 209 assert(pipe); 210 211 int rc; 212 usb_handle_t handle; 213 214 rc = usb_endpoint_pipe_async_read(pipe, buffer, size, size_transfered, 215 &handle); 216 if (rc != EOK) { 217 return rc; 218 } 219 220 rc = usb_endpoint_pipe_wait_for(pipe, handle); 221 return rc; 137 222 } 138 223 … … 147 232 void *buffer, size_t size) 148 233 { 149 return ENOTSUP; 234 assert(pipe); 235 236 int rc; 237 usb_handle_t handle; 238 239 rc = usb_endpoint_pipe_async_write(pipe, buffer, size, &handle); 240 if (rc != EOK) { 241 return rc; 242 } 243 244 rc = usb_endpoint_pipe_wait_for(pipe, handle); 245 return rc; 150 246 } 151 247 … … 204 300 usb_handle_t *handle) 205 301 { 206 return ENOTSUP; 302 assert(pipe); 303 304 if (pipe->hc_phone < 0) { 305 return EBADF; 306 } 307 308 if (pipe->direction != USB_DIRECTION_IN) { 309 return EBADF; 310 } 311 312 int rc; 313 _PREPARE_TARGET(target, pipe); 314 315 switch (pipe->transfer_type) { 316 case USB_TRANSFER_INTERRUPT: 317 rc = usb_drv_async_interrupt_in(pipe->hc_phone, target, 318 buffer, size, size_transfered, handle); 319 break; 320 case USB_TRANSFER_CONTROL: 321 rc = EBADF; 322 break; 323 default: 324 rc = ENOTSUP; 325 break; 326 } 327 328 return rc; 207 329 } 208 330 … … 220 342 usb_handle_t *handle) 221 343 { 222 return ENOTSUP; 344 assert(pipe); 345 346 if (pipe->hc_phone < 0) { 347 return EBADF; 348 } 349 350 if (pipe->direction != USB_DIRECTION_OUT) { 351 return EBADF; 352 } 353 354 int rc; 355 _PREPARE_TARGET(target, pipe); 356 357 switch (pipe->transfer_type) { 358 case USB_TRANSFER_INTERRUPT: 359 rc = usb_drv_async_interrupt_out(pipe->hc_phone, target, 360 buffer, size, handle); 361 break; 362 case USB_TRANSFER_CONTROL: 363 rc = EBADF; 364 break; 365 default: 366 rc = ENOTSUP; 367 break; 368 } 369 370 return rc; 223 371 } 224 372 … … 278 426 int usb_endpoint_pipe_wait_for(usb_endpoint_pipe_t *pipe, usb_handle_t handle) 279 427 { 280 return ENOTSUP;428 return usb_drv_async_wait_for(handle); 281 429 } 282 430
Note:
See TracChangeset
for help on using the changeset viewer.