source: mainline/uspace/lib/usbhost/include/usb/host/hcd.h@ 30ec5ea

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 30ec5ea was 7711296, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

libusbhost, libusbdev: Minor fixes.

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[45d105a]1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libusbhost
30 * @{
31 */
32/** @file
33 *
34 */
35#ifndef LIBUSBHOST_HOST_HCD_H
36#define LIBUSBHOST_HOST_HCD_H
37
38#include <assert.h>
[7265558]39#include <usbhc_iface.h>
[4dfc905]40
[8b54fe6]41#include <usb/host/usb_device_manager.h>
[45d105a]42#include <usb/host/usb_endpoint_manager.h>
[f58ef61]43#include <usb/host/usb_transfer_batch.h>
[45d105a]44
45typedef struct hcd hcd_t;
46
[4dfc905]47/** Generic host controller driver structure. */
[45d105a]48struct hcd {
[4dfc905]49 /** Device manager storing handles and addresses. */
[8b54fe6]50 usb_device_manager_t dev_manager;
[4dfc905]51 /** Endpoint manager. */
[45d105a]52 usb_endpoint_manager_t ep_manager;
53
[4dfc905]54 /** Device specific driver data. */
55 void *private_data;
56 /** Transfer scheduling, implement in device driver. */
[45d105a]57 int (*schedule)(hcd_t *, usb_transfer_batch_t *);
[4dfc905]58 /** Hook called upon registering new endpoint. */
[4f0e510]59 int (*ep_add_hook)(hcd_t *, endpoint_t *);
[4dfc905]60 /** Hook called upon removing of an endpoint. */
[48ae3ef]61 void (*ep_remove_hook)(hcd_t *, endpoint_t *);
[45d105a]62};
[df8f3fa]63/*----------------------------------------------------------------------------*/
[4dfc905]64/** Initialize hcd_t structure.
[7711296]65 * Initializes device and endpoint managers. Sets data and hook pointer to NULL.
[4dfc905]66 * @param hcd hcd_t structure to initialize, non-null.
67 * @param bandwidth Available bandwidth, passed to endpoint manager.
68 * @param bw_count Bandwidth compute function, passed to endpoint manager.
69 */
[5e07cbc0]70static inline void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth,
[933b0d7]71 size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t))
[45d105a]72{
73 assert(hcd);
[5e07cbc0]74 usb_device_manager_init(&hcd->dev_manager, max_speed);
[7265558]75 usb_endpoint_manager_init(&hcd->ep_manager, bandwidth, bw_count);
[4dfc905]76 hcd->private_data = NULL;
77 hcd->schedule = NULL;
78 hcd->ep_add_hook = NULL;
79 hcd->ep_remove_hook = NULL;
[3afb758]80}
81/*----------------------------------------------------------------------------*/
[4dfc905]82/** Check registered endpoints and reset toggle bit if necessary.
83 * @param hcd hcd_t structure, non-null.
84 * @param target Control communication target.
85 * @param setup_data Setup packet of the control communication.
86 */
87static inline void reset_ep_if_need(hcd_t *hcd, usb_target_t target,
88 const char setup_data[8])
[df8f3fa]89{
90 assert(hcd);
[48ae3ef]91 usb_endpoint_manager_reset_eps_if_need(
[df8f3fa]92 &hcd->ep_manager, target, (const uint8_t *)setup_data);
93}
94/*----------------------------------------------------------------------------*/
[4dfc905]95/** Data retrieve wrapper.
96 * @param fun ddf function, non-null.
97 * @return pointer cast to hcd_t*.
98 */
[549ff23]99static inline hcd_t * fun_to_hcd(const ddf_fun_t *fun)
[45d105a]100{
101 assert(fun);
102 return fun->driver_data;
103}
[df8f3fa]104/*----------------------------------------------------------------------------*/
[45d105a]105extern usbhc_iface_t hcd_iface;
106
107#endif
108/**
109 * @}
110 */
Note: See TracBrowser for help on using the repository browser.