Changeset 6832245 in mainline for uspace/lib/usbhost/src/endpoint.c
- Timestamp:
- 2017-12-14T23:01:57Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 837d53d
- Parents:
- bd05140
- git-author:
- Ondřej Hlavatý <aearsis@…> (2017-12-14 23:01:54)
- git-committer:
- Ondřej Hlavatý <aearsis@…> (2017-12-14 23:01:57)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/endpoint.c
rbd05140 r6832245 47 47 /** Initialize provided endpoint structure. 48 48 */ 49 void endpoint_init(endpoint_t *ep, bus_t *bus)49 void endpoint_init(endpoint_t *ep, device_t *dev, const usb_endpoint_desc_t *desc) 50 50 { 51 51 memset(ep, 0, sizeof(endpoint_t)); 52 52 53 ep->bus = bus; 53 assert(dev); 54 ep->device = dev; 55 54 56 atomic_set(&ep->refcnt, 0); 55 57 link_initialize(&ep->link); 56 58 fibril_mutex_initialize(&ep->guard); 57 59 fibril_condvar_initialize(&ep->avail); 60 61 ep->endpoint = desc->endpoint_no; 62 ep->direction = desc->direction; 63 ep->transfer_type = desc->transfer_type; 64 ep->max_packet_size = desc->max_packet_size; 65 ep->packets = desc->packets; 66 67 ep->bandwidth = endpoint_count_bw(ep, desc->max_packet_size); 68 } 69 70 static inline const bus_ops_t *get_bus_ops(endpoint_t *ep) 71 { 72 return ep->device->bus->ops; 58 73 } 59 74 … … 63 78 } 64 79 80 static inline void endpoint_destroy(endpoint_t *ep) 81 { 82 const bus_ops_t *ops = BUS_OPS_LOOKUP(get_bus_ops(ep), endpoint_destroy); 83 if (ops) { 84 ops->endpoint_destroy(ep); 85 } else { 86 assert(ep->active_batch == NULL); 87 88 /* Assume mostly the eps will be allocated by malloc. */ 89 free(ep); 90 } 91 } 92 65 93 void endpoint_del_ref(endpoint_t *ep) 66 94 { 67 95 if (atomic_predec(&ep->refcnt) == 0) { 68 if (ep->bus->ops.destroy_endpoint) { 69 ep->bus->ops.destroy_endpoint(ep); 70 } 71 else { 72 assert(ep->active_batch == NULL); 73 74 /* Assume mostly the eps will be allocated by malloc. */ 75 free(ep); 76 } 96 endpoint_destroy(ep); 77 97 } 78 98 } … … 133 153 assert(ep); 134 154 135 return ep->bus->ops.endpoint_get_toggle 136 ? ep->bus->ops.endpoint_get_toggle(ep) 155 const bus_ops_t *ops = BUS_OPS_LOOKUP(get_bus_ops(ep), endpoint_get_toggle); 156 return ops 157 ? ops->endpoint_get_toggle(ep) 137 158 : ep->toggle; 138 159 } … … 146 167 assert(ep); 147 168 148 if (ep->bus->ops.endpoint_set_toggle) { 149 ep->bus->ops.endpoint_set_toggle(ep, toggle); 169 const bus_ops_t *ops = BUS_OPS_LOOKUP(get_bus_ops(ep), endpoint_set_toggle); 170 if (ops) { 171 ops->endpoint_set_toggle(ep, toggle); 150 172 } 151 173 else { … … 154 176 } 155 177 178 ssize_t endpoint_count_bw(endpoint_t *ep, size_t packet_size) 179 { 180 assert(ep); 181 182 const bus_ops_t *ops = BUS_OPS_LOOKUP(get_bus_ops(ep), endpoint_count_bw); 183 if (!ops) 184 return 0; 185 186 return ops->endpoint_count_bw(ep, packet_size); 187 } 188 156 189 /** 157 190 * @}
Note:
See TracChangeset
for help on using the changeset viewer.