Changes in uspace/lib/usbdev/src/pipes.c [9d58539:c01987c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/pipes.c
r9d58539 rc01987c 35 35 #include <usb/dev/pipes.h> 36 36 #include <usb/dev/request.h> 37 #include <usb/usb.h> 38 #include <usb_iface.h> 39 40 #include <assert.h> 41 #include <async.h> 37 42 #include <errno.h> 38 #include <assert.h> 39 40 /** Prepare pipe for a long transfer. 41 * 42 * Long transfer is transfer consisting of several requests to the HC. 43 * Calling this function is optional and it has positive effect of 44 * improved performance because IPC session is initiated only once. 45 * 46 * @param pipe Pipe over which the transfer will happen. 47 * @return Error code. 48 */ 49 int usb_pipe_start_long_transfer(usb_pipe_t *pipe) 50 { 51 assert(pipe); 52 assert(pipe->wire); 53 assert(pipe->wire->hc_connection); 54 return usb_hc_connection_open(pipe->wire->hc_connection); 55 } 56 /*----------------------------------------------------------------------------*/ 57 /** Terminate a long transfer on a pipe. 58 * @param pipe Pipe where to end the long transfer. 59 * @return Error code. 60 * @see usb_pipe_start_long_transfer 61 */ 62 int usb_pipe_end_long_transfer(usb_pipe_t *pipe) 63 { 64 assert(pipe); 65 assert(pipe->wire); 66 assert(pipe->wire->hc_connection); 67 return usb_hc_connection_close(pipe->wire->hc_connection); 68 } 69 /*----------------------------------------------------------------------------*/ 43 #include <mem.h> 44 70 45 /** Try to clear endpoint halt of default control pipe. 71 46 * … … 85 60 pipe->auto_reset_halt = true; 86 61 } 87 /*----------------------------------------------------------------------------*/ 62 88 63 /** Request a control read transfer on an endpoint pipe. 89 64 * … … 121 96 memcpy(&setup_packet, setup_buffer, 8); 122 97 98 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 123 99 size_t act_size = 0; 124 const int rc = usb_ device_control_read(pipe->wire,100 const int rc = usb_read(exch, 125 101 pipe->endpoint_no, setup_packet, buffer, buffer_size, &act_size); 102 async_exchange_end(exch); 126 103 127 104 if (rc == ESTALL) { … … 135 112 return rc; 136 113 } 137 /*----------------------------------------------------------------------------*/ 114 138 115 /** Request a control write transfer on an endpoint pipe. 139 116 * … … 173 150 memcpy(&setup_packet, setup_buffer, 8); 174 151 175 const int rc = usb_device_control_write(pipe->wire, 152 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 153 const int rc = usb_write(exch, 176 154 pipe->endpoint_no, setup_packet, buffer, buffer_size); 155 async_exchange_end(exch); 177 156 178 157 if (rc == ESTALL) { … … 182 161 return rc; 183 162 } 184 /*----------------------------------------------------------------------------*/ 163 185 164 /** Request a read (in) transfer on an endpoint pipe. 186 165 * … … 217 196 return ENOTSUP; 218 197 198 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 219 199 size_t act_size = 0; 220 const int rc = usb_device_read(pipe->wire, 221 pipe->endpoint_no, buffer, size, &act_size); 200 const int rc = 201 usb_read(exch, pipe->endpoint_no, 0, buffer, size, &act_size); 202 async_exchange_end(exch); 222 203 223 204 if (rc == EOK && size_transfered != NULL) { … … 227 208 return rc; 228 209 } 229 /*----------------------------------------------------------------------------*/ 210 230 211 /** Request a write (out) transfer on an endpoint pipe. 231 212 * … … 256 237 return ENOTSUP; 257 238 258 return usb_device_write(pipe->wire, 259 pipe->endpoint_no, buffer, size); 260 } 261 /*----------------------------------------------------------------------------*/ 239 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 240 const int rc = usb_write(exch, pipe->endpoint_no, 0, buffer, size); 241 async_exchange_end(exch); 242 return rc; 243 } 244 262 245 /** Initialize USB endpoint pipe. 263 246 * 264 247 * @param pipe Endpoint pipe to be initialized. 265 * @param connection Connection to the USB device backing this pipe (the wire).266 248 * @param endpoint_no Endpoint number (in USB 1.1 in range 0 to 15). 267 249 * @param transfer_type Transfer type (e.g. interrupt or bulk). … … 270 252 * @return Error code. 271 253 */ 272 int usb_pipe_initialize(usb_pipe_t *pipe, 273 usb_device_connection_t *connection, usb_endpoint_t endpoint_no, 254 int usb_pipe_initialize(usb_pipe_t *pipe, usb_endpoint_t endpoint_no, 274 255 usb_transfer_type_t transfer_type, size_t max_packet_size, 275 usb_direction_t direction) 276 { 277 assert(pipe); 278 assert(connection); 279 280 pipe->wire = connection; 256 usb_direction_t direction, usb_dev_session_t *bus_session) 257 { 258 assert(pipe); 259 281 260 pipe->endpoint_no = endpoint_no; 282 261 pipe->transfer_type = transfer_type; … … 284 263 pipe->direction = direction; 285 264 pipe->auto_reset_halt = false; 265 pipe->bus_session = bus_session; 286 266 287 267 return EOK; 288 268 } 289 /*----------------------------------------------------------------------------*/ 269 290 270 /** Initialize USB endpoint pipe as the default zero control pipe. 291 271 * 292 272 * @param pipe Endpoint pipe to be initialized. 293 * @param connection Connection to the USB device backing this pipe (the wire).294 273 * @return Error code. 295 274 */ 296 275 int usb_pipe_initialize_default_control(usb_pipe_t *pipe, 297 usb_device_connection_t *connection) 298 { 299 assert(pipe); 300 assert(connection); 301 302 int rc = usb_pipe_initialize(pipe, connection, 0, USB_TRANSFER_CONTROL, 303 CTRL_PIPE_MIN_PACKET_SIZE, USB_DIRECTION_BOTH); 276 usb_dev_session_t *bus_session) 277 { 278 assert(pipe); 279 280 const int rc = usb_pipe_initialize(pipe, 0, USB_TRANSFER_CONTROL, 281 CTRL_PIPE_MIN_PACKET_SIZE, USB_DIRECTION_BOTH, bus_session); 304 282 305 283 pipe->auto_reset_halt = true; … … 307 285 return rc; 308 286 } 309 /*----------------------------------------------------------------------------*/ 287 310 288 /** Register endpoint with the host controller. 311 289 * … … 317 295 { 318 296 assert(pipe); 319 assert(pipe->wire); 320 321 return usb_device_register_endpoint(pipe->wire, 322 pipe->endpoint_no, pipe->transfer_type, 323 pipe->direction, pipe->max_packet_size, interval); 324 } 325 /*----------------------------------------------------------------------------*/ 297 assert(pipe->bus_session); 298 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 299 if (!exch) 300 return ENOMEM; 301 const int ret = usb_register_endpoint(exch, pipe->endpoint_no, 302 pipe->transfer_type, pipe->direction, pipe->max_packet_size, 303 interval); 304 async_exchange_end(exch); 305 return ret; 306 } 307 326 308 /** Revert endpoint registration with the host controller. 327 309 * … … 332 314 { 333 315 assert(pipe); 334 assert(pipe->wire); 335 336 return usb_device_unregister_endpoint(pipe->wire, 337 pipe->endpoint_no, pipe->direction); 316 assert(pipe->bus_session); 317 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 318 if (!exch) 319 return ENOMEM; 320 const int ret = usb_unregister_endpoint(exch, pipe->endpoint_no, 321 pipe->direction); 322 async_exchange_end(exch); 323 return ret; 338 324 } 339 325
Note:
See TracChangeset
for help on using the changeset viewer.