Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_t36.h" // Read this header first for key info
  25. // Printing of specific data structures. When this is enabled,
  26. // a tremendous amount of debug printing occurs. It's done all
  27. // from interrupt context, so this should never normally be
  28. // enabled for regular programs that print from the Arduino sketch.
  29. #ifdef USBHOST_PRINT_DEBUG
  30. void USBHost::print_(const Transfer_t *transfer)
  31. {
  32. if (!((uint32_t)transfer & 0xFFFFFFE0)) return;
  33. Serial.print("Transfer @ ");
  34. Serial.println(((uint32_t)transfer & 0xFFFFFFE0), HEX);
  35. Serial.print(" next: ");
  36. Serial.println(transfer->qtd.next, HEX);
  37. Serial.print(" anext: ");
  38. Serial.println(transfer->qtd.alt_next, HEX);
  39. Serial.print(" token: ");
  40. Serial.println(transfer->qtd.token, HEX);
  41. Serial.print(" bufs: ");
  42. for (int i=0; i < 5; i++) {
  43. Serial.print(transfer->qtd.buffer[i], HEX);
  44. if (i < 4) Serial.print(',');
  45. }
  46. Serial.println();
  47. }
  48. void USBHost::print_(const Transfer_t *first, const Transfer_t *last)
  49. {
  50. Serial.print("Transfer Followup List ");
  51. Serial.print((uint32_t)first, HEX);
  52. Serial.print(" to ");
  53. Serial.println((uint32_t)last, HEX);
  54. Serial.println(" forward:");
  55. while (first) {
  56. Serial.print(" ");
  57. Serial.print((uint32_t)first, HEX);
  58. print_token(first->qtd.token);
  59. first = first->next_followup;
  60. }
  61. Serial.println(" backward:");
  62. while (last) {
  63. Serial.print(" ");
  64. Serial.print((uint32_t)last, HEX);
  65. print_token(last->qtd.token);
  66. last = last->prev_followup;
  67. }
  68. }
  69. void USBHost::print_token(uint32_t token)
  70. {
  71. switch ((token >> 8) & 3) {
  72. case 0:
  73. Serial.print(" OUT ");
  74. Serial.println((token >> 16) & 0x7FFF);
  75. break;
  76. case 1:
  77. Serial.print(" IN ");
  78. Serial.println((token >> 16) & 0x7FFF);
  79. break;
  80. case 2:
  81. Serial.println(" SETUP");
  82. break;
  83. default:
  84. Serial.println(" unknown");
  85. }
  86. }
  87. void USBHost::print_(const Pipe_t *pipe)
  88. {
  89. if (!((uint32_t)pipe & 0xFFFFFFE0)) return;
  90. Serial.print("Pipe ");
  91. if (pipe->type == 0) Serial.print("control");
  92. else if (pipe->type == 1) Serial.print("isochronous");
  93. else if (pipe->type == 2) Serial.print("bulk");
  94. else if (pipe->type == 3) Serial.print("interrupt");
  95. Serial.print(pipe->direction ? " IN" : " OUT");
  96. Serial.print(" @ ");
  97. Serial.println((uint32_t)pipe, HEX);
  98. Serial.print(" horiz link: ");
  99. Serial.println(pipe->qh.horizontal_link, HEX);
  100. Serial.print(" capabilities: ");
  101. Serial.print(pipe->qh.capabilities[0], HEX);
  102. Serial.print(',');
  103. Serial.println(pipe->qh.capabilities[1], HEX);
  104. Serial.println(" overlay:");
  105. Serial.print(" cur: ");
  106. Serial.println(pipe->qh.current, HEX);
  107. Serial.print(" next: ");
  108. Serial.println(pipe->qh.next, HEX);
  109. Serial.print(" anext: ");
  110. Serial.println(pipe->qh.alt_next, HEX);
  111. Serial.print(" token: ");
  112. Serial.println(pipe->qh.token, HEX);
  113. Serial.print(" bufs: ");
  114. for (int i=0; i < 5; i++) {
  115. Serial.print(pipe->qh.buffer[i], HEX);
  116. if (i < 4) Serial.print(',');
  117. }
  118. Serial.println();
  119. const Transfer_t *t = (Transfer_t *)pipe->qh.next;
  120. while (((uint32_t)t & 0xFFFFFFE0)) {
  121. print_(t);
  122. t = (Transfer_t *)t->qtd.next;
  123. }
  124. //Serial.print();
  125. }
  126. void USBHost::print_driverlist(const char *name, const USBDriver *driver)
  127. {
  128. Serial.print("USBDriver (");
  129. Serial.print(name);
  130. Serial.print(") list: ");
  131. if (driver == NULL) {
  132. Serial.println("(empty");
  133. return;
  134. }
  135. uint32_t count=0;
  136. for (const USBDriver *p = driver; p; p = p->next) {
  137. Serial.print((uint32_t)p, HEX);
  138. if (p->next) Serial.print(" -> ");
  139. if (++count > 30) {
  140. Serial.println("abort:list too long");
  141. return;
  142. }
  143. }
  144. Serial.println();
  145. }
  146. void USBHost::print_qh_list(const Pipe_t *list)
  147. {
  148. if (!list) {
  149. Serial.println("(empty)");
  150. return;
  151. }
  152. const Pipe_t *node = list;
  153. while (1) {
  154. Serial.print((uint32_t)node, HEX);
  155. node = (const Pipe_t *)(node->qh.horizontal_link & 0xFFFFFFE0);
  156. if (!node) break;
  157. if (node == list) {
  158. Serial.print(" (loops)");
  159. break;
  160. }
  161. Serial.print(" -> ");
  162. }
  163. Serial.println();
  164. }
  165. void USBHost::print_hexbytes(const void *ptr, uint32_t len)
  166. {
  167. if (ptr == NULL || len == 0) return;
  168. const uint8_t *p = (const uint8_t *)ptr;
  169. do {
  170. if (*p < 16) Serial.print('0');
  171. Serial.print(*p++, HEX);
  172. Serial.print(' ');
  173. } while (--len);
  174. Serial.println();
  175. }
  176. #endif