Changeset 8dc762e0 in mainline for uspace/lib/usb/src
- Timestamp:
- 2011-04-06T21:12:41Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f567bcf
- Parents:
- 1e70157
- Location:
- uspace/lib/usb/src/host
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/host/device_keeper.c
r1e70157 r8dc762e0 63 63 /*----------------------------------------------------------------------------*/ 64 64 void usb_device_keeper_add_ep( 65 usb_device_keeper_t *instance, usb_address_t address, link_t *ep); 65 usb_device_keeper_t *instance, usb_address_t address, link_t *ep) 66 { 67 assert(instance); 68 fibril_mutex_lock(&instance->guard); 69 assert(instance->devices[address].occupied); 70 list_append(ep, &instance->devices[address].endpoints); 71 fibril_mutex_unlock(&instance->guard); 72 } 66 73 /*----------------------------------------------------------------------------*/ 67 74 /** Attempt to obtain address 0, blocks. -
uspace/lib/usb/src/host/endpoint.c
r1e70157 r8dc762e0 36 36 #include <errno.h> 37 37 38 #include "endpoint.h" 39 #include "utils/malloc32.h" 38 #include <usb/host/endpoint.h> 40 39 41 40 int endpoint_init(endpoint_t *instance, usb_transfer_type_t transfer_type, … … 48 47 instance->max_packet_size = max_packet_size; 49 48 instance->toggle = 0; 50 instance->qh = malloc32(sizeof(qh_t));51 if (instance->qh == NULL)52 return ENOMEM;53 49 return EOK; 54 50 } 55 51 /*----------------------------------------------------------------------------*/ 56 void endpoint_destroy( void *ep)52 void endpoint_destroy(endpoint_t *instance) 57 53 { 58 endpoint_t *instance = ep;59 54 assert(instance); 60 55 list_remove(&instance->same_device_eps); 61 free32(instance->qh);62 56 free(instance); 63 57 } -
uspace/lib/usb/src/host/usb_endpoint_manager.c
r1e70157 r8dc762e0 48 48 link_t link; 49 49 size_t bw; 50 void *data; 51 void (*data_remove_callback)(void* data); 52 } ep_t; 53 /*----------------------------------------------------------------------------*/ 54 static hash_index_t ep_hash(unsigned long key[]) 50 endpoint_t *ep; 51 } node_t; 52 /*----------------------------------------------------------------------------*/ 53 static hash_index_t node_hash(unsigned long key[]) 55 54 { 56 55 hash_index_t hash = 0; … … 63 62 } 64 63 /*----------------------------------------------------------------------------*/ 65 static int ep_compare(unsigned long key[], hash_count_t keys, link_t *item)64 static int node_compare(unsigned long key[], hash_count_t keys, link_t *item) 66 65 { 67 66 assert(item); 68 ep_t *ep = hash_table_get_instance(item, ep_t, link);67 node_t *node = hash_table_get_instance(item, node_t, link); 69 68 hash_count_t i = 0; 70 69 for (; i < keys; ++i) { 71 if (key[i] != ep->key[i])70 if (key[i] != node->key[i]) 72 71 return false; 73 72 } … … 75 74 } 76 75 /*----------------------------------------------------------------------------*/ 77 static void ep_remove(link_t *item)76 static void node_remove(link_t *item) 78 77 { 79 78 assert(item); 80 ep_t *ep = 81 hash_table_get_instance(item, ep_t, link); 82 ep->data_remove_callback(ep->data); 83 free(ep); 79 node_t *node = hash_table_get_instance(item, node_t, link); 80 endpoint_destroy(node->ep); 81 free(node); 84 82 } 85 83 /*----------------------------------------------------------------------------*/ 86 84 static hash_table_operations_t op = { 87 .hash = ep_hash,88 .compare = ep_compare,89 .remove_callback = ep_remove,85 .hash = node_hash, 86 .compare = node_compare, 87 .remove_callback = node_remove, 90 88 }; 91 89 /*----------------------------------------------------------------------------*/ … … 145 143 int usb_endpoint_manager_register_ep(usb_endpoint_manager_t *instance, 146 144 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 147 void *data, void (*data_remove_callback)(void* data), size_t bw) 148 { 145 endpoint_t *ep, size_t data_size) 146 { 147 assert(ep); 148 size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type, 149 data_size, ep->max_packet_size); 149 150 assert(instance); 150 151 … … 168 169 } 169 170 170 ep_t *ep = malloc(sizeof(ep_t));171 if ( ep== NULL) {171 node_t *node = malloc(sizeof(node_t)); 172 if (node == NULL) { 172 173 fibril_mutex_unlock(&instance->guard); 173 174 return ENOMEM; 174 175 } 175 176 176 ep->id = id; 177 ep->bw = bw; 178 ep->data = data; 179 link_initialize(&ep->link); 180 181 hash_table_insert(&instance->ep_table, (unsigned long*)&id, &ep->link); 177 node->id = id; 178 node->bw = bw; 179 node->ep = ep; 180 link_initialize(&node->link); 181 182 hash_table_insert(&instance->ep_table, 183 (unsigned long*)&id, &node->link); 182 184 instance->free_bw -= bw; 183 185 fibril_mutex_unlock(&instance->guard); … … 203 205 } 204 206 205 ep_t *ep = hash_table_get_instance(item, ep_t, link);206 instance->free_bw += ep->bw;207 node_t *node = hash_table_get_instance(item, node_t, link); 208 instance->free_bw += node->bw; 207 209 hash_table_remove(&instance->ep_table, (unsigned long*)&id, MAX_KEYS); 208 210 … … 212 214 } 213 215 /*----------------------------------------------------------------------------*/ 214 void * usb_endpoint_manager_get_ep_data(usb_endpoint_manager_t *instance,216 endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance, 215 217 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 216 218 size_t *bw) … … 229 231 return NULL; 230 232 } 231 ep_t *ep = hash_table_get_instance(item, ep_t, link);233 node_t *node = hash_table_get_instance(item, node_t, link); 232 234 if (bw) 233 *bw = ep->bw;235 *bw = node->bw; 234 236 235 237 fibril_mutex_unlock(&instance->guard); 236 return ep->data;237 } 238 return node->ep; 239 }
Note:
See TracChangeset
for help on using the changeset viewer.