Changeset 41924f30 in mainline for uspace/lib/usbhost/src/hcd.c
- Timestamp:
- 2017-10-12T14:07:27Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a5976973
- Parents:
- 7e74911
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/hcd.c
r7e74911 r41924f30 44 44 #include "hcd.h" 45 45 46 /** Calls ep_add_hook upon endpoint registration. 46 47 /*[>* Calls ep_add_hook upon endpoint registration. 47 48 * @param ep Endpoint to be registered. 48 49 * @param arg hcd_t in disguise. 49 50 * @return Error code. 50 */ 51 * OH TODO: remove 52 <] 51 53 static int register_helper(endpoint_t *ep, void *arg) 52 54 { … … 59 61 } 60 62 61 /** Calls ep_remove_hook upon endpoint removal.63 [>* Calls ep_remove_hook upon endpoint removal. 62 64 * @param ep Endpoint to be unregistered. 63 65 * @param arg hcd_t in disguise. 64 */ 66 * OH TODO: remove 67 <] 65 68 static void unregister_helper(endpoint_t *ep, void *arg) 66 69 { … … 72 75 } 73 76 74 /** Calls ep_remove_hook upon endpoint removal. Prints warning.77 [>* Calls ep_remove_hook upon endpoint removal. Prints warning. 75 78 * * @param ep Endpoint to be unregistered. 76 79 * * @param arg hcd_t in disguise. 77 * */ 80 * OH TODO: remove 81 * <] 78 82 static void unregister_helper_warn(endpoint_t *ep, void *arg) 79 83 { 80 84 assert(ep); 81 85 usb_log_warning("Endpoint %d:%d %s was left behind, removing.\n", 82 ep-> address, ep->endpoint, usb_str_direction(ep->direction));86 ep->target.address, ep->target.endpoint, usb_str_direction(ep->direction)); 83 87 unregister_helper(ep, arg); 84 88 } 85 89 */ 86 90 87 91 /** Initialize hcd_t structure. … … 93 97 * @param bw_count Bandwidth compute function, passed to endpoint manager. 94 98 */ 95 void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth, 96 bw_count_func_t bw_count) 97 { 98 assert(hcd); 99 usb_bus_init(&hcd->bus, bandwidth, bw_count, max_speed); 100 101 hcd_set_implementation(hcd, NULL, NULL); 99 void hcd_init(hcd_t *hcd) { 100 assert(hcd); 101 102 hcd_set_implementation(hcd, NULL, NULL, NULL); 102 103 } 103 104 … … 106 107 assert(hcd); 107 108 usb_address_t address = 0; 108 const int ret = usb_bus_request_address( 109 &hcd->bus, &address, false, speed); 109 const int ret = bus_request_address(hcd->bus, &address, false, speed); 110 110 if (ret != EOK) 111 111 return ret; … … 116 116 { 117 117 assert(hcd); 118 return usb_bus_remove_address(&hcd->bus, address,119 unregister_helper_warn, hcd);118 return bus_release_address(hcd->bus, address); 119 // OH TODO removed helper 120 120 } 121 121 … … 124 124 assert(hcd); 125 125 usb_address_t address = 0; 126 return usb_bus_request_address(&hcd->bus, &address, true, speed);126 return bus_request_address(hcd->bus, &address, true, speed); 127 127 } 128 128 … … 132 132 { 133 133 assert(hcd); 134 return usb_bus_add_ep(&hcd->bus, target.address, 135 target.endpoint, dir, type, max_packet_size, packets, size, 136 register_helper, hcd, tt_address, tt_port); 134 135 /* Temporary reference */ 136 endpoint_t *ep = bus_create_endpoint(hcd->bus); 137 if (!ep) 138 return ENOMEM; 139 140 ep->target = target; 141 ep->direction = dir; 142 ep->transfer_type = type; 143 ep->max_packet_size = max_packet_size; 144 ep->packets = packets; 145 146 ep->tt.address = tt_address; 147 ep->tt.port = tt_port; 148 149 const int err = bus_register_endpoint(hcd->bus, ep); 150 151 /* drop Temporary reference */ 152 endpoint_del_ref(ep); 153 154 return err; 137 155 } 138 156 … … 140 158 { 141 159 assert(hcd); 142 return usb_bus_remove_ep(&hcd->bus, target.address, 143 target.endpoint, dir, unregister_helper, hcd); 160 endpoint_t *ep = bus_find_endpoint(hcd->bus, target, dir); 161 if (!ep) 162 return ENOENT; 163 164 return bus_release_endpoint(hcd->bus, ep); 165 // OH TODO removed helper 144 166 } 145 167 … … 159 181 usb_log_debug2("Reseting toggle on %d:%d.\n", 160 182 toggle->target.address, toggle->target.endpoint); 161 usb_bus_reset_toggle(&toggle->hcd->bus,183 bus_reset_toggle(toggle->hcd->bus, 162 184 toggle->target, toggle->target.endpoint == 0); 163 185 } … … 185 207 assert(hcd); 186 208 187 endpoint_t *ep = usb_bus_find_ep(&hcd->bus, 188 target.address, target.endpoint, direction); 209 endpoint_t *ep = bus_find_endpoint(hcd->bus, target, direction); 189 210 if (ep == NULL) { 190 211 usb_log_error("Endpoint(%d:%d) not registered for %s.\n", … … 196 217 name, target.address, target.endpoint, size, ep->max_packet_size); 197 218 198 const size_t bw = bandwidth_count_usb11( 199 ep->speed, ep->transfer_type, size, ep->max_packet_size); 219 const size_t bw = bus_count_bw(ep, size); 200 220 /* Check if we have enough bandwidth reserved */ 201 221 if (ep->bandwidth < bw) { 202 222 usb_log_error("Endpoint(%d:%d) %s needs %zu bw " 203 223 "but only %zu is reserved.\n", 204 ep-> address, ep->endpoint, name, bw, ep->bandwidth);224 ep->target.address, ep->target.endpoint, name, bw, ep->bandwidth); 205 225 return ENOSPC; 206 226 }
Note:
See TracChangeset
for help on using the changeset viewer.