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

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

Error reporting refactored

  • Property mode set to 100644
File size: 3.4 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 toggle, bool isochronous,
42 usb_target_t target, int pid, void *buffer)
43{
44 assert(instance);
45
46 instance->next = 0 | LINK_POINTER_TERMINATE_FLAG;
47
48 instance->status = 0
49 | ((error_count & TD_STATUS_ERROR_COUNT_MASK) << TD_STATUS_ERROR_COUNT_POS)
50 | TD_STATUS_ERROR_ACTIVE;
51
52 assert(size < 1024);
53 instance->device = 0
54 | (((size - 1) & TD_DEVICE_MAXLEN_MASK) << TD_DEVICE_MAXLEN_POS)
55 | (toggle ? TD_DEVICE_DATA_TOGGLE_ONE_FLAG : 0)
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/*----------------------------------------------------------------------------*/
83int transfer_descriptor_status(transfer_descriptor_t *instance)
84{
85 assert(instance);
86
87 if ((instance->status & TD_STATUS_ERROR_STALLED) != 0)
88 return EIO;
89
90 if ((instance->status & TD_STATUS_ERROR_CRC) != 0)
91 return EAGAIN;
92
93 if ((instance->status & TD_STATUS_ERROR_BUFFER) != 0)
94 return EAGAIN;
95
96 if ((instance->status & TD_STATUS_ERROR_BABBLE) != 0)
97 return EIO;
98
99 if ((instance->status & TD_STATUS_ERROR_NAK) != 0)
100 return EAGAIN;
101
102 if ((instance->status & TD_STATUS_ERROR_BIT_STUFF) != 0)
103 return EAGAIN;
104
105 return EOK;
106}
107/**
108 * @}
109 */
Note: See TracBrowser for help on using the repository browser.