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 | /** @addtogroup usb
|
---|
29 | * @{
|
---|
30 | */
|
---|
31 | /** @file
|
---|
32 | * @brief UHCI driver
|
---|
33 | */
|
---|
34 | #include <errno.h>
|
---|
35 | #include <usb/debug.h>
|
---|
36 |
|
---|
37 | #include "transfer_descriptor.h"
|
---|
38 | #include "utils/malloc32.h"
|
---|
39 |
|
---|
40 | void td_init(td_t *instance, int err_count, size_t size, bool toggle, bool iso,
|
---|
41 | bool low_speed, usb_target_t target, usb_packet_id pid, void *buffer, td_t *next)
|
---|
42 | {
|
---|
43 | assert(instance);
|
---|
44 | assert(size < 1024);
|
---|
45 | assert((pid == USB_PID_SETUP) || (pid == USB_PID_IN) || (pid == USB_PID_OUT));
|
---|
46 |
|
---|
47 | instance->next = 0
|
---|
48 | | LINK_POINTER_VERTICAL_FLAG
|
---|
49 | | ((next != NULL) ? addr_to_phys(next) : LINK_POINTER_TERMINATE_FLAG);
|
---|
50 |
|
---|
51 | instance->status = 0
|
---|
52 | | ((err_count & TD_STATUS_ERROR_COUNT_MASK) << TD_STATUS_ERROR_COUNT_POS)
|
---|
53 | | (low_speed ? TD_STATUS_LOW_SPEED_FLAG : 0)
|
---|
54 | | (iso ? TD_STATUS_ISOCHRONOUS_FLAG : 0)
|
---|
55 | | TD_STATUS_ERROR_ACTIVE;
|
---|
56 |
|
---|
57 | if (pid == USB_PID_IN && !iso) {
|
---|
58 | instance->status |= TD_STATUS_SPD_FLAG;
|
---|
59 | }
|
---|
60 |
|
---|
61 | instance->device = 0
|
---|
62 | | (((size - 1) & TD_DEVICE_MAXLEN_MASK) << TD_DEVICE_MAXLEN_POS)
|
---|
63 | | (toggle ? TD_DEVICE_DATA_TOGGLE_ONE_FLAG : 0)
|
---|
64 | | ((target.address & TD_DEVICE_ADDRESS_MASK) << TD_DEVICE_ADDRESS_POS)
|
---|
65 | | ((target.endpoint & TD_DEVICE_ENDPOINT_MASK) << TD_DEVICE_ENDPOINT_POS)
|
---|
66 | | ((pid & TD_DEVICE_PID_MASK) << TD_DEVICE_PID_POS);
|
---|
67 |
|
---|
68 | instance->buffer_ptr = 0;
|
---|
69 |
|
---|
70 | if (size) {
|
---|
71 | instance->buffer_ptr = (uintptr_t)addr_to_phys(buffer);
|
---|
72 | }
|
---|
73 |
|
---|
74 | usb_log_debug2("Created TD: %X:%X:%X:%X(%p).\n",
|
---|
75 | instance->next, instance->status, instance->device,
|
---|
76 | instance->buffer_ptr, buffer);
|
---|
77 | }
|
---|
78 | /*----------------------------------------------------------------------------*/
|
---|
79 | int td_status(td_t *instance)
|
---|
80 | {
|
---|
81 | assert(instance);
|
---|
82 |
|
---|
83 | if ((instance->status & TD_STATUS_ERROR_STALLED) != 0)
|
---|
84 | return ESTALL;
|
---|
85 |
|
---|
86 | if ((instance->status & TD_STATUS_ERROR_CRC) != 0)
|
---|
87 | return EBADCHECKSUM;
|
---|
88 |
|
---|
89 | if ((instance->status & TD_STATUS_ERROR_BUFFER) != 0)
|
---|
90 | return EAGAIN;
|
---|
91 |
|
---|
92 | if ((instance->status & TD_STATUS_ERROR_BABBLE) != 0)
|
---|
93 | return EIO;
|
---|
94 |
|
---|
95 | if ((instance->status & TD_STATUS_ERROR_NAK) != 0)
|
---|
96 | return EAGAIN;
|
---|
97 |
|
---|
98 | if ((instance->status & TD_STATUS_ERROR_BIT_STUFF) != 0)
|
---|
99 | return EAGAIN;
|
---|
100 |
|
---|
101 | return EOK;
|
---|
102 | }
|
---|
103 | /**
|
---|
104 | * @}
|
---|
105 | */
|
---|