Changeset 8cd1aa5e in mainline for uspace/lib/usb/src/hcdhubd.c
- Timestamp:
- 2010-11-21T23:22:50Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 03171de, 0b749a3
- Parents:
- 31860b7 (diff), f0da4eb2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/hcdhubd.c
r31860b7 r8cd1aa5e 34 34 */ 35 35 #include <usb/hcdhubd.h> 36 #include <usb/devreq.h> 36 37 #include <usbhc_iface.h> 37 38 #include <driver.h> … … 55 56 .interfaces[USBHC_DEV_IFACE] = &usb_interface 56 57 }; 58 59 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address); 57 60 58 61 /** Callback when new device is detected and must be handled by this driver. … … 98 101 return EOK; 99 102 } else { 100 printf("%s: hub added, hurrah!\n", hc_driver->name); 103 usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link); 104 set_hub_address(hc, 5); 105 101 106 /* 102 107 * We are some (probably deeply nested) hub. … … 104 109 * connected devices. 105 110 */ 111 106 112 return ENOTSUP; 107 113 } 114 } 115 116 /** Sample usage of usb_hc_async functions. 117 * This function sets hub address using standard SET_ADDRESS request. 118 * 119 * @warning This function shall be removed once you are familiar with 120 * the usb_hc_ API. 121 * 122 * @param hc Host controller the hub belongs to. 123 * @param address New hub address. 124 */ 125 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) 126 { 127 printf("%s: setting hub address to %d\n", hc->generic->name, address); 128 usb_target_t target = {0, 0}; 129 usb_handle_t handle; 130 int rc; 131 132 usb_device_request_setup_packet_t setup_packet = { 133 .request_type = 0, 134 .request = USB_DEVREQ_SET_ADDRESS, 135 .index = 0, 136 .length = 0, 137 }; 138 setup_packet.value = address; 139 140 rc = usb_hc_async_control_write_setup(hc, target, 141 &setup_packet, sizeof(setup_packet), &handle); 142 if (rc != EOK) { 143 return; 144 } 145 146 rc = usb_hc_async_wait_for(handle); 147 if (rc != EOK) { 148 return; 149 } 150 151 rc = usb_hc_async_control_write_status(hc, target, &handle); 152 if (rc != EOK) { 153 return; 154 } 155 156 rc = usb_hc_async_wait_for(handle); 157 if (rc != EOK) { 158 return; 159 } 160 161 printf("%s: hub address changed\n", hc->generic->name); 108 162 } 109 163 … … 212 266 213 267 /* 214 * For testing/debugging purposes only.215 * Try to send some data to default USB address.216 */217 usb_target_t target = {0, 0};218 usb_handle_t handle = 0;219 char *data = (char *) "Hello, World!";220 221 222 (void)usb_hc_async_interrupt_out(dev, target, data, str_length(data), &handle);223 (void)usb_hc_async_wait_for(handle);224 225 /*226 268 * Announce presence of child device. 227 269 */ … … 272 314 } 273 315 274 /** Issue interrupt OUT transfer to HC driven by current task.275 *276 * @param hc Host controller to handle the transfer.277 * @param target Target device address.278 * @param buffer Data buffer.279 * @param size Buffer size.280 * @param handle Transfer handle.281 * @return Error code.282 */283 int usb_hc_async_interrupt_out(usb_hc_device_t *hc, usb_target_t target,284 void *buffer, size_t size,285 usb_handle_t *handle)286 {287 if ((hc->transfer_ops == NULL)288 || (hc->transfer_ops->transfer_out == NULL)) {289 return ENOTSUP;290 }291 292 /*293 * For debugging purposes only.294 * We need to find appropriate device in list of managed device295 * and pass it to the transfer callback function.296 */297 usb_hcd_attached_device_info_t dev = {298 .address = target.address,299 .endpoint_count = 0,300 .endpoints = NULL,301 };302 usb_hc_endpoint_info_t endpoint = {303 .endpoint = target.endpoint,304 .transfer_type = USB_TRANSFER_INTERRUPT,305 .direction = USB_DIRECTION_OUT,306 .data_toggle = 0307 };308 309 hc->transfer_ops->transfer_out(hc, &dev, &endpoint, buffer, size, NULL, NULL);310 311 *handle = (usb_handle_t)NULL;312 313 return EOK;314 }315 316 317 /** Issue interrupt IN transfer to HC driven by current task.318 *319 * @warning The @p buffer and @p actual_size parameters shall not be320 * touched until this transfer is waited for by usb_hc_async_wait_for().321 *322 * @param hc Host controller to handle the transfer.323 * @param target Target device address.324 * @param buffer Data buffer.325 * @param size Buffer size.326 * @param actual_size Size of actually transferred data.327 * @param handle Transfer handle.328 * @return Error code.329 */330 int usb_hc_async_interrupt_in(usb_hc_device_t *hc, usb_target_t target,331 void *buffer, size_t size, size_t *actual_size,332 usb_handle_t *handle)333 {334 /*335 * TODO: verify that given endpoint is of interrupt type and336 * call hc->transfer_ops->transfer_in()337 */338 return ENOTSUP;339 }340 341 /** Wait for transfer to complete.342 *343 * @param handle Transfer handle.344 * @return Error code.345 */346 int usb_hc_async_wait_for(usb_handle_t handle)347 {348 return ENOTSUP;349 }350 351 316 /** 352 317 * @}
Note:
See TracChangeset
for help on using the changeset viewer.