Ignore:
File:
1 edited

Legend:

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

    r0ee999d r56fd7cf  
    3838
    3939#include <assert.h>
    40 #include <adt/list.h>
    4140#include <usbhc_iface.h>
    4241
     42#include <usb/host/usb_device_manager.h>
    4343#include <usb/host/usb_endpoint_manager.h>
    4444#include <usb/host/usb_transfer_batch.h>
     
    4646typedef struct hcd hcd_t;
    4747
    48 typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *);
    49 typedef int (*ep_add_hook_t)(hcd_t *, endpoint_t *);
    50 typedef void (*ep_remove_hook_t)(hcd_t *, endpoint_t *);
    51 
    5248/** Generic host controller driver structure. */
    5349struct hcd {
     50        /** Device manager storing handles and addresses. */
     51        usb_device_manager_t dev_manager;
    5452        /** Endpoint manager. */
    5553        usb_endpoint_manager_t ep_manager;
     
    5856        void *private_data;
    5957        /** Transfer scheduling, implement in device driver. */
    60         schedule_hook_t schedule;
     58        int (*schedule)(hcd_t *, usb_transfer_batch_t *);
    6159        /** Hook called upon registering new endpoint. */
    62         ep_add_hook_t ep_add_hook;
     60        int (*ep_add_hook)(hcd_t *, endpoint_t *);
    6361        /** Hook called upon removing of an endpoint. */
    64         ep_remove_hook_t ep_remove_hook;
     62        void (*ep_remove_hook)(hcd_t *, endpoint_t *);
    6563};
    6664
    67 void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth,
    68     bw_count_func_t bw_count);
    69 
    70 static inline void hcd_set_implementation(hcd_t *hcd, void *data,
    71     schedule_hook_t schedule, ep_add_hook_t add_hook, ep_remove_hook_t rem_hook)
     65/** Initialize hcd_t structure.
     66 * Initializes device and endpoint managers. Sets data and hook pointer to NULL.
     67 * @param hcd hcd_t structure to initialize, non-null.
     68 * @param bandwidth Available bandwidth, passed to endpoint manager.
     69 * @param bw_count Bandwidth compute function, passed to endpoint manager.
     70 */
     71static inline void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth,
     72    size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t))
    7273{
    7374        assert(hcd);
    74         hcd->private_data = data;
    75         hcd->schedule = schedule;
    76         hcd->ep_add_hook = add_hook;
    77         hcd->ep_remove_hook = rem_hook;
     75        usb_device_manager_init(&hcd->dev_manager, max_speed);
     76        usb_endpoint_manager_init(&hcd->ep_manager, bandwidth, bw_count);
     77        hcd->private_data = NULL;
     78        hcd->schedule = NULL;
     79        hcd->ep_add_hook = NULL;
     80        hcd->ep_remove_hook = NULL;
    7881}
    7982
    80 usb_address_t hcd_request_address(hcd_t *hcd, usb_speed_t speed);
    81 
    82 int hcd_release_address(hcd_t *hcd, usb_address_t address);
    83 
    84 int hcd_reserve_default_address(hcd_t *hcd, usb_speed_t speed);
    85 
    86 static inline int hcd_release_default_address(hcd_t *hcd)
     83/** Check registered endpoints and reset toggle bit if necessary.
     84 * @param hcd hcd_t structure, non-null.
     85 * @param target Control communication target.
     86 * @param setup_data Setup packet of the control communication.
     87 */
     88static inline void reset_ep_if_need(hcd_t *hcd, usb_target_t target,
     89    const char setup_data[8])
    8790{
    88         return hcd_release_address(hcd, USB_ADDRESS_DEFAULT);
     91        assert(hcd);
     92        usb_endpoint_manager_reset_eps_if_need(
     93            &hcd->ep_manager, target, (const uint8_t *)setup_data);
    8994}
    9095
    91 int hcd_add_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir,
    92     usb_transfer_type_t type, size_t max_packet_size, size_t size,
    93     usb_address_t tt_address, unsigned tt_port);
     96/** Data retrieve wrapper.
     97 * @param fun ddf function, non-null.
     98 * @return pointer cast to hcd_t*.
     99 */
     100static inline hcd_t *fun_to_hcd(ddf_fun_t *fun)
     101{
     102        return ddf_fun_data_get(fun);
     103}
    94104
    95 int hcd_remove_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir);
    96 
    97 int hcd_send_batch(hcd_t *hcd, usb_target_t target, usb_direction_t direction,
    98     void *data, size_t size, uint64_t setup_data,
    99     usbhc_iface_transfer_in_callback_t in,
    100     usbhc_iface_transfer_out_callback_t out, void *arg, const char* name);
    101 
    102 ssize_t hcd_send_batch_sync(hcd_t *hcd, usb_target_t target,
    103     usb_direction_t dir, void *data, size_t size, uint64_t setup_data,
    104     const char* name);
     105extern usbhc_iface_t hcd_iface;
    105106
    106107#endif
     108
    107109/**
    108110 * @}
Note: See TracChangeset for help on using the changeset viewer.