Changes in uspace/lib/usbhost/src/endpoint.c [563d9d0a:17412546] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/endpoint.c
r563d9d0a r17412546 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 29 /** @addtogroup drvusbuhcihc 28 /** @addtogroup libusbhost 30 29 * @{ 31 30 */ … … 39 38 #include <usb/host/endpoint.h> 40 39 41 endpoint_t * endpoint_get(usb_address_t address, usb_endpoint_t endpoint, 40 /** Allocate ad initialize endpoint_t structure. 41 * @param address USB address. 42 * @param endpoint USB endpoint number. 43 * @param direction Communication direction. 44 * @param type USB transfer type. 45 * @param speed Communication speed. 46 * @param max_packet_size Maximum size of data packets. 47 * @param bw Required bandwidth. 48 * @return Pointer to initialized endpoint_t structure, NULL on failure. 49 */ 50 endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint, 42 51 usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed, 43 size_t max_packet_size )52 size_t max_packet_size, size_t bw) 44 53 { 45 54 endpoint_t *instance = malloc(sizeof(endpoint_t)); … … 51 60 instance->speed = speed; 52 61 instance->max_packet_size = max_packet_size; 62 instance->bandwidth = bw; 53 63 instance->toggle = 0; 54 64 instance->active = false; 55 instance->destroy_hook = NULL;56 65 instance->hc_data.data = NULL; 57 66 instance->hc_data.toggle_get = NULL; 58 67 instance->hc_data.toggle_set = NULL; 68 link_initialize(&instance->link); 59 69 fibril_mutex_initialize(&instance->guard); 60 70 fibril_condvar_initialize(&instance->avail); 61 endpoint_clear_hc_data(instance);62 71 } 63 72 return instance; 64 73 } 65 74 /*----------------------------------------------------------------------------*/ 75 /** Properly dispose of endpoint_t structure. 76 * @param instance endpoint_t structure. 77 */ 66 78 void endpoint_destroy(endpoint_t *instance) 67 79 { 68 80 assert(instance); 81 //TODO: Do something about waiting fibrils. 69 82 assert(!instance->active); 70 if (instance->hc_data.data) { 71 assert(instance->destroy_hook); 72 instance->destroy_hook(instance); 73 } 83 assert(instance->hc_data.data == NULL); 74 84 free(instance); 75 85 } 76 86 /*----------------------------------------------------------------------------*/ 87 /** Set device specific data and hooks. 88 * @param instance endpoint_t structure. 89 * @param data device specific data. 90 * @param toggle_get Hook to call when retrieving value of toggle bit. 91 * @param toggle_set Hook to call when setting the value of toggle bit. 92 */ 77 93 void endpoint_set_hc_data(endpoint_t *instance, 78 void *data, void (*destroy_hook)(endpoint_t *), 79 int (*toggle_get)(void *), void (*toggle_set)(void *, int)) 94 void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int)) 80 95 { 81 96 assert(instance); 82 instance->destroy_hook = destroy_hook;97 fibril_mutex_lock(&instance->guard); 83 98 instance->hc_data.data = data; 84 99 instance->hc_data.toggle_get = toggle_get; 85 100 instance->hc_data.toggle_set = toggle_set; 101 fibril_mutex_unlock(&instance->guard); 86 102 } 87 103 /*----------------------------------------------------------------------------*/ 104 /** Clear device specific data and hooks. 105 * @param instance endpoint_t structure. 106 * @note This function does not free memory pointed to by data pointer. 107 */ 88 108 void endpoint_clear_hc_data(endpoint_t *instance) 89 109 { 90 110 assert(instance); 91 instance->destroy_hook = NULL;111 fibril_mutex_lock(&instance->guard); 92 112 instance->hc_data.data = NULL; 93 113 instance->hc_data.toggle_get = NULL; 94 114 instance->hc_data.toggle_set = NULL; 115 fibril_mutex_unlock(&instance->guard); 95 116 } 96 117 /*----------------------------------------------------------------------------*/ 118 /** Mark the endpoint as active and block access for further fibrils. 119 * @param instance endpoint_t structure. 120 */ 97 121 void endpoint_use(endpoint_t *instance) 98 122 { … … 105 129 } 106 130 /*----------------------------------------------------------------------------*/ 131 /** Mark the endpoint as inactive and allow access for further fibrils. 132 * @param instance endpoint_t structure. 133 */ 107 134 void endpoint_release(endpoint_t *instance) 108 135 { … … 114 141 } 115 142 /*----------------------------------------------------------------------------*/ 143 /** Get the value of toggle bit. 144 * @param instance endpoint_t structure. 145 * @note Will use provided hook. 146 */ 116 147 int endpoint_toggle_get(endpoint_t *instance) 117 148 { 118 149 assert(instance); 150 fibril_mutex_lock(&instance->guard); 119 151 if (instance->hc_data.toggle_get) 120 152 instance->toggle = 121 153 instance->hc_data.toggle_get(instance->hc_data.data); 122 return (int)instance->toggle; 154 const int ret = instance->toggle; 155 fibril_mutex_unlock(&instance->guard); 156 return ret; 123 157 } 124 158 /*----------------------------------------------------------------------------*/ 159 /** Set the value of toggle bit. 160 * @param instance endpoint_t structure. 161 * @note Will use provided hook. 162 */ 125 163 void endpoint_toggle_set(endpoint_t *instance, int toggle) 126 164 { 127 165 assert(instance); 128 166 assert(toggle == 0 || toggle == 1); 167 fibril_mutex_lock(&instance->guard); 168 instance->toggle = toggle; 129 169 if (instance->hc_data.toggle_set) 130 170 instance->hc_data.toggle_set(instance->hc_data.data, toggle); 131 instance->toggle = toggle; 132 } 133 /*----------------------------------------------------------------------------*/ 134 void endpoint_toggle_reset_filtered(endpoint_t *instance, usb_target_t target) 135 { 136 assert(instance); 137 if (instance->address == target.address && 138 (instance->endpoint == target.endpoint || target.endpoint == 0)) 139 endpoint_toggle_set(instance, 0); 171 fibril_mutex_unlock(&instance->guard); 140 172 } 141 173 /**
Note:
See TracChangeset
for help on using the changeset viewer.