source: mainline/uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c@ 3f189c5

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

Lots of cleanup, removes unused code (replaced by trackers)

  • Property mode set to 100644
File size: 3.8 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
40void transfer_descriptor_init(transfer_descriptor_t *instance,
41 int error_count, size_t size, bool isochronous, usb_target_t target,
42 int pid, void *buffer)
43{
44 assert(instance);
45
46 instance->next =
47 0 | LINK_POINTER_TERMINATE_FLAG;
48
49 assert(size < 1024);
50 instance->status = 0
51 | ((error_count & TD_STATUS_ERROR_COUNT_MASK) << TD_STATUS_ERROR_COUNT_POS)
52 | TD_STATUS_ERROR_ACTIVE;
53
54 instance->device = 0
55 | (((size - 1) & TD_DEVICE_MAXLEN_MASK) << TD_DEVICE_MAXLEN_POS)
56 | ((target.address & TD_DEVICE_ADDRESS_MASK) << TD_DEVICE_ADDRESS_POS)
57 | ((target.endpoint & TD_DEVICE_ENDPOINT_MASK) << TD_DEVICE_ENDPOINT_POS)
58 | ((pid & TD_DEVICE_PID_MASK) << TD_DEVICE_PID_POS);
59
60 instance->buffer_ptr = 0;
61
62 if (size) {
63 instance->buffer_ptr = (uintptr_t)addr_to_phys(buffer);
64 }
65
66 usb_log_info("Created TD: %X:%X:%X:%X(%p).\n",
67 instance->next, instance->status, instance->device,
68 instance->buffer_ptr, buffer);
69#if 0
70 if (size) {
71 unsigned char * buff = buffer;
72 uhci_print_verbose("TD Buffer dump(%p-%dB): ", buffer, size);
73 unsigned i = 0;
74 /* TODO: Verbose? */
75 for (; i < size; ++i) {
76 printf((i & 1) ? "%x " : "%x", buff[i]);
77 }
78 printf("\n");
79 }
80#endif
81}
82
83static inline usb_transaction_outcome_t convert_outcome(uint32_t status)
84{
85 /*TODO: refactor into something sane */
86 /*TODO: add additional usb_errors to usb_outcome_t */
87
88 if (status & TD_STATUS_ERROR_STALLED)
89 return USB_OUTCOME_CRCERROR;
90
91 if (status & TD_STATUS_ERROR_BUFFER)
92 return USB_OUTCOME_CRCERROR;
93
94 if (status & TD_STATUS_ERROR_BABBLE)
95 return USB_OUTCOME_BABBLE;
96
97 if (status & TD_STATUS_ERROR_NAK)
98 return USB_OUTCOME_CRCERROR;
99
100 if (status & TD_STATUS_ERROR_CRC)
101 return USB_OUTCOME_CRCERROR;
102
103 if (status & TD_STATUS_ERROR_BIT_STUFF)
104 return USB_OUTCOME_CRCERROR;
105
106 assert((((status >> TD_STATUS_ERROR_POS) & TD_STATUS_ERROR_MASK)
107 | TD_STATUS_ERROR_RESERVED) == TD_STATUS_ERROR_RESERVED);
108 return USB_OUTCOME_OK;
109}
110/*----------------------------------------------------------------------------*/
111int transfer_descriptor_status(transfer_descriptor_t *instance)
112{
113 assert(instance);
114 if (convert_outcome(instance->status))
115 return EINVAL; //TODO: use sane error value here
116 return EOK;
117}
118/**
119 * @}
120 */
Note: See TracBrowser for help on using the repository browser.