Changes in uspace/lib/usbhost/src/endpoint.c [f527f58:9d58539] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/endpoint.c
rf527f58 r9d58539 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 29 28 /** @addtogroup libusbhost 30 29 * @{ … … 34 33 */ 35 34 36 #include <usb/host/endpoint.h>37 38 35 #include <assert.h> 39 36 #include <stdlib.h> 40 #include <atomic.h> 37 #include <errno.h> 38 #include <usb/host/endpoint.h> 41 39 42 40 /** Allocate ad initialize endpoint_t structure. … … 52 50 endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint, 53 51 usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed, 54 size_t max_packet_size, unsigned packets, size_t bw, 55 usb_address_t tt_address, unsigned tt_p) 52 size_t max_packet_size, size_t bw) 56 53 { 57 54 endpoint_t *instance = malloc(sizeof(endpoint_t)); 58 55 if (instance) { 59 atomic_set(&instance->refcnt, 0);60 56 instance->address = address; 61 57 instance->endpoint = endpoint; … … 64 60 instance->speed = speed; 65 61 instance->max_packet_size = max_packet_size; 66 instance->packets = packets;67 62 instance->bandwidth = bw; 68 63 instance->toggle = 0; 69 64 instance->active = false; 70 instance->tt.address = tt_address;71 instance->tt.port = tt_p;72 65 instance->hc_data.data = NULL; 73 66 instance->hc_data.toggle_get = NULL; … … 79 72 return instance; 80 73 } 81 74 /*----------------------------------------------------------------------------*/ 82 75 /** Properly dispose of endpoint_t structure. 83 76 * @param instance endpoint_t structure. … … 86 79 { 87 80 assert(instance); 81 //TODO: Do something about waiting fibrils. 88 82 assert(!instance->active); 89 83 assert(instance->hc_data.data == NULL); 90 84 free(instance); 91 85 } 92 93 void endpoint_add_ref(endpoint_t *instance) 94 { 95 atomic_inc(&instance->refcnt); 96 } 97 98 void endpoint_del_ref(endpoint_t *instance) 99 { 100 if (atomic_predec(&instance->refcnt) == 0) 101 endpoint_destroy(instance); 102 } 103 86 /*----------------------------------------------------------------------------*/ 104 87 /** Set device specific data and hooks. 105 88 * @param instance endpoint_t structure. … … 118 101 fibril_mutex_unlock(&instance->guard); 119 102 } 120 103 /*----------------------------------------------------------------------------*/ 121 104 /** Clear device specific data and hooks. 122 105 * @param instance endpoint_t structure. … … 126 109 { 127 110 assert(instance); 128 endpoint_set_hc_data(instance, NULL, NULL, NULL); 111 fibril_mutex_lock(&instance->guard); 112 instance->hc_data.data = NULL; 113 instance->hc_data.toggle_get = NULL; 114 instance->hc_data.toggle_set = NULL; 115 fibril_mutex_unlock(&instance->guard); 129 116 } 130 117 /*----------------------------------------------------------------------------*/ 131 118 /** Mark the endpoint as active and block access for further fibrils. 132 119 * @param instance endpoint_t structure. … … 135 122 { 136 123 assert(instance); 137 /* Add reference for active endpoint. */138 endpoint_add_ref(instance);139 124 fibril_mutex_lock(&instance->guard); 140 125 while (instance->active) … … 143 128 fibril_mutex_unlock(&instance->guard); 144 129 } 145 130 /*----------------------------------------------------------------------------*/ 146 131 /** Mark the endpoint as inactive and allow access for further fibrils. 147 132 * @param instance endpoint_t structure. … … 154 139 fibril_mutex_unlock(&instance->guard); 155 140 fibril_condvar_signal(&instance->avail); 156 /* Drop reference for active endpoint. */157 endpoint_del_ref(instance);158 141 } 159 142 /*----------------------------------------------------------------------------*/ 160 143 /** Get the value of toggle bit. 161 144 * @param instance endpoint_t structure. … … 173 156 return ret; 174 157 } 175 158 /*----------------------------------------------------------------------------*/ 176 159 /** Set the value of toggle bit. 177 160 * @param instance endpoint_t structure. … … 188 171 fibril_mutex_unlock(&instance->guard); 189 172 } 190 191 173 /** 192 174 * @}
Note:
See TracChangeset
for help on using the changeset viewer.