You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* USB EHCI Host for Teensy 3.6
  2. * Copyright 2017 Paul Stoffregen (paul@pjrc.com)
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included
  13. * in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <Arduino.h>
  24. #include "USBHost.h"
  25. void USBHost::print(const Transfer_t *transfer)
  26. {
  27. if (!((uint32_t)transfer & 0xFFFFFFE0)) return;
  28. Serial.print("Transfer @ ");
  29. Serial.println(((uint32_t)transfer & 0xFFFFFFE0), HEX);
  30. Serial.print(" next: ");
  31. Serial.println(transfer->qtd.next, HEX);
  32. Serial.print(" anext: ");
  33. Serial.println(transfer->qtd.alt_next, HEX);
  34. Serial.print(" token: ");
  35. Serial.println(transfer->qtd.token, HEX);
  36. Serial.print(" bufs: ");
  37. for (int i=0; i < 5; i++) {
  38. Serial.print(transfer->qtd.buffer[i], HEX);
  39. if (i < 4) Serial.print(',');
  40. }
  41. Serial.println();
  42. }
  43. void USBHost::print(const Transfer_t *first, const Transfer_t *last)
  44. {
  45. Serial.print("Transfer Followup List ");
  46. Serial.print((uint32_t)first, HEX);
  47. Serial.print(" to ");
  48. Serial.println((uint32_t)last, HEX);
  49. Serial.println(" forward:");
  50. while (first) {
  51. Serial.print(" ");
  52. Serial.print((uint32_t)first, HEX);
  53. print_token(first->qtd.token);
  54. first = first->next_followup;
  55. }
  56. Serial.println(" backward:");
  57. while (last) {
  58. Serial.print(" ");
  59. Serial.print((uint32_t)last, HEX);
  60. print_token(last->qtd.token);
  61. last = last->prev_followup;
  62. }
  63. }
  64. void USBHost::print_token(uint32_t token)
  65. {
  66. switch ((token >> 8) & 3) {
  67. case 0:
  68. Serial.print(" OUT ");
  69. Serial.println((token >> 16) & 0x7FFF);
  70. break;
  71. case 1:
  72. Serial.print(" IN ");
  73. Serial.println((token >> 16) & 0x7FFF);
  74. break;
  75. case 2:
  76. Serial.println(" SETUP");
  77. break;
  78. default:
  79. Serial.println(" unknown");
  80. }
  81. }
  82. void USBHost::print(const Pipe_t *pipe)
  83. {
  84. if (!((uint32_t)pipe & 0xFFFFFFE0)) return;
  85. Serial.print("Pipe ");
  86. if (pipe->type == 0) Serial.print("control");
  87. else if (pipe->type == 1) Serial.print("isochronous");
  88. else if (pipe->type == 2) Serial.print("bulk");
  89. else if (pipe->type == 3) Serial.print("interrupt");
  90. Serial.print(pipe->direction ? " IN" : " OUT");
  91. Serial.print(" @ ");
  92. Serial.println((uint32_t)pipe, HEX);
  93. Serial.print(" horiz link: ");
  94. Serial.println(pipe->qh.horizontal_link, HEX);
  95. Serial.print(" capabilities: ");
  96. Serial.print(pipe->qh.capabilities[0], HEX);
  97. Serial.print(',');
  98. Serial.println(pipe->qh.capabilities[1], HEX);
  99. Serial.println(" overlay:");
  100. Serial.print(" cur: ");
  101. Serial.println(pipe->qh.current, HEX);
  102. Serial.print(" next: ");
  103. Serial.println(pipe->qh.next, HEX);
  104. Serial.print(" anext: ");
  105. Serial.println(pipe->qh.alt_next, HEX);
  106. Serial.print(" token: ");
  107. Serial.println(pipe->qh.token, HEX);
  108. Serial.print(" bufs: ");
  109. for (int i=0; i < 5; i++) {
  110. Serial.print(pipe->qh.buffer[i], HEX);
  111. if (i < 4) Serial.print(',');
  112. }
  113. Serial.println();
  114. const Transfer_t *t = (Transfer_t *)pipe->qh.next;
  115. while (((uint32_t)t & 0xFFFFFFE0)) {
  116. print(t);
  117. t = (Transfer_t *)t->qtd.next;
  118. }
  119. //Serial.print();
  120. }
  121. void USBHost::print_hexbytes(const void *ptr, uint32_t len)
  122. {
  123. if (ptr == NULL || len == 0) return;
  124. const uint8_t *p = (const uint8_t *)ptr;
  125. do {
  126. if (*p < 16) Serial.print('0');
  127. Serial.print(*p++, HEX);
  128. Serial.print(' ');
  129. } while (--len);
  130. Serial.println();
  131. }
  132. void USBHost::print(const char *s)
  133. {
  134. Serial.println(s);
  135. }
  136. void USBHost::print(const char *s, int num)
  137. {
  138. Serial.print(s);
  139. Serial.println(num);
  140. }