source: mainline/uspace/lib/usbhost/include/usb/host/endpoint.h@ 5e2b1ae6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5e2b1ae6 was 56257ba, checked in by Ondřej Hlavatý <aearsis@…>, 8 years ago

usbhost: manage endpoints by library + get/set_toggle → reset_toggle

That simplifies things A LOT. Now you can find endpoints for device in
an array inside device. This array is managed automatically in
register/unregister endpoint. HC drivers still needs to write to it when
setting up/tearing down the device.

Sorry for these two changes being in one commit, but splitting them
would be simply more work for no benefit.

  • Property mode set to 100644
File size: 4.4 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 <adt/list.h>
43#include <atomic.h>
44#include <fibril_synch.h>
45#include <stdbool.h>
46#include <usb/usb.h>
47#include <usb/host/bus.h>
48#include <usbhc_iface.h>
49
50typedef struct bus bus_t;
51typedef struct device device_t;
52typedef struct usb_transfer_batch usb_transfer_batch_t;
53
54/** Host controller side endpoint structure. */
55typedef struct endpoint {
56 /** Part of linked list. */
57 link_t link;
58 /** USB device */
59 device_t *device;
60 /** Reference count. */
61 atomic_t refcnt;
62 /** Reserved bandwidth. */
63 size_t bandwidth;
64 /** Value of the toggle bit. Untouched by the library. */
65 unsigned toggle:1;
66 /** The currently active transfer batch. Write using methods, read under guard. */
67 usb_transfer_batch_t *active_batch;
68 /** Protects resources and active status changes. */
69 fibril_mutex_t guard;
70 /** Signals change of active status. */
71 fibril_condvar_t avail;
72
73 /** Enpoint number */
74 usb_endpoint_t endpoint;
75 /** Communication direction. */
76 usb_direction_t direction;
77 /** USB transfer type. */
78 usb_transfer_type_t transfer_type;
79 /** Maximum size of one packet */
80 size_t max_packet_size;
81
82 /** Maximum size of one transfer */
83 size_t max_transfer_size;
84 /** Number of packats that can be sent in one service interval (not necessarily uframe) */
85 unsigned packets_per_uframe;
86
87 /* This structure is meant to be extended by overriding. */
88} endpoint_t;
89
90extern void endpoint_init(endpoint_t *, device_t *, const usb_endpoint_descriptors_t *);
91
92extern void endpoint_add_ref(endpoint_t *);
93extern void endpoint_del_ref(endpoint_t *);
94
95/* Pay atention to synchronization of batch access wrt to aborting & finishing from another fibril. */
96
97/* Set currently active batch. The common case is to activate in the same
98 * critical section as scheduling to HW.
99 */
100extern void endpoint_activate_locked(endpoint_t *, usb_transfer_batch_t *);
101
102/* Deactivate the endpoint, allowing others to activate it again. Batch shall
103 * already have an error set. */
104extern void endpoint_deactivate_locked(endpoint_t *);
105
106/* Abort the currenty active batch. */
107void endpoint_abort(endpoint_t *);
108
109/* Calculate bandwidth */
110ssize_t endpoint_count_bw(endpoint_t *, size_t);
111
112int endpoint_send_batch(endpoint_t *, usb_target_t, usb_direction_t,
113 char *, size_t, uint64_t, usbhc_iface_transfer_callback_t, void *,
114 const char *);
115
116static inline bus_t *endpoint_get_bus(endpoint_t *ep)
117{
118 return ep->device->bus;
119}
120
121/** list_get_instance wrapper.
122 *
123 * @param item Pointer to link member.
124 *
125 * @return Pointer to endpoint_t structure.
126 *
127 */
128static inline endpoint_t * endpoint_get_instance(link_t *item)
129{
130 return item ? list_get_instance(item, endpoint_t, link) : NULL;
131}
132
133#endif
134
135/**
136 * @}
137 */
Note: See TracBrowser for help on using the repository browser.