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