[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 |
|
---|
| 39 | #include <assert.h>
|
---|
[9c7ed9c] | 40 | #include <adt/list.h>
|
---|
[7265558] | 41 | #include <usbhc_iface.h>
|
---|
[4dfc905] | 42 |
|
---|
[8b54fe6] | 43 | #include <usb/host/usb_device_manager.h>
|
---|
[45d105a] | 44 | #include <usb/host/usb_endpoint_manager.h>
|
---|
[f58ef61] | 45 | #include <usb/host/usb_transfer_batch.h>
|
---|
[45d105a] | 46 |
|
---|
| 47 | typedef struct hcd hcd_t;
|
---|
| 48 |
|
---|
[f29931c] | 49 | typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *);
|
---|
| 50 | typedef int (*ep_add_hook_t)(hcd_t *, endpoint_t *);
|
---|
| 51 | typedef void (*ep_remove_hook_t)(hcd_t *, endpoint_t *);
|
---|
| 52 |
|
---|
[4dfc905] | 53 | /** Generic host controller driver structure. */
|
---|
[45d105a] | 54 | struct hcd {
|
---|
[4dfc905] | 55 | /** Device manager storing handles and addresses. */
|
---|
[8b54fe6] | 56 | usb_device_manager_t dev_manager;
|
---|
[4dfc905] | 57 | /** Endpoint manager. */
|
---|
[45d105a] | 58 | usb_endpoint_manager_t ep_manager;
|
---|
| 59 |
|
---|
[4dfc905] | 60 | /** Device specific driver data. */
|
---|
| 61 | void *private_data;
|
---|
| 62 | /** Transfer scheduling, implement in device driver. */
|
---|
[f29931c] | 63 | schedule_hook_t schedule;
|
---|
[4dfc905] | 64 | /** Hook called upon registering new endpoint. */
|
---|
[f29931c] | 65 | ep_add_hook_t ep_add_hook;
|
---|
[4dfc905] | 66 | /** Hook called upon removing of an endpoint. */
|
---|
[f29931c] | 67 | ep_remove_hook_t ep_remove_hook;
|
---|
[45d105a] | 68 | };
|
---|
[77ad86c] | 69 |
|
---|
[21be46a] | 70 | void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth,
|
---|
| 71 | bw_count_func_t bw_count);
|
---|
[77ad86c] | 72 |
|
---|
[4daee7a] | 73 | static inline void hcd_set_implementation(hcd_t *hcd, void *data,
|
---|
| 74 | schedule_hook_t schedule, ep_add_hook_t add_hook, ep_remove_hook_t rem_hook)
|
---|
| 75 | {
|
---|
| 76 | assert(hcd);
|
---|
| 77 | hcd->private_data = data;
|
---|
| 78 | hcd->schedule = schedule;
|
---|
| 79 | hcd->ep_add_hook = add_hook;
|
---|
| 80 | hcd->ep_remove_hook = rem_hook;
|
---|
| 81 |
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[3c4663e] | 84 | int hcd_send_batch(hcd_t *hcd, usb_target_t target, usb_direction_t direction,
|
---|
[d9b2c73] | 85 | void *data, size_t size, uint64_t setup_data,
|
---|
| 86 | usbhc_iface_transfer_in_callback_t in,
|
---|
| 87 | usbhc_iface_transfer_out_callback_t out, void *arg, const char* name);
|
---|
[9c7ed9c] | 88 |
|
---|
[45d105a] | 89 | #endif
|
---|
| 90 | /**
|
---|
| 91 | * @}
|
---|
| 92 | */
|
---|