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 | */
|
---|
35 |
|
---|
36 | #ifndef LIBUSBHOST_HOST_HCD_H
|
---|
37 | #define LIBUSBHOST_HOST_HCD_H
|
---|
38 |
|
---|
39 | #include <assert.h>
|
---|
40 | #include <mem.h>
|
---|
41 | #include <stddef.h>
|
---|
42 | #include <stdint.h>
|
---|
43 | #include <usb/usb.h>
|
---|
44 | #include <usbhc_iface.h>
|
---|
45 |
|
---|
46 | typedef struct hcd hcd_t;
|
---|
47 | typedef struct bus bus_t;
|
---|
48 | typedef struct device device_t;
|
---|
49 | typedef struct usb_transfer_batch usb_transfer_batch_t;
|
---|
50 |
|
---|
51 | typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *);
|
---|
52 | typedef void (*interrupt_hook_t)(hcd_t *, uint32_t);
|
---|
53 | typedef int (*status_hook_t)(hcd_t *, uint32_t *);
|
---|
54 |
|
---|
55 | typedef struct {
|
---|
56 | /** Transfer scheduling, implement in device driver. */
|
---|
57 | schedule_hook_t schedule;
|
---|
58 | /** Hook to be called on device interrupt, passes ARG1 */
|
---|
59 | interrupt_hook_t irq_hook;
|
---|
60 | /** Periodic polling hook */
|
---|
61 | status_hook_t status_hook;
|
---|
62 | } hcd_ops_t;
|
---|
63 |
|
---|
64 | /** Generic host controller driver structure. */
|
---|
65 | struct hcd {
|
---|
66 | /** Endpoint manager. */
|
---|
67 | bus_t *bus;
|
---|
68 |
|
---|
69 | /** Interrupt replacement fibril */
|
---|
70 | fid_t polling_fibril;
|
---|
71 |
|
---|
72 | /** Driver implementation */
|
---|
73 | hcd_ops_t ops;
|
---|
74 |
|
---|
75 | /** Device specific driver data. */
|
---|
76 | void * driver_data;
|
---|
77 | };
|
---|
78 |
|
---|
79 | extern void hcd_init(hcd_t *);
|
---|
80 |
|
---|
81 | static inline void hcd_set_implementation(hcd_t *hcd, void *data,
|
---|
82 | const hcd_ops_t *ops, bus_t *bus)
|
---|
83 | {
|
---|
84 | assert(hcd);
|
---|
85 | if (ops) {
|
---|
86 | hcd->driver_data = data;
|
---|
87 | hcd->ops = *ops;
|
---|
88 | hcd->bus = bus;
|
---|
89 | } else {
|
---|
90 | memset(&hcd->ops, 0, sizeof(hcd->ops));
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | static inline void * hcd_get_driver_data(hcd_t *hcd)
|
---|
95 | {
|
---|
96 | assert(hcd);
|
---|
97 | return hcd->driver_data;
|
---|
98 | }
|
---|
99 |
|
---|
100 | extern int hcd_get_ep0_max_packet_size(uint16_t *, hcd_t *, device_t *);
|
---|
101 | extern void hcd_setup_device_tt(device_t *);
|
---|
102 |
|
---|
103 | extern int hcd_send_batch(hcd_t *, device_t *, usb_target_t,
|
---|
104 | usb_direction_t direction, char *, size_t, uint64_t,
|
---|
105 | usbhc_iface_transfer_callback_t, void *, const char *);
|
---|
106 |
|
---|
107 | extern ssize_t hcd_send_batch_sync(hcd_t *, device_t *, usb_target_t,
|
---|
108 | usb_direction_t direction, char *, size_t, uint64_t,
|
---|
109 | const char *);
|
---|
110 |
|
---|
111 | /** How many toggles need to be reset */
|
---|
112 | typedef enum {
|
---|
113 | RESET_NONE,
|
---|
114 | RESET_EP,
|
---|
115 | RESET_ALL
|
---|
116 | } toggle_reset_mode_t;
|
---|
117 |
|
---|
118 | #endif
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * @}
|
---|
122 | */
|
---|