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