[45d105a] | 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 | */
|
---|
[77ad86c] | 35 |
|
---|
[45d105a] | 36 | #ifndef LIBUSBHOST_HOST_HCD_H
|
---|
| 37 | #define LIBUSBHOST_HOST_HCD_H
|
---|
| 38 |
|
---|
[8d2e251] | 39 | #include <usb/host/endpoint.h>
|
---|
[41924f30] | 40 | #include <usb/host/bus.h>
|
---|
[f58ef61] | 41 | #include <usb/host/usb_transfer_batch.h>
|
---|
[8d2e251] | 42 | #include <usb/usb.h>
|
---|
| 43 |
|
---|
| 44 | #include <assert.h>
|
---|
[479e32d] | 45 | #include <mem.h>
|
---|
[8d2dd7f2] | 46 | #include <stddef.h>
|
---|
| 47 | #include <stdint.h>
|
---|
[f9d0a86] | 48 | #include <usbhc_iface.h>
|
---|
[45d105a] | 49 |
|
---|
| 50 | typedef struct hcd hcd_t;
|
---|
| 51 |
|
---|
[f29931c] | 52 | typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *);
|
---|
[7191992] | 53 | typedef void (*interrupt_hook_t)(hcd_t *, uint32_t);
|
---|
[e26a9d95] | 54 | typedef int (*status_hook_t)(hcd_t *, uint32_t *);
|
---|
[867b375] | 55 | typedef int (*address_device_hook_t)(hcd_t *, usb_speed_t, usb_tt_address_t, usb_address_t *);
|
---|
[f29931c] | 56 |
|
---|
[9348862] | 57 | typedef struct {
|
---|
[4dfc905] | 58 | /** Transfer scheduling, implement in device driver. */
|
---|
[f29931c] | 59 | schedule_hook_t schedule;
|
---|
[7191992] | 60 | /** Hook to be called on device interrupt, passes ARG1 */
|
---|
| 61 | interrupt_hook_t irq_hook;
|
---|
[e26a9d95] | 62 | /** Periodic polling hook */
|
---|
| 63 | status_hook_t status_hook;
|
---|
[867b375] | 64 | /** Hook to setup device address */
|
---|
| 65 | address_device_hook_t address_device;
|
---|
[b5f813c] | 66 | } hcd_ops_t;
|
---|
[9348862] | 67 |
|
---|
| 68 | /** Generic host controller driver structure. */
|
---|
| 69 | struct hcd {
|
---|
| 70 | /** Endpoint manager. */
|
---|
[41924f30] | 71 | bus_t *bus;
|
---|
[9348862] | 72 |
|
---|
[3e200736] | 73 | /** Interrupt replacement fibril */
|
---|
| 74 | fid_t polling_fibril;
|
---|
[b5f813c] | 75 |
|
---|
| 76 | /** Driver implementation */
|
---|
| 77 | hcd_ops_t ops;
|
---|
[41924f30] | 78 |
|
---|
[b5f813c] | 79 | /** Device specific driver data. */
|
---|
| 80 | void * driver_data;
|
---|
[45d105a] | 81 | };
|
---|
[77ad86c] | 82 |
|
---|
[41924f30] | 83 | extern void hcd_init(hcd_t *);
|
---|
[77ad86c] | 84 |
|
---|
[4daee7a] | 85 | static inline void hcd_set_implementation(hcd_t *hcd, void *data,
|
---|
[41924f30] | 86 | const hcd_ops_t *ops, bus_t *bus)
|
---|
[b5f813c] | 87 | {
|
---|
| 88 | assert(hcd);
|
---|
| 89 | if (ops) {
|
---|
| 90 | hcd->driver_data = data;
|
---|
| 91 | hcd->ops = *ops;
|
---|
[41924f30] | 92 | hcd->bus = bus;
|
---|
[b5f813c] | 93 | } else {
|
---|
| 94 | memset(&hcd->ops, 0, sizeof(hcd->ops));
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | static inline void * hcd_get_driver_data(hcd_t *hcd)
|
---|
[4daee7a] | 99 | {
|
---|
| 100 | assert(hcd);
|
---|
[b5f813c] | 101 | return hcd->driver_data;
|
---|
[4daee7a] | 102 | }
|
---|
| 103 |
|
---|
[58563585] | 104 | extern usb_address_t hcd_request_address(hcd_t *, usb_speed_t);
|
---|
[b4c1c95] | 105 |
|
---|
[58563585] | 106 | extern int hcd_add_ep(hcd_t *, usb_target_t, usb_direction_t,
|
---|
[867b375] | 107 | usb_transfer_type_t, size_t, unsigned int, size_t, usb_tt_address_t);
|
---|
[0816c2e] | 108 |
|
---|
[58563585] | 109 | extern int hcd_remove_ep(hcd_t *, usb_target_t, usb_direction_t);
|
---|
[0816c2e] | 110 |
|
---|
[327f147] | 111 | extern int hcd_send_batch(hcd_t *, device_t *, usb_target_t,
|
---|
| 112 | usb_direction_t direction, char *, size_t, uint64_t,
|
---|
[f9d0a86] | 113 | usbhc_iface_transfer_callback_t, void *, const char *);
|
---|
[9c7ed9c] | 114 |
|
---|
[327f147] | 115 | extern ssize_t hcd_send_batch_sync(hcd_t *, device_t *, usb_target_t,
|
---|
| 116 | usb_direction_t direction, char *, size_t, uint64_t,
|
---|
| 117 | const char *);
|
---|
[237df2f] | 118 |
|
---|
[45d105a] | 119 | #endif
|
---|
[58563585] | 120 |
|
---|
[45d105a] | 121 | /**
|
---|
| 122 | * @}
|
---|
| 123 | */
|
---|