Changeset 5fd9c30 in mainline for uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.