source: mainline/uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h@ 46f2808

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

libusbhost: usb_endpoint_manager add function to remove all endpoints of one address.

  • Property mode set to 100644
File size: 4.0 KB
Line 
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/** @addtogroup libusbhost
29 * @{
30 */
31/** @file
32 * Device keeper structure and functions.
33 *
34 * Typical USB host controller needs to keep track of various settings for
35 * each device that is connected to it.
36 * State of toggle bit, device speed etc. etc.
37 * This structure shall simplify the management.
38 */
39#ifndef LIBUSBHOST_HOST_USB_ENDPOINT_MANAGER_H
40#define LIBUSBHOST_HOST_USB_ENDPOINT_MANAGER_H
41
42#include <adt/list.h>
43#include <fibril_synch.h>
44#include <usb/usb.h>
45
46#include <usb/host/endpoint.h>
47
48/** Bytes per second in FULL SPEED */
49#define BANDWIDTH_TOTAL_USB11 (12000000 / 8)
50/** 90% of total bandwidth is available for periodic transfers */
51#define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 / 10) * 9)
52/** 16 addresses per list */
53#define ENDPOINT_LIST_COUNT 8
54
55/** Endpoint management structure */
56typedef struct usb_endpoint_manager {
57 /** Store endpoint_t instances */
58 list_t endpoint_lists[ENDPOINT_LIST_COUNT];
59 /** Prevents races accessing lists */
60 fibril_mutex_t guard;
61 /** Size of the bandwidth pool */
62 size_t free_bw;
63 /** Use this function to count bw required by EP */
64 size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t);
65} usb_endpoint_manager_t;
66
67size_t bandwidth_count_usb11(usb_speed_t speed, usb_transfer_type_t type,
68 size_t size, size_t max_packet_size);
69
70int usb_endpoint_manager_init(usb_endpoint_manager_t *instance,
71 size_t available_bandwidth,
72 size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t));
73
74void usb_endpoint_manager_reset_eps_if_need(usb_endpoint_manager_t *instance,
75 usb_target_t target, const uint8_t data[8]);
76
77int usb_endpoint_manager_register_ep(
78 usb_endpoint_manager_t *instance, endpoint_t *ep, size_t data_size);
79int usb_endpoint_manager_unregister_ep(
80 usb_endpoint_manager_t *instance, endpoint_t *ep);
81endpoint_t * usb_endpoint_manager_find_ep(usb_endpoint_manager_t *instance,
82 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction);
83
84int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance,
85 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
86 usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size,
87 size_t data_size, int (*callback)(endpoint_t *, void *), void *arg);
88
89int usb_endpoint_manager_remove_ep(usb_endpoint_manager_t *instance,
90 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
91 void (*callback)(endpoint_t *, void *), void *arg);
92
93void usb_endpoint_manager_remove_address(usb_endpoint_manager_t *instance,
94 usb_address_t address, void (*callback)(endpoint_t *, void *), void *arg);
95#endif
96/**
97 * @}
98 */
Note: See TracBrowser for help on using the repository browser.