Changeset dc4c19e in mainline for uspace/lib/usb/src/host/device_keeper.c
- Timestamp:
- 2011-04-10T12:18:09Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 60c0573
- Parents:
- a49e171 (diff), 82e8861 (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/host/device_keeper.c
ra49e171 rdc4c19e 54 54 for (; i < USB_ADDRESS_COUNT; ++i) { 55 55 instance->devices[i].occupied = false; 56 instance->devices[i].control_used = 0;57 56 instance->devices[i].handle = 0; 58 list_initialize(&instance->devices[i].endpoints);57 instance->devices[i].speed = USB_SPEED_MAX; 59 58 } 60 } 61 /*----------------------------------------------------------------------------*/ 62 void usb_device_keeper_add_ep( 63 usb_device_keeper_t *instance, usb_address_t address, endpoint_t *ep) 64 { 65 assert(instance); 66 fibril_mutex_lock(&instance->guard); 67 assert(instance->devices[address].occupied); 68 list_append(&ep->same_device_eps, &instance->devices[address].endpoints); 69 fibril_mutex_unlock(&instance->guard); 59 // TODO: is this hack enough? 60 // (it is needed to allow smooth registration at default address) 61 instance->devices[0].occupied = true; 70 62 } 71 63 /*----------------------------------------------------------------------------*/ … … 102 94 } 103 95 /*----------------------------------------------------------------------------*/ 104 /** Check setup packet data for signs of toggle reset.105 *106 * @param[in] instance Device keeper structure to use.107 * @param[in] target Device to receive setup packet.108 * @param[in] data Setup packet data.109 *110 * Really ugly one.111 */112 void usb_device_keeper_reset_if_need(113 usb_device_keeper_t *instance, usb_target_t target, const uint8_t *data)114 {115 assert(instance);116 fibril_mutex_lock(&instance->guard);117 if (target.endpoint > 15 || target.endpoint < 0118 || target.address >= USB_ADDRESS_COUNT || target.address < 0119 || !instance->devices[target.address].occupied) {120 fibril_mutex_unlock(&instance->guard);121 usb_log_error("Invalid data when checking for toggle reset.\n");122 return;123 }124 125 switch (data[1])126 {127 case 0x01: /*clear feature*/128 /* recipient is endpoint, value is zero (ENDPOINT_STALL) */129 if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {130 link_t *current =131 instance->devices[target.address].endpoints.next;132 while (current !=133 &instance->devices[target.address].endpoints)134 {135 /* endpoint number is < 16, thus first byte is enough */136 endpoint_toggle_reset_filtered(137 current, data[4]);138 current = current->next;139 }140 }141 break;142 143 case 0x9: /* set configuration */144 case 0x11: /* set interface */145 /* target must be device */146 if ((data[0] & 0xf) == 0) {147 link_t *current =148 instance->devices[target.address].endpoints.next;149 while (current !=150 &instance->devices[target.address].endpoints)151 {152 endpoint_toggle_reset(current);153 current = current->next;154 }155 }156 break;157 }158 fibril_mutex_unlock(&instance->guard);159 }160 96 /*----------------------------------------------------------------------------*/ 161 97 /** Get a free USB address … … 264 200 return instance->devices[address].speed; 265 201 } 266 /*----------------------------------------------------------------------------*/267 void usb_device_keeper_use_control(268 usb_device_keeper_t *instance, usb_target_t target)269 {270 assert(instance);271 const uint16_t ep = 1 << target.endpoint;272 fibril_mutex_lock(&instance->guard);273 while (instance->devices[target.address].control_used & ep) {274 fibril_condvar_wait(&instance->change, &instance->guard);275 }276 instance->devices[target.address].control_used |= ep;277 fibril_mutex_unlock(&instance->guard);278 }279 /*----------------------------------------------------------------------------*/280 void usb_device_keeper_release_control(281 usb_device_keeper_t *instance, usb_target_t target)282 {283 assert(instance);284 const uint16_t ep = 1 << target.endpoint;285 fibril_mutex_lock(&instance->guard);286 assert((instance->devices[target.address].control_used & ep) != 0);287 instance->devices[target.address].control_used &= ~ep;288 fibril_mutex_unlock(&instance->guard);289 fibril_condvar_signal(&instance->change);290 }291 202 /** 292 203 * @}
Note:
See TracChangeset
for help on using the changeset viewer.