source: mainline/uspace/lib/usbhost/include/usb/host/endpoint.h@ 888238e9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 888238e9 was 888238e9, checked in by Aearsis <Hlavaty.Ondrej@…>, 8 years ago

usbhost: endpoints do not have speed on their own

This information was redundant, and the fact it was never set proves it
should be removed because it is source of errors.

  • 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
29/** @addtogroup libusbhost
30 * @{
31 */
32/** @file
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.
37 *
38 */
39#ifndef LIBUSBHOST_HOST_ENDPOINT_H
40#define LIBUSBHOST_HOST_ENDPOINT_H
41
42#include <stdbool.h>
43#include <adt/list.h>
44#include <fibril_synch.h>
45#include <usb/usb.h>
46#include <atomic.h>
47
48typedef struct bus bus_t;
49typedef struct device device_t;
50typedef struct usb_transfer_batch usb_transfer_batch_t;
51
52/** Host controller side endpoint structure. */
53typedef struct endpoint {
54 /** Part of linked list. */
55 link_t link;
56 /** Managing bus */
57 bus_t *bus;
58 /** Reference count. */
59 atomic_t refcnt;
60 /** USB device */
61 device_t *device;
62 /** Enpoint number */
63 usb_endpoint_t endpoint;
64 /** Communication direction. */
65 usb_direction_t direction;
66 /** USB transfer type. */
67 usb_transfer_type_t transfer_type;
68 /** Maximum size of data packets. */
69 size_t max_packet_size;
70 /** Additional opportunities per uframe */
71 unsigned packets;
72 /** Reserved bandwidth. */
73 size_t bandwidth;
74 /** Value of the toggle bit. */
75 unsigned toggle:1;
76 /** The currently active transfer batch. Write using methods, read under guard. */
77 usb_transfer_batch_t *active_batch;
78 /** Protects resources and active status changes. */
79 fibril_mutex_t guard;
80 /** Signals change of active status. */
81 fibril_condvar_t avail;
82
83 /* This structure is meant to be extended by overriding. */
84} endpoint_t;
85
86extern void endpoint_init(endpoint_t *, bus_t *);
87
88extern void endpoint_add_ref(endpoint_t *);
89extern void endpoint_del_ref(endpoint_t *);
90
91/* Pay atention to synchronization of batch access wrt to aborting & finishing from another fibril. */
92
93/* Set currently active batch. The common case is to activate in the same
94 * critical section as scheduling to HW.
95 */
96extern void endpoint_activate_locked(endpoint_t *, usb_transfer_batch_t *);
97
98/* Deactivate the endpoint, allowing others to activate it again. Batch shall
99 * already have an error set. */
100extern void endpoint_deactivate_locked(endpoint_t *);
101
102/* Abort the currenty active batch. */
103void endpoint_abort(endpoint_t *);
104
105extern int endpoint_toggle_get(endpoint_t *);
106extern void endpoint_toggle_set(endpoint_t *, bool);
107
108/** list_get_instance wrapper.
109 *
110 * @param item Pointer to link member.
111 *
112 * @return Pointer to endpoint_t structure.
113 *
114 */
115static inline endpoint_t * endpoint_get_instance(link_t *item)
116{
117 return item ? list_get_instance(item, endpoint_t, link) : NULL;
118}
119
120#endif
121
122/**
123 * @}
124 */
Note: See TracBrowser for help on using the repository browser.