Changes in uspace/lib/usbdev/src/pipes.c [bb655dab:58563585] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/pipes.c
rbb655dab r58563585 36 36 #include <usb/dev/request.h> 37 37 #include <usb/usb.h> 38 #include <usb_iface.h> 38 39 39 40 #include <assert.h> … … 50 51 assert(pipe != NULL); 51 52 52 if (!pipe->auto_reset_halt || (pipe-> desc.endpoint_no != 0)) {53 if (!pipe->auto_reset_halt || (pipe->endpoint_no != 0)) { 53 54 return; 54 55 } … … 56 57 /* Prevent infinite recursion. */ 57 58 pipe->auto_reset_halt = false; 58 usb_ pipe_clear_halt(pipe, pipe);59 usb_request_clear_endpoint_halt(pipe, 0); 59 60 pipe->auto_reset_halt = true; 60 61 } … … 69 70 * @param[out] data_buffer Buffer for incoming data. 70 71 * @param[in] data_buffer_size Size of the buffer for incoming data (in bytes). 71 * @param[out] data_transfer red_size Number of bytes that were actually72 * transfer red during the DATA stage.72 * @param[out] data_transfered_size Number of bytes that were actually 73 * transfered during the DATA stage. 73 74 * @return Error code. 74 75 */ 75 76 int usb_pipe_control_read(usb_pipe_t *pipe, 76 77 const void *setup_buffer, size_t setup_buffer_size, 77 void *buffer, size_t buffer_size, size_t *transfer red_size)78 void *buffer, size_t buffer_size, size_t *transfered_size) 78 79 { 79 80 assert(pipe); … … 87 88 } 88 89 89 if ((pipe->d esc.direction != USB_DIRECTION_BOTH)90 || (pipe-> desc.transfer_type != USB_TRANSFER_CONTROL)) {90 if ((pipe->direction != USB_DIRECTION_BOTH) 91 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) { 91 92 return EBADF; 92 93 } … … 97 98 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 98 99 size_t act_size = 0; 99 const int rc = usb hc_read(exch, pipe->desc.endpoint_no, setup_packet, buffer,100 const int rc = usb_read(exch, pipe->endpoint_no, setup_packet, buffer, 100 101 buffer_size, &act_size); 101 102 async_exchange_end(exch); … … 105 106 } 106 107 107 if (rc == EOK && transfer red_size != NULL) {108 *transfer red_size = act_size;108 if (rc == EOK && transfered_size != NULL) { 109 *transfered_size = act_size; 109 110 } 110 111 … … 141 142 } 142 143 143 if ((pipe->d esc.direction != USB_DIRECTION_BOTH)144 || (pipe-> desc.transfer_type != USB_TRANSFER_CONTROL)) {144 if ((pipe->direction != USB_DIRECTION_BOTH) 145 || (pipe->transfer_type != USB_TRANSFER_CONTROL)) { 145 146 return EBADF; 146 147 } … … 150 151 151 152 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 152 const int rc = usb hc_write(exch,153 pipe-> desc.endpoint_no, setup_packet, buffer, buffer_size);153 const int rc = usb_write(exch, 154 pipe->endpoint_no, setup_packet, buffer, buffer_size); 154 155 async_exchange_end(exch); 155 156 … … 166 167 * @param[out] buffer Buffer where to store the data. 167 168 * @param[in] size Size of the buffer (in bytes). 168 * @param[out] size_transfer red Number of bytes that were actually transferred.169 * @param[out] size_transfered Number of bytes that were actually transfered. 169 170 * @return Error code. 170 171 */ 171 172 int usb_pipe_read(usb_pipe_t *pipe, 172 void *buffer, size_t size, size_t *size_transfer red)173 void *buffer, size_t size, size_t *size_transfered) 173 174 { 174 175 assert(pipe); … … 182 183 } 183 184 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 } 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; 191 197 192 198 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 193 199 size_t act_size = 0; 194 200 const int rc = 195 usb hc_read(exch, pipe->desc.endpoint_no, 0, buffer, size, &act_size);196 async_exchange_end(exch); 197 198 if (rc == EOK && size_transfer red != NULL) {199 *size_transfer red = act_size;201 usb_read(exch, pipe->endpoint_no, 0, buffer, size, &act_size); 202 async_exchange_end(exch); 203 204 if (rc == EOK && size_transfered != NULL) { 205 *size_transfered = act_size; 200 206 } 201 207 … … 218 224 } 219 225 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); 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); 230 241 async_exchange_end(exch); 231 242 return rc; … … 235 246 * 236 247 * @param pipe Endpoint pipe to be initialized. 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 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; 244 265 pipe->auto_reset_halt = false; 245 266 pipe->bus_session = bus_session; … … 248 269 } 249 270 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. 271 /** Initialize USB endpoint pipe as the default zero control pipe. 260 272 * 261 273 * @param pipe Endpoint pipe to be initialized. 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; 274 * @return Error code. 275 */ 276 int usb_pipe_initialize_default_control(usb_pipe_t *pipe, 277 usb_dev_session_t *bus_session) 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 272 284 pipe->auto_reset_halt = true; 273 285 274 return EOK;286 return rc; 275 287 } 276 288 … … 278 290 * 279 291 * @param pipe Pipe to be registered. 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) 292 * @param interval Polling interval. 293 * @return Error code. 294 */ 295 int usb_pipe_register(usb_pipe_t *pipe, unsigned interval) 285 296 { 286 297 assert(pipe); 287 298 assert(pipe->bus_session); 288 assert(ep_desc);289 290 299 async_exch_t *exch = async_exchange_begin(pipe->bus_session); 291 300 if (!exch) 292 301 return ENOMEM; 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); 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); 312 305 async_exchange_end(exch); 313 306 return ret; … … 326 319 if (!exch) 327 320 return ENOMEM; 328 329 const int ret = usbhc_unregister_endpoint(exch, &pipe->desc); 330 321 const int ret = usb_unregister_endpoint(exch, pipe->endpoint_no, 322 pipe->direction); 331 323 async_exchange_end(exch); 332 324 return ret;
Note:
See TracChangeset
for help on using the changeset viewer.