Changes in uspace/lib/usbhost/src/endpoint.c [3e4f2e0:563d9d0a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/endpoint.c
r3e4f2e0 r563d9d0a 35 35 36 36 #include <assert.h> 37 #include <stdlib.h> 37 38 #include <errno.h> 38 39 #include <usb/host/endpoint.h> 39 40 40 int endpoint_init(endpoint_t *instance, usb_address_t address,41 usb_ endpoint_t endpoint, usb_direction_t direction,42 usb_transfer_type_t type, usb_speed_t speed,size_t max_packet_size)41 endpoint_t * endpoint_get(usb_address_t address, usb_endpoint_t endpoint, 42 usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed, 43 size_t max_packet_size) 43 44 { 44 assert(instance); 45 instance->address = address; 46 instance->endpoint = endpoint; 47 instance->direction = direction; 48 instance->transfer_type = type; 49 instance->speed = speed; 50 instance->max_packet_size = max_packet_size; 51 instance->toggle = 0; 52 instance->active = false; 53 fibril_mutex_initialize(&instance->guard); 54 fibril_condvar_initialize(&instance->avail); 55 endpoint_clear_hc_data(instance); 56 return EOK; 45 endpoint_t *instance = malloc(sizeof(endpoint_t)); 46 if (instance) { 47 instance->address = address; 48 instance->endpoint = endpoint; 49 instance->direction = direction; 50 instance->transfer_type = type; 51 instance->speed = speed; 52 instance->max_packet_size = max_packet_size; 53 instance->toggle = 0; 54 instance->active = false; 55 instance->destroy_hook = NULL; 56 instance->hc_data.data = NULL; 57 instance->hc_data.toggle_get = NULL; 58 instance->hc_data.toggle_set = NULL; 59 fibril_mutex_initialize(&instance->guard); 60 fibril_condvar_initialize(&instance->avail); 61 endpoint_clear_hc_data(instance); 62 } 63 return instance; 57 64 } 58 65 /*----------------------------------------------------------------------------*/ … … 61 68 assert(instance); 62 69 assert(!instance->active); 70 if (instance->hc_data.data) { 71 assert(instance->destroy_hook); 72 instance->destroy_hook(instance); 73 } 63 74 free(instance); 64 75 } 65 76 /*----------------------------------------------------------------------------*/ 66 77 void endpoint_set_hc_data(endpoint_t *instance, 67 void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int)) 78 void *data, void (*destroy_hook)(endpoint_t *), 79 int (*toggle_get)(void *), void (*toggle_set)(void *, int)) 68 80 { 69 81 assert(instance); 82 instance->destroy_hook = destroy_hook; 70 83 instance->hc_data.data = data; 71 84 instance->hc_data.toggle_get = toggle_get; … … 76 89 { 77 90 assert(instance); 91 instance->destroy_hook = NULL; 78 92 instance->hc_data.data = NULL; 79 93 instance->hc_data.toggle_get = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.