Changeset df6ded8 in mainline for uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h
- Timestamp:
- 2018-02-28T16:37:50Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1b20da0
- Parents:
- f5e5f73 (diff), b2dca8de (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Jakub Jermar <jakub@…> (2018-02-28 16:06:42)
- git-committer:
- Jakub Jermar <jakub@…> (2018-02-28 16:37:50)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h
rf5e5f73 rdf6ded8 1 1 /* 2 2 * Copyright (c) 2011 Jan Vesely 3 * Copyright (c) 2018 Ondrej Hlavaty 3 4 * All rights reserved. 4 5 * … … 37 38 #define LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H 38 39 39 #include <usb/host/endpoint.h> 40 #include <usb/usb.h> 41 42 #include <assert.h> 40 #include <atomic.h> 41 #include <errno.h> 43 42 #include <stddef.h> 44 43 #include <stdint.h> 44 #include <usb/dma_buffer.h> 45 #include <usb/request.h> 46 #include <usb/usb.h> 45 47 #include <usbhc_iface.h> 46 48 47 #define USB_SETUP_PACKET_SIZE 8 49 #include <usb/host/hcd.h> 50 #include <usb/host/endpoint.h> 51 #include <usb/host/bus.h> 52 53 typedef struct endpoint endpoint_t; 54 typedef struct bus bus_t; 48 55 49 56 /** Structure stores additional data needed for communication with EP */ 50 57 typedef struct usb_transfer_batch { 58 /** Target for communication */ 59 usb_target_t target; 60 /** Direction of the transfer */ 61 usb_direction_t dir; 62 51 63 /** Endpoint used for communication */ 52 64 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 /** Place for data to send/receive */ 60 char *buffer; 61 /** Size of memory pointed to by buffer member */ 62 size_t buffer_size; 65 63 66 /** Place to store SETUP data needed by control transfers */ 64 char setup_buffer[USB_SETUP_PACKET_SIZE]; 65 /** Used portion of setup_buffer member 66 * 67 * SETUP buffer must be 8 bytes for control transfers and is left 68 * unused for all other transfers. Thus, this field is either 0 or 8. 67 union { 68 char buffer [USB_SETUP_PACKET_SIZE]; 69 usb_device_request_setup_packet_t packet; 70 uint64_t packed; 71 } setup; 72 73 /** DMA buffer with enforced policy */ 74 dma_buffer_t dma_buffer; 75 /** Size of memory buffer */ 76 size_t offset, size; 77 78 /** 79 * In case a bounce buffer is allocated, the original buffer must to be 80 * stored to be filled after the IN transaction is finished. 69 81 */ 70 size_t setup_size; 82 char *original_buffer; 83 bool is_bounced; 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 */ 76 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 */ 85 /** Indicates success/failure of the communication */ 81 86 errno_t error; 87 /** Actually used portion of the buffer */ 88 size_t transferred_size; 89 90 /** Function called on completion */ 91 usbhc_iface_transfer_callback_t on_complete; 92 /** Arbitrary data for the handler */ 93 void *on_complete_data; 82 94 } usb_transfer_batch_t; 83 95 84 /** Printf formatting string for dumping usb_transfer_batch_t. */ 96 /** 97 * Printf formatting string for dumping usb_transfer_batch_t. 98 * [address:endpoint speed transfer_type-direction buffer_sizeB/max_packet_size] 99 * */ 85 100 #define USB_TRANSFER_BATCH_FMT "[%d:%d %s %s-%s %zuB/%zu]" 86 101 … … 89 104 */ 90 105 #define USB_TRANSFER_BATCH_ARGS(batch) \ 91 ( batch).ep->address, (batch).ep->endpoint, \92 usb_str_speed((batch).ep-> speed), \106 ((batch).ep->device->address), ((batch).ep->endpoint), \ 107 usb_str_speed((batch).ep->device->speed), \ 93 108 usb_str_transfer_type_short((batch).ep->transfer_type), \ 94 usb_str_direction((batch). ep->direction), \95 (batch). buffer_size, (batch).ep->max_packet_size109 usb_str_direction((batch).dir), \ 110 (batch).size, (batch).ep->max_packet_size 96 111 112 /** Wrapper for bus operation. */ 113 usb_transfer_batch_t *usb_transfer_batch_create(endpoint_t *); 97 114 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(usb_transfer_batch_t *instance); 115 /** Batch initializer. */ 116 void usb_transfer_batch_init(usb_transfer_batch_t *, endpoint_t *); 108 117 109 void usb_transfer_batch_finish_error(const usb_transfer_batch_t *instance, 110 const void* data, size_t size, errno_t error); 118 /** Buffer handling */ 119 bool usb_transfer_batch_bounce_required(usb_transfer_batch_t *); 120 errno_t usb_transfer_batch_bounce(usb_transfer_batch_t *); 111 121 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. 122 /** Batch finalization. */ 123 void usb_transfer_batch_finish(usb_transfer_batch_t *); 124 125 /** To be called from outside only when the transfer is not going to be finished 126 * (i.o.w. until successfuly scheduling) 116 127 */ 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 } 128 void usb_transfer_batch_destroy(usb_transfer_batch_t *); 149 129 150 130 #endif
Note:
See TracChangeset
for help on using the changeset viewer.