source: mainline/uspace/drv/uhci/uhci_struct/transfer_descriptor.c@ 113aef8

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

TD debug messages refatoring

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#include "transfer_descriptor.h"
2
3void transfer_descriptor_init(transfer_descriptor_t *instance,
4 int error_count, size_t size, bool isochronous, usb_target_t target,
5 int pid, void *buffer)
6{
7 assert(instance);
8
9 instance->next =
10 0 | LINK_POINTER_TERMINATE_FLAG;
11
12
13 assert(size < 1024);
14 instance->status = 0
15 | ((error_count & TD_STATUS_ERROR_COUNT_MASK) << TD_STATUS_ERROR_COUNT_POS)
16 | TD_STATUS_ERROR_ACTIVE;
17
18 instance->device = 0
19 | (((size - 1) & TD_DEVICE_MAXLEN_MASK) << TD_DEVICE_MAXLEN_POS)
20 | ((target.address & TD_DEVICE_ADDRESS_MASK) << TD_DEVICE_ADDRESS_POS)
21 | ((target.endpoint & TD_DEVICE_ENDPOINT_MASK) << TD_DEVICE_ENDPOINT_POS)
22 | ((pid & TD_DEVICE_PID_MASK) << TD_DEVICE_PID_POS);
23
24 instance->buffer_ptr = 0;
25
26 instance->next_va = NULL;
27 instance->callback = NULL;
28
29 if (size) {
30 instance->buffer_ptr = (uintptr_t)addr_to_phys(buffer);
31 }
32
33 uhci_print_info("Created TD: %X:%X:%X:%X(%p).\n",
34 instance->next, instance->status, instance->device,
35 instance->buffer_ptr, buffer);
36
37 if (size) {
38 unsigned char * buff = buffer;
39 uhci_print_verbose("TD Buffer dump(%p-%dB): ", buffer, size);
40 unsigned i = 0;
41 /* TODO: Verbose? */
42 for (; i < size; ++i) {
43 printf((i & 1) ? "%x " : "%x", buff[i]);
44 }
45 printf("\n");
46 }
47}
48
49static inline usb_transaction_outcome_t convert_outcome(uint32_t status)
50{
51 /*TODO: refactor into something sane */
52 /*TODO: add additional usb_errors to usb_outcome_t */
53
54 if (status & TD_STATUS_ERROR_STALLED)
55 return USB_OUTCOME_CRCERROR;
56
57 if (status & TD_STATUS_ERROR_BUFFER)
58 return USB_OUTCOME_CRCERROR;
59
60 if (status & TD_STATUS_ERROR_BABBLE)
61 return USB_OUTCOME_BABBLE;
62
63 if (status & TD_STATUS_ERROR_NAK)
64 return USB_OUTCOME_CRCERROR;
65
66 if (status & TD_STATUS_ERROR_CRC)
67 return USB_OUTCOME_CRCERROR;
68
69 if (status & TD_STATUS_ERROR_BIT_STUFF)
70 return USB_OUTCOME_CRCERROR;
71
72 assert((((status >> TD_STATUS_ERROR_POS) & TD_STATUS_ERROR_MASK)
73 | TD_STATUS_ERROR_RESERVED) == TD_STATUS_ERROR_RESERVED);
74 return USB_OUTCOME_OK;
75}
76
77void transfer_descriptor_fini(transfer_descriptor_t *instance)
78{
79 assert(instance);
80 callback_run(instance->callback,
81 convert_outcome(instance->status),
82 ((instance->status >> TD_STATUS_ACTLEN_POS) + 1) & TD_STATUS_ACTLEN_MASK
83 );
84}
Note: See TracBrowser for help on using the repository browser.