Changeset 5fd9c30 in mainline for uspace/lib/usbhost/include


Ignore:
Timestamp:
2017-10-21T20:52:56Z (8 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.

Location:
uspace/lib/usbhost/include/usb/host
Files:
3 edited

Legend:

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

    r74b852b r5fd9c30  
    3333 *
    3434 * The purpose of this structure is to keep information about connected devices
    35  * and enpoints, manage available bandwidth and the toggle bit flipping.
     35 * and endpoints, manage available bandwidth and the toggle bit flipping.
    3636 *
    3737 * The generic implementation is provided for USB 1 and 2 in usb2_bus.c. Some
     
    5353typedef struct bus bus_t;
    5454typedef struct ddf_fun ddf_fun_t;
     55typedef struct usb_transfer_batch usb_transfer_batch_t;
    5556
    5657typedef struct device {
     
    8586        int (*release_endpoint)(bus_t *, endpoint_t *);
    8687        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 */
    8791
    8892        int (*request_address)(bus_t *, usb_address_t*, bool, usb_speed_t);
     
    9397        size_t (*count_bw) (endpoint_t *, size_t);
    9498
    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 */
    99101} bus_ops_t;
    100102
     
    135137int bus_release_address(bus_t *, usb_address_t);
    136138
     139
    137140static inline int bus_reserve_default_address(bus_t *bus, usb_speed_t speed) {
    138141        usb_address_t addr = USB_ADDRESS_DEFAULT;
  • uspace/lib/usbhost/include/usb/host/endpoint.h

    r74b852b r5fd9c30  
    4848typedef struct bus bus_t;
    4949typedef struct device device_t;
     50typedef struct usb_transfer_batch usb_transfer_batch_t;
    5051
    5152/** Host controller side endpoint structure. */
  • 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.