Changeset 5fd9c30 in mainline for uspace/lib/usbhost/include
- Timestamp:
- 2017-10-21T20:52:56Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 766043c
- Parents:
- 74b852b
- Location:
- uspace/lib/usbhost/include/usb/host
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/bus.h
r74b852b r5fd9c30 33 33 * 34 34 * The purpose of this structure is to keep information about connected devices 35 * and en points, manage available bandwidth and the toggle bit flipping.35 * and endpoints, manage available bandwidth and the toggle bit flipping. 36 36 * 37 37 * The generic implementation is provided for USB 1 and 2 in usb2_bus.c. Some … … 53 53 typedef struct bus bus_t; 54 54 typedef struct ddf_fun ddf_fun_t; 55 typedef struct usb_transfer_batch usb_transfer_batch_t; 55 56 56 57 typedef struct device { … … 85 86 int (*release_endpoint)(bus_t *, endpoint_t *); 86 87 endpoint_t *(*find_endpoint)(bus_t *, usb_target_t, usb_direction_t); 88 void (*destroy_endpoint)(endpoint_t *); /**< Optional */ 89 bool (*endpoint_get_toggle)(endpoint_t *); /**< Optional */ 90 void (*endpoint_set_toggle)(endpoint_t *, bool); /**< Optional */ 87 91 88 92 int (*request_address)(bus_t *, usb_address_t*, bool, usb_speed_t); … … 93 97 size_t (*count_bw) (endpoint_t *, size_t); 94 98 95 /* Endpoint ops, optional (have generic fallback) */ 96 void (*destroy_endpoint)(endpoint_t *); 97 bool (*endpoint_get_toggle)(endpoint_t *); 98 void (*endpoint_set_toggle)(endpoint_t *, bool); 99 usb_transfer_batch_t *(*create_batch)(bus_t *, endpoint_t *); /**< Optional */ 100 void (*destroy_batch)(usb_transfer_batch_t *); /**< Optional */ 99 101 } bus_ops_t; 100 102 … … 135 137 int bus_release_address(bus_t *, usb_address_t); 136 138 139 137 140 static inline int bus_reserve_default_address(bus_t *bus, usb_speed_t speed) { 138 141 usb_address_t addr = USB_ADDRESS_DEFAULT; -
uspace/lib/usbhost/include/usb/host/endpoint.h
r74b852b r5fd9c30 48 48 typedef struct bus bus_t; 49 49 typedef struct device device_t; 50 typedef struct usb_transfer_batch usb_transfer_batch_t; 50 51 51 52 /** Host controller side endpoint structure. */ -
uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h
r74b852b r5fd9c30 37 37 #define LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H 38 38 39 #include <usb/host/endpoint.h>40 39 #include <usb/usb.h> 40 #include <usb/request.h> 41 41 42 #include <assert.h>43 42 #include <stddef.h> 44 43 #include <stdint.h> … … 47 46 #define USB_SETUP_PACKET_SIZE 8 48 47 48 typedef struct endpoint endpoint_t; 49 typedef struct bus bus_t; 50 typedef struct usb_transfer_batch usb_transfer_batch_t; 51 52 /** Callback to be called on transfer. */ 53 typedef int (*usb_transfer_batch_callback_t)(usb_transfer_batch_t *); 54 49 55 /** Structure stores additional data needed for communication with EP */ 50 56 typedef struct usb_transfer_batch { 51 57 /** Endpoint used for communication */ 52 58 endpoint_t *ep; 53 /** Function called on completion (IN version) */ 54 usbhc_iface_transfer_in_callback_t callback_in; 55 /** Function called on completion (OUT version) */ 56 usbhc_iface_transfer_out_callback_t callback_out; 57 /** Argument to pass to the completion function */ 58 void *arg; 59 /** Size reported to be sent */ 60 size_t expected_size; 61 62 /** Direction of the transfer */ 63 usb_direction_t dir; 64 65 /** Function called on completion */ 66 usb_transfer_batch_callback_t on_complete; 67 /** Arbitrary data for the handler */ 68 void *on_complete_data; 69 70 /** Place to store SETUP data needed by control transfers */ 71 union { 72 char buffer [USB_SETUP_PACKET_SIZE]; 73 usb_device_request_setup_packet_t packet; 74 uint64_t packed; 75 } setup; 76 77 /** Resetting the Toggle */ 78 toggle_reset_mode_t toggle_reset_mode; 79 59 80 /** Place for data to send/receive */ 60 81 char *buffer; 61 82 /** Size of memory pointed to by buffer member */ 62 83 size_t buffer_size; 63 /** Place to store SETUP data needed by control transfers */64 char setup_buffer[USB_SETUP_PACKET_SIZE];65 /** Used portion of setup_buffer member66 *67 * SETUP buffer must be 8 bytes for control transfers and is left68 * unused for all other transfers. Thus, this field is either 0 or 8.69 */70 size_t setup_size;71 84 72 /** Actually used portion of the buffer 73 * This member is never accessed by functions provided in this header, 74 * with the exception of usb_transfer_batch_finish. For external use. 75 */ 85 /** Actually used portion of the buffer */ 76 86 size_t transfered_size; 77 /** Indicates success/failure of the communication 78 * This member is never accessed by functions provided in this header, 79 * with the exception of usb_transfer_batch_finish. For external use. 80 */ 87 /** Indicates success/failure of the communication */ 81 88 int error; 82 89 } usb_transfer_batch_t; … … 95 102 (batch).buffer_size, (batch).ep->max_packet_size 96 103 104 void usb_transfer_batch_init(usb_transfer_batch_t *, endpoint_t *); 105 void usb_transfer_batch_finish(usb_transfer_batch_t *); 97 106 98 usb_transfer_batch_t * usb_transfer_batch_create( 99 endpoint_t *ep, 100 char *buffer, 101 size_t buffer_size, 102 uint64_t setup_buffer, 103 usbhc_iface_transfer_in_callback_t func_in, 104 usbhc_iface_transfer_out_callback_t func_out, 105 void *arg 106 ); 107 void usb_transfer_batch_destroy(const usb_transfer_batch_t *instance); 107 usb_transfer_batch_t *usb_transfer_batch_create(endpoint_t *); 108 void usb_transfer_batch_destroy(usb_transfer_batch_t *); 108 109 109 void usb_transfer_batch_finish_error(const usb_transfer_batch_t *instance, 110 const void* data, size_t size, int error); 111 112 /** Finish batch using stored error value and transferred size. 113 * 114 * @param[in] instance Batch structure to use. 115 * @param[in] data Data to copy to the output buffer. 110 /** Provided to ease the transition. Wraps old-style handlers into a new one. 116 111 */ 117 static inline void usb_transfer_batch_finish( 118 const usb_transfer_batch_t *instance, const void* data) 119 { 120 assert(instance); 121 usb_transfer_batch_finish_error( 122 instance, data, instance->transfered_size, instance->error); 123 } 124 125 /** Determine batch direction based on the callbacks present 126 * @param[in] instance Batch structure to use, non-null. 127 * @return USB_DIRECTION_IN, or USB_DIRECTION_OUT. 128 */ 129 static inline usb_direction_t usb_transfer_batch_direction( 130 const usb_transfer_batch_t *instance) 131 { 132 assert(instance); 133 if (instance->callback_in) { 134 assert(instance->callback_out == NULL); 135 assert(instance->ep == NULL 136 || instance->ep->transfer_type == USB_TRANSFER_CONTROL 137 || instance->ep->direction == USB_DIRECTION_IN); 138 return USB_DIRECTION_IN; 139 } 140 if (instance->callback_out) { 141 assert(instance->callback_in == NULL); 142 assert(instance->ep == NULL 143 || instance->ep->transfer_type == USB_TRANSFER_CONTROL 144 || instance->ep->direction == USB_DIRECTION_OUT); 145 return USB_DIRECTION_OUT; 146 } 147 assert(false); 148 } 112 extern void usb_transfer_batch_set_old_handlers(usb_transfer_batch_t *, 113 usbhc_iface_transfer_in_callback_t, 114 usbhc_iface_transfer_out_callback_t, void *); 149 115 150 116 #endif
Note:
See TracChangeset
for help on using the changeset viewer.