Changeset 1102eca in mainline for uspace/lib/usbhost/src/usb2_bus.c
- Timestamp:
- 2018-01-08T17:17:38Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bdd8842c
- Parents:
- eb928c4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/usb2_bus.c
reb928c4 r1102eca 31 31 */ 32 32 /** @file 33 * HC Endpoint management. 33 * 34 * A bus_t implementation for USB 2 and lower. Implements USB 2 enumeration and 35 * configurable bandwidth counting. 34 36 */ 35 37 … … 50 52 #include "usb2_bus.h" 51 53 52 /** Ops receive generic bus_t pointer. */ 54 /** 55 * Ops receive generic bus_t pointer. 56 */ 53 57 static inline usb2_bus_t *bus_to_usb2_bus(bus_t *bus_base) 54 58 { … … 57 61 } 58 62 59 /** Unregister and destroy all endpoints using given address. 60 * @param bus usb_bus structure, non-null. 61 * @param address USB address. 62 * @param endpoint USB endpoint number. 63 * @param direction Communication direction. 64 * @return Error code. 65 */ 66 static int release_address(usb2_bus_t *bus, usb_address_t address) 67 { 68 if (!usb_address_is_valid(address)) 69 return EINVAL; 70 71 const int ret = bus->address_occupied[address] ? EOK : ENOENT; 72 bus->address_occupied[address] = false; 73 return ret; 74 } 75 76 /** Request USB address. 63 /** 64 * Request a new address. A free address is found and marked as occupied. 65 * 66 * There's no need to synchronize this method, because it is called only with 67 * default address reserved. 68 * 77 69 * @param bus usb_device_manager 78 70 * @param addr Pointer to requested address value, place to store new address 79 * @return Error code.80 * @note Default address is only available in strict mode.81 71 */ 82 72 static int request_address(usb2_bus_t *bus, usb_address_t *addr) … … 99 89 } 100 90 91 /** 92 * Mark address as free. 93 */ 94 static void release_address(usb2_bus_t *bus, usb_address_t address) 95 { 96 bus->address_occupied[address] = false; 97 } 98 101 99 static const usb_target_t usb2_default_target = {{ 102 100 .address = USB_ADDRESS_DEFAULT, … … 104 102 }}; 105 103 104 /** 105 * Transition the device to the addressed state. 106 * 107 * Reserve address, configure the control EP, issue a SET_ADDRESS command. 108 * Configure the device with the new address, mark the device as online. 109 */ 106 110 static int address_device(device_t *dev) 107 111 { … … 184 188 } 185 189 186 /** Enumerate a new USB device 190 /** 191 * Enumerate a USB device. Move it to the addressed state, then explore it 192 * to create a DDF function node with proper characteristics. 187 193 */ 188 194 static int usb2_bus_device_enumerate(device_t *dev) … … 223 229 } 224 230 225 static endpoint_t *usb2_bus_create_ep(device_t *dev, const usb_endpoint_descriptors_t *desc) 226 { 227 endpoint_t *ep = malloc(sizeof(endpoint_t)); 228 if (!ep) 229 return NULL; 230 231 endpoint_init(ep, dev, desc); 232 return ep; 233 } 234 235 /** Register an endpoint to the bus. Reserves bandwidth. 236 * @param bus usb_bus structure, non-null. 237 * @param endpoint USB endpoint number. 231 /** 232 * Register an endpoint to the bus. Reserves bandwidth. 238 233 */ 239 234 static int usb2_bus_register_ep(endpoint_t *ep) … … 252 247 } 253 248 254 /** Release bandwidth reserved by the given endpoint. 249 /** 250 * Release bandwidth reserved by the given endpoint. 255 251 */ 256 252 static int usb2_bus_unregister_ep(endpoint_t *ep) … … 266 262 const bus_ops_t usb2_bus_ops = { 267 263 .device_enumerate = usb2_bus_device_enumerate, 268 .endpoint_create = usb2_bus_create_ep,269 264 .endpoint_register = usb2_bus_register_ep, 270 265 .endpoint_unregister = usb2_bus_unregister_ep, … … 275 270 * @param bus usb_bus structure, non-null. 276 271 * @param available_bandwidth Size of the bandwidth pool. 277 * @param bw_count function to use to calculate endpoint bw requirements.278 * @return Error code.279 272 */ 280 273 void usb2_bus_init(usb2_bus_t *bus, size_t available_bandwidth) … … 287 280 bus->free_bw = available_bandwidth; 288 281 } 282 289 283 /** 290 284 * @}
Note:
See TracChangeset
for help on using the changeset viewer.