選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

host.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. };
  56. struct Pipe_struct {
  57. // Queue Head (QH), EHCI page 46-50
  58. struct { // must be aligned to 32 byte boundary
  59. volatile uint32_t horizontal_link;
  60. volatile uint32_t capabilities[2];
  61. volatile uint32_t current;
  62. volatile uint32_t next;
  63. volatile uint32_t alt_next;
  64. volatile uint32_t token;
  65. volatile uint32_t buffer[5];
  66. } qh;
  67. Device_t *device;
  68. uint8_t type; // 0=control, 1=isochronous, 2=bulk, 3=interrupt
  69. uint8_t direction; // 0=out, 1=in
  70. //uint8_t data01; // next packet DATA0 or DATA1
  71. uint8_t unusedbyte[2];
  72. uint32_t unused[2];
  73. };
  74. struct Transfer_struct {
  75. // Queue Element Transfer Descriptor (qTD), EHCI pg 40-45
  76. struct { // must be aligned to 32 byte boundary
  77. volatile uint32_t next;
  78. volatile uint32_t alt_next;
  79. volatile uint32_t token;
  80. volatile uint32_t buffer[5];
  81. } qtd;
  82. Pipe_t *pipe;
  83. void *callback;
  84. void *callback_arg;
  85. Transfer_t *next_followup;
  86. uint32_t unused[4];
  87. };
  88. Device_t * allocate_Device(void);
  89. void free_Device(Device_t *q);
  90. Pipe_t * allocate_Pipe(void);
  91. void free_Pipe(Pipe_t *q);
  92. Transfer_t * allocate_Transfer(void);
  93. void free_Transfer(Transfer_t *q);
  94. #endif