Changes in uspace/lib/usbdev/src/pipes.c [58563585:bb655dab] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/pipes.c
r58563585 rbb655dab 36 36 #include <usb/dev/request.h> 37 37 #include <usb/usb.h> 38 #include <usb_iface.h>39 38 40 39 #include <assert.h> … … 51 50 assert(pipe != NULL); 52 51 53 if (!pipe->auto_reset_halt || (pipe-> endpoint_no != 0)) {52 if (!pipe->auto_reset_halt || (pipe->desc.endpoint_no != 0)) { 54 53 return; 55 54 } … … 57 56 /* Prevent infinite recursion. */ 58 57 pipe->auto_reset_halt = false; 59 usb_ request_clear_endpoint_halt(pipe, 0);58 usb_pipe_clear_halt(pipe, pipe); 60 59 pipe->auto_reset_halt = true; 61 60 } … … 70 69 * @param[out] data_buffer Buffer for incoming data. 71 70 * @param[in] data_buffer_size Size of the buffer for incoming data (in bytes). 72 * @param[out] data_transfer ed_size Number of bytes that were actually73 * transfer ed during the DATA stage.71 * @param[out] data_transferred_size Number of bytes that were actually 72 * transferred during the DATA stage. 74 73 * @return Error code. 75 74 */ 76 75 int usb_pipe_control_read(usb_pipe_t *pipe, 77 76 const void *setup_buffer, size_t setup_buffer_size, 78 void *buffer, size_t buffer_size, size_t *transfer ed_size)77 void *buffer, size_t buffer_size, size_t *transferred_size) 79 78 { 80 79 assert(pipe); … … 88 87 } 89 88 90 if ((pipe->d irection != USB_DIRECTION_BOTH)91 || (pipe-> transfer_type != USB_TRANSFER_CONTROL)) {89 if ((pipe->desc.direction != USB_DIRECTION_BOTH) 90 || (pipe->desc.transfer_type != USB_TRANSFER_CONTROL)) { 92 91 return EBADF; 93 92 } … … 98 97 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 99 98 size_t act_size = 0; 100 const int rc = usb _read(exch, pipe->endpoint_no, setup_packet, buffer,99 const int rc = usbhc_read(exch, pipe->desc.endpoint_no, setup_packet, buffer, 101 100 buffer_size, &act_size); 102 101 async_exchange_end(exch); … … 106 105 } 107 106 108 if (rc == EOK && transfer ed_size != NULL) {109 *transfer ed_size = act_size;107 if (rc == EOK && transferred_size != NULL) { 108 *transferred_size = act_size; 110 109 } 111 110 … … 142 141 } 143 142 144 if ((pipe->d irection != USB_DIRECTION_BOTH)145 || (pipe-> transfer_type != USB_TRANSFER_CONTROL)) {143 if ((pipe->desc.direction != USB_DIRECTION_BOTH) 144 || (pipe->desc.transfer_type != USB_TRANSFER_CONTROL)) { 146 145 return EBADF; 147 146 } … … 151 150 152 151 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 153 const int rc = usb _write(exch,154 pipe-> endpoint_no, setup_packet, buffer, buffer_size);152 const int rc = usbhc_write(exch, 153 pipe->desc.endpoint_no, setup_packet, buffer, buffer_size); 155 154 async_exchange_end(exch); 156 155 … … 167 166 * @param[out] buffer Buffer where to store the data. 168 167 * @param[in] size Size of the buffer (in bytes). 169 * @param[out] size_transfer ed Number of bytes that were actually transfered.168 * @param[out] size_transferred Number of bytes that were actually transferred. 170 169 * @return Error code. 171 170 */ 172 171 int usb_pipe_read(usb_pipe_t *pipe, 173 void *buffer, size_t size, size_t *size_transfer ed)172 void *buffer, size_t size, size_t *size_transferred) 174 173 { 175 174 assert(pipe); … … 183 182 } 184 183 185 if (pipe->direction != USB_DIRECTION_IN) { 186 return EBADF; 187 } 188 189 if (pipe->transfer_type == USB_TRANSFER_CONTROL) { 190 return EBADF; 191 } 192 193 /* Isochronous transfer are not supported (yet) */ 194 if (pipe->transfer_type != USB_TRANSFER_INTERRUPT && 195 pipe->transfer_type != USB_TRANSFER_BULK) 196 return ENOTSUP; 184 if (pipe->desc.direction != USB_DIRECTION_IN) { 185 return EBADF; 186 } 187 188 if (pipe->desc.transfer_type == USB_TRANSFER_CONTROL) { 189 return EBADF; 190 } 197 191 198 192 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 199 193 size_t act_size = 0; 200 194 const int rc = 201 usb _read(exch, pipe->endpoint_no, 0, buffer, size, &act_size);202 async_exchange_end(exch); 203 204 if (rc == EOK && size_transfer ed != NULL) {205 *size_transfer ed = act_size;195 usbhc_read(exch, pipe->desc.endpoint_no, 0, buffer, size, &act_size); 196 async_exchange_end(exch); 197 198 if (rc == EOK && size_transferred != NULL) { 199 *size_transferred = act_size; 206 200 } 207 201 … … 224 218 } 225 219 226 if (pipe->direction != USB_DIRECTION_OUT) { 227 return EBADF; 228 } 229 230 if (pipe->transfer_type == USB_TRANSFER_CONTROL) { 231 return EBADF; 232 } 233 234 /* Isochronous transfer are not supported (yet) */ 235 if (pipe->transfer_type != USB_TRANSFER_INTERRUPT && 236 pipe->transfer_type != USB_TRANSFER_BULK) 237 return ENOTSUP; 238 239 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 240 const int rc = usb_write(exch, pipe->endpoint_no, 0, buffer, size); 220 if (pipe->desc.direction != USB_DIRECTION_OUT) { 221 return EBADF; 222 } 223 224 if (pipe->desc.transfer_type == USB_TRANSFER_CONTROL) { 225 return EBADF; 226 } 227 228 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 229 const int rc = usbhc_write(exch, pipe->desc.endpoint_no, 0, buffer, size); 241 230 async_exchange_end(exch); 242 231 return rc; … … 246 235 * 247 236 * @param pipe Endpoint pipe to be initialized. 248 * @param endpoint_no Endpoint number (in USB 1.1 in range 0 to 15). 249 * @param transfer_type Transfer type (e.g. interrupt or bulk). 250 * @param max_packet_size Maximum packet size in bytes. 251 * @param direction Endpoint direction (in/out). 252 * @return Error code. 253 */ 254 int usb_pipe_initialize(usb_pipe_t *pipe, usb_endpoint_t endpoint_no, 255 usb_transfer_type_t transfer_type, size_t max_packet_size, 256 usb_direction_t direction, unsigned packets, usb_dev_session_t *bus_session) 257 { 258 assert(pipe); 259 260 pipe->endpoint_no = endpoint_no; 261 pipe->transfer_type = transfer_type; 262 pipe->packets = packets; 263 pipe->max_packet_size = max_packet_size; 264 pipe->direction = direction; 237 * @param bus_session Endpoint pipe to be initialized. 238 * @return Error code. 239 */ 240 int usb_pipe_initialize(usb_pipe_t *pipe, usb_dev_session_t *bus_session) 241 { 242 assert(pipe); 243 265 244 pipe->auto_reset_halt = false; 266 245 pipe->bus_session = bus_session; … … 269 248 } 270 249 271 /** Initialize USB endpoint pipe as the default zero control pipe. 250 static const usb_pipe_desc_t default_control_pipe = { 251 .endpoint_no = 0, 252 .transfer_type = USB_TRANSFER_CONTROL, 253 .direction = USB_DIRECTION_BOTH, 254 .max_transfer_size = CTRL_PIPE_MIN_PACKET_SIZE, 255 }; 256 257 /** Initialize USB default control pipe. 258 * 259 * This one is special because it must not be registered, it is registered automatically. 272 260 * 273 261 * @param pipe Endpoint pipe to be initialized. 274 * @ return Error code.275 * /276 int usb_pipe_initialize_default_control(usb_pipe_t *pipe, 277 278 { 279 assert(pipe);280 281 const int rc = usb_pipe_initialize(pipe, 0, USB_TRANSFER_CONTROL,282 CTRL_PIPE_MIN_PACKET_SIZE, USB_DIRECTION_BOTH, 1, bus_session); 283 262 * @param bus_session Endpoint pipe to be initialized. 263 * @return Error code. 264 */ 265 int usb_pipe_initialize_default_control(usb_pipe_t *pipe, usb_dev_session_t *bus_session) 266 { 267 const int ret = usb_pipe_initialize(pipe, bus_session); 268 if (ret) 269 return ret; 270 271 pipe->desc = default_control_pipe; 284 272 pipe->auto_reset_halt = true; 285 273 286 return rc;274 return EOK; 287 275 } 288 276 … … 290 278 * 291 279 * @param pipe Pipe to be registered. 292 * @param interval Polling interval. 293 * @return Error code. 294 */ 295 int usb_pipe_register(usb_pipe_t *pipe, unsigned interval) 280 * @param ep_desc Matched endpoint descriptor 281 * @param comp_desc Matched superspeed companion descriptro, if any 282 * @return Error code. 283 */ 284 int usb_pipe_register(usb_pipe_t *pipe, const usb_standard_endpoint_descriptor_t *ep_desc, const usb_superspeed_endpoint_companion_descriptor_t *comp_desc) 296 285 { 297 286 assert(pipe); 298 287 assert(pipe->bus_session); 288 assert(ep_desc); 289 299 290 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 300 291 if (!exch) 301 292 return ENOMEM; 302 const int ret = usb_register_endpoint(exch, pipe->endpoint_no, 303 pipe->transfer_type, pipe->direction, pipe->max_packet_size, 304 pipe->packets, interval); 293 294 usb_endpoint_descriptors_t descriptors; 295 296 #define COPY(field) descriptors.endpoint.field = ep_desc->field 297 COPY(endpoint_address); 298 COPY(attributes); 299 COPY(max_packet_size); 300 COPY(poll_interval); 301 #undef COPY 302 303 #define COPY(field) descriptors.companion.field = comp_desc->field 304 if (comp_desc) { 305 COPY(max_burst); 306 COPY(attributes); 307 COPY(bytes_per_interval); 308 } 309 #undef COPY 310 311 const int ret = usbhc_register_endpoint(exch, &pipe->desc, &descriptors); 305 312 async_exchange_end(exch); 306 313 return ret; … … 319 326 if (!exch) 320 327 return ENOMEM; 321 const int ret = usb_unregister_endpoint(exch, pipe->endpoint_no, 322 pipe->direction); 328 329 const int ret = usbhc_unregister_endpoint(exch, &pipe->desc); 330 323 331 async_exchange_end(exch); 324 332 return ret;
Note:
See TracChangeset
for help on using the changeset viewer.