Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

112 lines
3.2KB

  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. #ifndef USB_HOST_TEENSY36_
  24. #define USB_HOST_TEENSY36_
  25. #include <stdint.h>
  26. typedef struct Device_struct Device_t;
  27. typedef struct Pipe_struct Pipe_t;
  28. typedef struct Transfer_struct Transfer_t;
  29. typedef union {
  30. struct {
  31. union {
  32. struct {
  33. uint8_t bmRequestType;
  34. uint8_t bRequest;
  35. };
  36. uint16_t wRequestAndType;
  37. };
  38. uint16_t wValue;
  39. uint16_t wIndex;
  40. uint16_t wLength;
  41. };
  42. struct {
  43. uint32_t word1;
  44. uint32_t word2;
  45. };
  46. } setup_t;
  47. struct Device_struct {
  48. Pipe_t *control_pipe;
  49. Device_t *next;
  50. setup_t setup;
  51. uint8_t speed; // 0=12, 1=1.5, 2=480 Mbit/sec
  52. uint8_t address;
  53. uint8_t hub_address;
  54. uint8_t hub_port;
  55. uint8_t enum_state;
  56. };
  57. struct Pipe_struct {
  58. // Queue Head (QH), EHCI page 46-50
  59. struct { // must be aligned to 32 byte boundary
  60. volatile uint32_t horizontal_link;
  61. volatile uint32_t capabilities[2];
  62. volatile uint32_t current;
  63. volatile uint32_t next;
  64. volatile uint32_t alt_next;
  65. volatile uint32_t token;
  66. volatile uint32_t buffer[5];
  67. } qh;
  68. Device_t *device;
  69. uint8_t type; // 0=control, 1=isochronous, 2=bulk, 3=interrupt
  70. uint8_t direction; // 0=out, 1=in (changes for control, others fixed)
  71. uint8_t unusedbyte[2];
  72. void *callback_object; // TODO: C++ callbacks??
  73. void (*callback_function)(const Transfer_t *);
  74. };
  75. struct Transfer_struct {
  76. // Queue Element Transfer Descriptor (qTD), EHCI pg 40-45
  77. struct { // must be aligned to 32 byte boundary
  78. volatile uint32_t next;
  79. volatile uint32_t alt_next;
  80. volatile uint32_t token;
  81. volatile uint32_t buffer[5];
  82. } qtd;
  83. // linked list of queued, not-yet-completed transfers
  84. Transfer_t *next_followup;
  85. Transfer_t *prev_followup;
  86. // data to be used by callback function
  87. Pipe_t *pipe;
  88. void *buffer;
  89. uint32_t length;
  90. uint32_t unused[3];
  91. };
  92. void init_Device_Pipe_Transfer_memory(void);
  93. Device_t * allocate_Device(void);
  94. void free_Device(Device_t *q);
  95. Pipe_t * allocate_Pipe(void);
  96. void free_Pipe(Pipe_t *q);
  97. Transfer_t * allocate_Transfer(void);
  98. void free_Transfer(Transfer_t *q);
  99. #endif