Ignore:
Timestamp:
2017-10-21T20:52:56Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
766043c
Parents:
74b852b
Message:

usbhost refactoring: let transfer_batch be initialized by bus

Currently makes older HCs fail, work in progress.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h

    r74b852b r5fd9c30  
    3737#define LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
    3838
    39 #include <usb/host/endpoint.h>
    4039#include <usb/usb.h>
     40#include <usb/request.h>
    4141
    42 #include <assert.h>
    4342#include <stddef.h>
    4443#include <stdint.h>
     
    4746#define USB_SETUP_PACKET_SIZE 8
    4847
     48typedef struct endpoint endpoint_t;
     49typedef struct bus bus_t;
     50typedef struct usb_transfer_batch usb_transfer_batch_t;
     51
     52/** Callback to be called on transfer. */
     53typedef int (*usb_transfer_batch_callback_t)(usb_transfer_batch_t *);
     54
    4955/** Structure stores additional data needed for communication with EP */
    5056typedef struct usb_transfer_batch {
    5157        /** Endpoint used for communication */
    5258        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
    5980        /** Place for data to send/receive */
    6081        char *buffer;
    6182        /** Size of memory pointed to by buffer member */
    6283        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 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.
    69          */
    70         size_t setup_size;
    7184
    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 */
    7686        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 */
    8188        int error;
    8289} usb_transfer_batch_t;
     
    95102        (batch).buffer_size, (batch).ep->max_packet_size
    96103
     104void usb_transfer_batch_init(usb_transfer_batch_t *, endpoint_t *);
     105void usb_transfer_batch_finish(usb_transfer_batch_t *);
    97106
    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);
     107usb_transfer_batch_t *usb_transfer_batch_create(endpoint_t *);
     108void usb_transfer_batch_destroy(usb_transfer_batch_t *);
    108109
    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.
    116111 */
    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 }
     112extern 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 *);
    149115
    150116#endif
Note: See TracChangeset for help on using the changeset viewer.