[6ce42e85] | 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 |
|
---|
[160b75e] | 29 | /** @addtogroup libusbhost
|
---|
[6ce42e85] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
[41924f30] | 33 | *
|
---|
| 34 | * Endpoint structure is tightly coupled to the bus. The bus controls the
|
---|
| 35 | * life-cycle of endpoint. In order to keep endpoints lightweight, operations
|
---|
| 36 | * on endpoints are part of the bus structure.
|
---|
[8dc762e0] | 37 | *
|
---|
[6ce42e85] | 38 | */
|
---|
[160b75e] | 39 | #ifndef LIBUSBHOST_HOST_ENDPOINT_H
|
---|
| 40 | #define LIBUSBHOST_HOST_ENDPOINT_H
|
---|
[6ce42e85] | 41 |
|
---|
[3e6a98c5] | 42 | #include <stdbool.h>
|
---|
[6ce42e85] | 43 | #include <adt/list.h>
|
---|
[6a32665d] | 44 | #include <fibril_synch.h>
|
---|
[6ce42e85] | 45 | #include <usb/usb.h>
|
---|
[f527f58] | 46 | #include <atomic.h>
|
---|
[6ce42e85] | 47 |
|
---|
[41924f30] | 48 | typedef struct bus bus_t;
|
---|
[20eaa82] | 49 | typedef struct device device_t;
|
---|
[41924f30] | 50 |
|
---|
[17412546] | 51 | /** Host controller side endpoint structure. */
|
---|
[6ce42e85] | 52 | typedef struct endpoint {
|
---|
[41924f30] | 53 | /** Managing bus */
|
---|
| 54 | bus_t *bus;
|
---|
[f527f58] | 55 | /** Reference count. */
|
---|
[e9e24f2] | 56 | atomic_t refcnt;
|
---|
[17412546] | 57 | /** Part of linked list. */
|
---|
[83c3123] | 58 | link_t link;
|
---|
[20eaa82] | 59 | /** USB device */
|
---|
| 60 | device_t *device;
|
---|
[17412546] | 61 | /** USB address. */
|
---|
[41924f30] | 62 | usb_target_t target;
|
---|
[17412546] | 63 | /** Communication direction. */
|
---|
[0aae4a6a] | 64 | usb_direction_t direction;
|
---|
[17412546] | 65 | /** USB transfer type. */
|
---|
[6ce42e85] | 66 | usb_transfer_type_t transfer_type;
|
---|
[17412546] | 67 | /** Communication speed. */
|
---|
[6ce42e85] | 68 | usb_speed_t speed;
|
---|
[17412546] | 69 | /** Maximum size of data packets. */
|
---|
[6ce42e85] | 70 | size_t max_packet_size;
|
---|
[4e732f1a] | 71 | /** Additional opportunities per uframe */
|
---|
| 72 | unsigned packets;
|
---|
[41924f30] | 73 | /** Reserved bandwidth. */
|
---|
[83c3123] | 74 | size_t bandwidth;
|
---|
[17412546] | 75 | /** Value of the toggle bit. */
|
---|
[f567bcf] | 76 | unsigned toggle:1;
|
---|
[17412546] | 77 | /** True if there is a batch using this scheduled for this endpoint. */
|
---|
[41924f30] | 78 | bool active;
|
---|
[17412546] | 79 | /** Protects resources and active status changes. */
|
---|
[6a32665d] | 80 | fibril_mutex_t guard;
|
---|
[17412546] | 81 | /** Signals change of active status. */
|
---|
[6a32665d] | 82 | fibril_condvar_t avail;
|
---|
[41924f30] | 83 |
|
---|
| 84 | /* This structure is meant to be extended by overriding. */
|
---|
[6ce42e85] | 85 | } endpoint_t;
|
---|
| 86 |
|
---|
[41924f30] | 87 | extern void endpoint_init(endpoint_t *, bus_t *);
|
---|
[1e70157] | 88 |
|
---|
[58563585] | 89 | extern void endpoint_add_ref(endpoint_t *);
|
---|
| 90 | extern void endpoint_del_ref(endpoint_t *);
|
---|
[f527f58] | 91 |
|
---|
[58563585] | 92 | extern void endpoint_use(endpoint_t *);
|
---|
| 93 | extern void endpoint_release(endpoint_t *);
|
---|
[6a32665d] | 94 |
|
---|
[58563585] | 95 | extern int endpoint_toggle_get(endpoint_t *);
|
---|
[41924f30] | 96 | extern void endpoint_toggle_set(endpoint_t *, unsigned);
|
---|
[7265558] | 97 |
|
---|
[17412546] | 98 | /** list_get_instance wrapper.
|
---|
[58563585] | 99 | *
|
---|
[17412546] | 100 | * @param item Pointer to link member.
|
---|
[58563585] | 101 | *
|
---|
[c59dbdd5] | 102 | * @return Pointer to endpoint_t structure.
|
---|
[58563585] | 103 | *
|
---|
[17412546] | 104 | */
|
---|
[7265558] | 105 | static inline endpoint_t * endpoint_get_instance(link_t *item)
|
---|
| 106 | {
|
---|
[c59dbdd5] | 107 | return item ? list_get_instance(item, endpoint_t, link) : NULL;
|
---|
[7265558] | 108 | }
|
---|
[6ce42e85] | 109 | #endif
|
---|
[58563585] | 110 |
|
---|
[6ce42e85] | 111 | /**
|
---|
| 112 | * @}
|
---|
| 113 | */
|
---|