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

93 行
2.9KB

  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. // Memory allocation
  26. static Device_t memory_Device[3];
  27. static Pipe_t memory_Pipe[8] __attribute__ ((aligned(32)));
  28. static Transfer_t memory_Transfer[34] __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. Device_t *end_device = memory_Device + sizeof(memory_Device)/sizeof(Device_t);
  35. for (Device_t *device = memory_Device; device < end_device; device++) {
  36. free_Device(device);
  37. }
  38. Pipe_t *end_pipe = memory_Pipe + sizeof(memory_Pipe)/sizeof(Pipe_t);
  39. for (Pipe_t *pipe = memory_Pipe; pipe < end_pipe; pipe++) {
  40. free_Pipe(pipe);
  41. }
  42. Transfer_t *end_transfer = memory_Transfer + sizeof(memory_Transfer)/sizeof(Transfer_t);
  43. for (Transfer_t *transfer = memory_Transfer; transfer < end_transfer; transfer++) {
  44. free_Transfer(transfer);
  45. }
  46. }
  47. Device_t * USBHost::allocate_Device(void)
  48. {
  49. Device_t *device = free_Device_list;
  50. if (device) free_Device_list = *(Device_t **)device;
  51. return device;
  52. }
  53. void USBHost::free_Device(Device_t *device)
  54. {
  55. *(Device_t **)device = free_Device_list;
  56. free_Device_list = device;
  57. }
  58. Pipe_t * USBHost::allocate_Pipe(void)
  59. {
  60. Pipe_t *pipe = free_Pipe_list;
  61. if (pipe) free_Pipe_list = *(Pipe_t **)pipe;
  62. return pipe;
  63. }
  64. void USBHost::free_Pipe(Pipe_t *pipe)
  65. {
  66. *(Pipe_t **)pipe = free_Pipe_list;
  67. free_Pipe_list = pipe;
  68. }
  69. Transfer_t * USBHost::allocate_Transfer(void)
  70. {
  71. Transfer_t *transfer = free_Transfer_list;
  72. if (transfer) free_Transfer_list = *(Transfer_t **)transfer;
  73. return transfer;
  74. }
  75. void USBHost::free_Transfer(Transfer_t *transfer)
  76. {
  77. *(Transfer_t **)transfer = free_Transfer_list;
  78. free_Transfer_list = transfer;
  79. }