| 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_BANDWIDTH_H
|
|---|
| 40 | #define LIBUSB_HOST_BANDWIDTH_H
|
|---|
| 41 |
|
|---|
| 42 | #include <adt/hash_table.h>
|
|---|
| 43 | #include <fibril_synch.h>
|
|---|
| 44 | #include <usb/usb.h>
|
|---|
| 45 |
|
|---|
| 46 | #define BANDWIDTH_TOTAL_USB11 12000000
|
|---|
| 47 | #define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 / 10) * 9)
|
|---|
| 48 |
|
|---|
| 49 | typedef struct bandwidth {
|
|---|
| 50 | hash_table_t reserved;
|
|---|
| 51 | fibril_mutex_t guard;
|
|---|
| 52 | size_t free;
|
|---|
| 53 | size_t (*usage_fnc)(usb_speed_t, usb_transfer_type_t, size_t, size_t);
|
|---|
| 54 | } bandwidth_t;
|
|---|
| 55 |
|
|---|
| 56 | size_t bandwidth_count_usb11(usb_speed_t speed, usb_transfer_type_t type,
|
|---|
| 57 | size_t size, size_t max_packet_size);
|
|---|
| 58 |
|
|---|
| 59 | int bandwidth_init(bandwidth_t *instance, size_t bandwidth,
|
|---|
| 60 | size_t (*usage_fnc)(usb_speed_t, usb_transfer_type_t, size_t, size_t));
|
|---|
| 61 |
|
|---|
| 62 | void bandwidth_destroy(bandwidth_t *instance);
|
|---|
| 63 |
|
|---|
| 64 | int bandwidth_reserve(bandwidth_t *instance, usb_address_t address,
|
|---|
| 65 | usb_endpoint_t endpoint, usb_direction_t direction, usb_speed_t speed,
|
|---|
| 66 | usb_transfer_type_t transfer_type, size_t max_packet_size, size_t size,
|
|---|
| 67 | unsigned interval);
|
|---|
| 68 |
|
|---|
| 69 | int bandwidth_release(bandwidth_t *instance, usb_address_t address,
|
|---|
| 70 | usb_endpoint_t endpoint, usb_direction_t direction);
|
|---|
| 71 |
|
|---|
| 72 | int bandwidth_use(bandwidth_t *instance, usb_address_t address,
|
|---|
| 73 | usb_endpoint_t endpoint, usb_direction_t direction);
|
|---|
| 74 |
|
|---|
| 75 | int bandwidth_free(bandwidth_t *instance, usb_address_t address,
|
|---|
| 76 | usb_endpoint_t endpoint, usb_direction_t direction);
|
|---|
| 77 |
|
|---|
| 78 | #endif
|
|---|
| 79 | /**
|
|---|
| 80 | * @}
|
|---|
| 81 | */
|
|---|