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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a81a1d09 was 3e4f2e0, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

libusb divided into sublibraries

Also removed address keeper test from tester as it is useless.

Directory reorganization of the include/ will follow.

  • Property mode set to 100644
File size: 3.6 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 libusb
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 LIBUSB_HOST_USB_ENDPOINT_MANAGER_H
40#define LIBUSB_HOST_YSB_ENDPOINT_MANAGER_H
41
42#include <adt/hash_table.h>
43#include <fibril_synch.h>
44#include <usb/usb.h>
45#include <usb/host/endpoint.h>
46
47#define BANDWIDTH_TOTAL_USB11 12000000
48#define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 / 10) * 9)
49
50typedef struct usb_endpoint_manager {
51 hash_table_t ep_table;
52 fibril_mutex_t guard;
53 fibril_condvar_t change;
54 size_t free_bw;
55} usb_endpoint_manager_t;
56
57size_t bandwidth_count_usb11(usb_speed_t speed, usb_transfer_type_t type,
58 size_t size, size_t max_packet_size);
59
60int usb_endpoint_manager_init(usb_endpoint_manager_t *instance,
61 size_t available_bandwidth);
62
63void usb_endpoint_manager_destroy(usb_endpoint_manager_t *instance);
64
65int usb_endpoint_manager_register_ep(usb_endpoint_manager_t *instance,
66 endpoint_t *ep, size_t data_size);
67
68int usb_endpoint_manager_unregister_ep(usb_endpoint_manager_t *instance,
69 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction);
70
71endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance,
72 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction,
73 size_t *bw);
74
75void usb_endpoint_manager_reset_if_need(
76 usb_endpoint_manager_t *instance, usb_target_t target, const uint8_t *data);
77
78static inline int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance,
79 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
80 usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size,
81 size_t data_size)
82{
83 endpoint_t *ep = malloc(sizeof(endpoint_t));
84 if (ep == NULL)
85 return ENOMEM;
86
87 int ret = endpoint_init(ep, address, endpoint, direction, type, speed,
88 max_packet_size);
89 if (ret != EOK) {
90 free(ep);
91 return ret;
92 }
93
94 ret = usb_endpoint_manager_register_ep(instance, ep, data_size);
95 if (ret != EOK) {
96 endpoint_destroy(ep);
97 return ret;
98 }
99 return EOK;
100}
101#endif
102/**
103 * @}
104 */
105
Note: See TracBrowser for help on using the repository browser.