Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

109 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. #include <Arduino.h>
  24. #include "USBHost_t36.h" // Read this header first for key info
  25. // Memory allocation
  26. static Device_t memory_Device[1];
  27. static Pipe_t memory_Pipe[1] __attribute__ ((aligned(32)));
  28. static Transfer_t memory_Transfer[4] __attribute__ ((aligned(32)));
  29. static Device_t * free_Device_list = NULL;
  30. static Pipe_t * free_Pipe_list = NULL;
  31. static Transfer_t * free_Transfer_list = NULL;
  32. void USBHost::init_Device_Pipe_Transfer_memory(void)
  33. {
  34. contribute_Devices(memory_Device, sizeof(memory_Device)/sizeof(Device_t));
  35. contribute_Pipes(memory_Pipe, sizeof(memory_Pipe)/sizeof(Pipe_t));
  36. contribute_Transfers(memory_Transfer, sizeof(memory_Transfer)/sizeof(Transfer_t));
  37. }
  38. Device_t * USBHost::allocate_Device(void)
  39. {
  40. Device_t *device = free_Device_list;
  41. if (device) free_Device_list = *(Device_t **)device;
  42. return device;
  43. }
  44. void USBHost::free_Device(Device_t *device)
  45. {
  46. *(Device_t **)device = free_Device_list;
  47. free_Device_list = device;
  48. }
  49. Pipe_t * USBHost::allocate_Pipe(void)
  50. {
  51. Pipe_t *pipe = free_Pipe_list;
  52. if (pipe) free_Pipe_list = *(Pipe_t **)pipe;
  53. return pipe;
  54. }
  55. void USBHost::free_Pipe(Pipe_t *pipe)
  56. {
  57. *(Pipe_t **)pipe = free_Pipe_list;
  58. free_Pipe_list = pipe;
  59. }
  60. Transfer_t * USBHost::allocate_Transfer(void)
  61. {
  62. Transfer_t *transfer = free_Transfer_list;
  63. if (transfer) free_Transfer_list = *(Transfer_t **)transfer;
  64. return transfer;
  65. }
  66. void USBHost::free_Transfer(Transfer_t *transfer)
  67. {
  68. *(Transfer_t **)transfer = free_Transfer_list;
  69. free_Transfer_list = transfer;
  70. }
  71. void USBHost::contribute_Devices(Device_t *devices, uint32_t num)
  72. {
  73. Device_t *end = devices + num;
  74. for (Device_t *device = devices ; device < end; device++) {
  75. free_Device(device);
  76. }
  77. }
  78. void USBHost::contribute_Pipes(Pipe_t *pipes, uint32_t num)
  79. {
  80. Pipe_t *end = pipes + num;
  81. for (Pipe_t *pipe = pipes; pipe < end; pipe++) {
  82. free_Pipe(pipe);
  83. }
  84. }
  85. void USBHost::contribute_Transfers(Transfer_t *transfers, uint32_t num)
  86. {
  87. Transfer_t *end = transfers + num;
  88. for (Transfer_t *transfer = transfers ; transfer < end; transfer++) {
  89. free_Transfer(transfer);
  90. }
  91. }