Changeset 17412546 in mainline
- Timestamp:
- 2011-10-29T20:17:51Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c44a5f1
- Parents:
- 549ff23
- Location:
- uspace/lib/usbhost
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/endpoint.h
r549ff23 r17412546 41 41 #include <usb/usb.h> 42 42 43 /** Host controller side endpoint structure. */ 43 44 typedef struct endpoint { 45 /** Part of linked list. */ 44 46 link_t link; 47 /** USB address. */ 45 48 usb_address_t address; 49 /** USB endpoint number. */ 46 50 usb_endpoint_t endpoint; 51 /** Communication direction. */ 47 52 usb_direction_t direction; 53 /** USB transfer type. */ 48 54 usb_transfer_type_t transfer_type; 55 /** Communication speed. */ 49 56 usb_speed_t speed; 57 /** Maximum size of data packets. */ 50 58 size_t max_packet_size; 59 /** Necessary bandwidth. */ 51 60 size_t bandwidth; 61 /** Value of the toggle bit. */ 52 62 unsigned toggle:1; 63 /** True if there is a batch using this scheduled for this endpoint. */ 64 volatile bool active; 65 /** Protects resources and active status changes. */ 53 66 fibril_mutex_t guard; 67 /** Signals change of active status. */ 54 68 fibril_condvar_t avail; 55 volatile bool active;69 /** Optional device specific data. */ 56 70 struct { 71 /** Device specific data. */ 57 72 void *data; 73 /** Callback to get the value of toggle bit. */ 58 74 int (*toggle_get)(void *); 75 /** Callback to set the value of toggle bit. */ 59 76 void (*toggle_set)(void *, int); 60 77 } hc_data; … … 76 93 void endpoint_toggle_set(endpoint_t *instance, int toggle); 77 94 95 /** list_get_instance wrapper. 96 * @param item Pointer to link member. 97 * @return Pointer to enpoint_t structure. 98 */ 78 99 static inline endpoint_t * endpoint_get_instance(link_t *item) 79 100 { -
uspace/lib/usbhost/src/endpoint.c
r549ff23 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 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 */ 41 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, … … 60 69 fibril_mutex_initialize(&instance->guard); 61 70 fibril_condvar_initialize(&instance->avail); 62 endpoint_clear_hc_data(instance);63 71 } 64 72 return instance; 65 73 } 66 74 /*----------------------------------------------------------------------------*/ 75 /** Properly dispose of endpoint_t structure. 76 * @param instance endpoint_t structure. 77 */ 67 78 void endpoint_destroy(endpoint_t *instance) 68 79 { 69 80 assert(instance); 81 //TODO: Do something about waiting fibrils. 70 82 assert(!instance->active); 71 83 assert(instance->hc_data.data == NULL); … … 73 85 } 74 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 */ 75 93 void endpoint_set_hc_data(endpoint_t *instance, 76 94 void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int)) 77 95 { 78 96 assert(instance); 97 fibril_mutex_lock(&instance->guard); 79 98 instance->hc_data.data = data; 80 99 instance->hc_data.toggle_get = toggle_get; 81 100 instance->hc_data.toggle_set = toggle_set; 101 fibril_mutex_unlock(&instance->guard); 82 102 } 83 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 */ 84 108 void endpoint_clear_hc_data(endpoint_t *instance) 85 109 { 86 110 assert(instance); 111 fibril_mutex_lock(&instance->guard); 87 112 instance->hc_data.data = NULL; 88 113 instance->hc_data.toggle_get = NULL; 89 114 instance->hc_data.toggle_set = NULL; 115 fibril_mutex_unlock(&instance->guard); 90 116 } 91 117 /*----------------------------------------------------------------------------*/ 118 /** Mark the endpoint as active and block access for further fibrils. 119 * @param instance endpoint_t structure. 120 */ 92 121 void endpoint_use(endpoint_t *instance) 93 122 { … … 100 129 } 101 130 /*----------------------------------------------------------------------------*/ 131 /** Mark the endpoint as inactive and allow access for further fibrils. 132 * @param instance endpoint_t structure. 133 */ 102 134 void endpoint_release(endpoint_t *instance) 103 135 { … … 109 141 } 110 142 /*----------------------------------------------------------------------------*/ 143 /** Get the value of toggle bit. 144 * @param instance endpoint_t structure. 145 * @note Will use provided hook. 146 */ 111 147 int endpoint_toggle_get(endpoint_t *instance) 112 148 { 113 149 assert(instance); 150 fibril_mutex_lock(&instance->guard); 114 151 if (instance->hc_data.toggle_get) 115 152 instance->toggle = 116 153 instance->hc_data.toggle_get(instance->hc_data.data); 117 return (int)instance->toggle; 154 const int ret = instance->toggle; 155 fibril_mutex_unlock(&instance->guard); 156 return ret; 118 157 } 119 158 /*----------------------------------------------------------------------------*/ 159 /** Set the value of toggle bit. 160 * @param instance endpoint_t structure. 161 * @note Will use provided hook. 162 */ 120 163 void endpoint_toggle_set(endpoint_t *instance, int toggle) 121 164 { 122 165 assert(instance); 123 166 assert(toggle == 0 || toggle == 1); 167 fibril_mutex_lock(&instance->guard); 168 instance->toggle = toggle; 124 169 if (instance->hc_data.toggle_set) 125 170 instance->hc_data.toggle_set(instance->hc_data.data, toggle); 126 instance->toggle = toggle;171 fibril_mutex_unlock(&instance->guard); 127 172 } 128 173 /**
Note:
See TracChangeset
for help on using the changeset viewer.