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.

181 satır
5.0KB

  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_driverlist(const char *name, const USBDriver *driver)
  122. {
  123. Serial.print("USBDriver (");
  124. Serial.print(name);
  125. Serial.print(") list: ");
  126. if (driver == NULL) {
  127. Serial.println("(empty");
  128. return;
  129. }
  130. uint32_t count=0;
  131. for (const USBDriver *p = driver; p; p = p->next) {
  132. Serial.print((uint32_t)p, HEX);
  133. if (p->next) Serial.print(" -> ");
  134. if (++count > 30) {
  135. Serial.println("abort:list too long");
  136. return;
  137. }
  138. }
  139. Serial.println();
  140. }
  141. void USBHost::print_qh_list(const Pipe_t *list)
  142. {
  143. if (!list) {
  144. Serial.println("(empty)");
  145. return;
  146. }
  147. const Pipe_t *node = list;
  148. while (1) {
  149. Serial.print((uint32_t)node, HEX);
  150. node = (const Pipe_t *)(node->qh.horizontal_link & 0xFFFFFFE0);
  151. if (!node) break;
  152. if (node == list) {
  153. Serial.print(" (loops)");
  154. break;
  155. }
  156. Serial.print(" -> ");
  157. }
  158. Serial.println();
  159. }
  160. void USBHost::print_hexbytes(const void *ptr, uint32_t len)
  161. {
  162. if (ptr == NULL || len == 0) return;
  163. const uint8_t *p = (const uint8_t *)ptr;
  164. do {
  165. if (*p < 16) Serial.print('0');
  166. Serial.print(*p++, HEX);
  167. Serial.print(' ');
  168. } while (--len);
  169. Serial.println();
  170. }