source: mainline/uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c@ 8e9becf6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8e9becf6 was a7e2f0d, checked in by Jan Vesely <jano.vesely@…>, 15 years ago

Doxygen and other comments

  • Property mode set to 100644
File size: 4.3 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/** @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/** Initializes Transfer Descriptor
41 *
42 * @param[in] instance Memory place to initialize.
43 * @param[in] err_count Number of retries hc should attempt.
44 * @param[in] size Size of data source.
45 * @param[in] toggle Value of toggle bit.
46 * @param[in] iso True if TD is for Isochronous transfer.
47 * @param[in] low_speed Target device's speed.
48 * @param[in] target Address and endpoint receiving the transfer.
49 * @param[in] pid Packet identification (SETUP, IN or OUT).
50 * @param[in] buffer Source of data.
51 * @param[in] next Net TD in transaction.
52 * @return Error code.
53 */
54void td_init(td_t *instance, int err_count, size_t size, bool toggle, bool iso,
55 bool low_speed, usb_target_t target, usb_packet_id pid, void *buffer,
56 td_t *next)
57{
58 assert(instance);
59 assert(size < 1024);
60 assert((pid == USB_PID_SETUP) || (pid == USB_PID_IN)
61 || (pid == USB_PID_OUT));
62
63 instance->next = 0
64 | LINK_POINTER_VERTICAL_FLAG
65 | ((next != NULL) ? addr_to_phys(next) : LINK_POINTER_TERMINATE_FLAG);
66
67 instance->status = 0
68 | ((err_count & TD_STATUS_ERROR_COUNT_MASK) << TD_STATUS_ERROR_COUNT_POS)
69 | (low_speed ? TD_STATUS_LOW_SPEED_FLAG : 0)
70 | (iso ? TD_STATUS_ISOCHRONOUS_FLAG : 0)
71 | TD_STATUS_ERROR_ACTIVE;
72
73 if (pid == USB_PID_IN && !iso) {
74 instance->status |= TD_STATUS_SPD_FLAG;
75 }
76
77 instance->device = 0
78 | (((size - 1) & TD_DEVICE_MAXLEN_MASK) << TD_DEVICE_MAXLEN_POS)
79 | (toggle ? TD_DEVICE_DATA_TOGGLE_ONE_FLAG : 0)
80 | ((target.address & TD_DEVICE_ADDRESS_MASK) << TD_DEVICE_ADDRESS_POS)
81 | ((target.endpoint & TD_DEVICE_ENDPOINT_MASK) << TD_DEVICE_ENDPOINT_POS)
82 | ((pid & TD_DEVICE_PID_MASK) << TD_DEVICE_PID_POS);
83
84 instance->buffer_ptr = 0;
85
86 if (size) {
87 instance->buffer_ptr = (uintptr_t)addr_to_phys(buffer);
88 }
89
90 usb_log_debug2("Created TD: %X:%X:%X:%X(%p).\n",
91 instance->next, instance->status, instance->device,
92 instance->buffer_ptr, buffer);
93 if (pid == USB_PID_SETUP) {
94 usb_log_debug("SETUP BUFFER: %s\n",
95 usb_debug_str_buffer(buffer, 8, 8));
96 }
97}
98/*----------------------------------------------------------------------------*/
99/** Converts TD status into standard error code
100 *
101 * @param[in] instance TD structure to use.
102 * @return Error code.
103 */
104int td_status(td_t *instance)
105{
106 assert(instance);
107
108 if ((instance->status & TD_STATUS_ERROR_STALLED) != 0)
109 return ESTALL;
110
111 if ((instance->status & TD_STATUS_ERROR_CRC) != 0)
112 return EBADCHECKSUM;
113
114 if ((instance->status & TD_STATUS_ERROR_BUFFER) != 0)
115 return EAGAIN;
116
117 if ((instance->status & TD_STATUS_ERROR_BABBLE) != 0)
118 return EIO;
119
120 if ((instance->status & TD_STATUS_ERROR_NAK) != 0)
121 return EAGAIN;
122
123 if ((instance->status & TD_STATUS_ERROR_BIT_STUFF) != 0)
124 return EAGAIN;
125
126 return EOK;
127}
128/**
129 * @}
130 */
Note: See TracBrowser for help on using the repository browser.