test_hcd_common.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "freertos/FreeRTOS.h"
  7. #include "freertos/semphr.h"
  8. #include "hcd.h"
  9. #include "usb_private.h"
  10. #include "usb/usb_types_ch9.h"
  11. extern hcd_port_handle_t port_hdl;
  12. #define URB_CONTEXT_VAL ((void *)0xDEADBEEF)
  13. // ------------------------------------------------- HCD Event Test ----------------------------------------------------
  14. /**
  15. * @brief Expect (wait) for an HCD port event
  16. *
  17. * @param port_hdl Port handle to expect event from
  18. * @param expected_event Port event to expect
  19. */
  20. void test_hcd_expect_port_event(hcd_port_handle_t port_hdl, hcd_port_event_t expected_event);
  21. /**
  22. * @brief Expect (wait) for an HCD pipe event
  23. *
  24. * @param pipe_hdl Pipe handle to expect event from
  25. * @param expected_event Pipe event to expect
  26. */
  27. void test_hcd_expect_pipe_event(hcd_pipe_handle_t pipe_hdl, hcd_pipe_event_t expected_event);
  28. /**
  29. * @brief Get the current number of queued port events (dequeued using test_hcd_expect_port_event())
  30. *
  31. * @param port_hdl Port handle
  32. * @return int Number of port events currently queued
  33. */
  34. int test_hcd_get_num_port_events(hcd_port_handle_t port_hdl);
  35. /**
  36. * @brief Get the current number of queued pipe events (dequeued using test_hcd_expect_pipe_event())
  37. *
  38. * @param pipe_hdl Pipe handle
  39. * @return int Number of pipe events currently queued
  40. */
  41. int test_hcd_get_num_pipe_events(hcd_pipe_handle_t pipe_hdl);
  42. // ----------------------------------------------- Driver/Port Related -------------------------------------------------
  43. /**
  44. * @brief Sets up the HCD and initializes an HCD port.
  45. *
  46. * @return hcd_port_handle_t Port handle
  47. */
  48. hcd_port_handle_t test_hcd_setup(void);
  49. /**
  50. * @brief Frees and HCD port and uninstalls the HCD
  51. *
  52. * @param port_hdl Port handle
  53. */
  54. void test_hcd_teardown(hcd_port_handle_t port_hdl);
  55. /**
  56. * @brief Wait for a connection on an HCD port
  57. *
  58. * @note This function will internally call test_usb_set_phy_state() to allow for a connection
  59. *
  60. * @param port_hdl Port handle
  61. * @return usb_speed_t Speed of the connected device
  62. */
  63. usb_speed_t test_hcd_wait_for_conn(hcd_port_handle_t port_hdl);
  64. /**
  65. * @brief Wait for a disconnection on an HCD port
  66. *
  67. * @note This fucntion will internally call test_usb_set_phy_state() to force a disconnection
  68. *
  69. * @param port_hdl Port handle
  70. * @param already_disabled Whether the HCD port is already in the disabled state
  71. */
  72. void test_hcd_wait_for_disconn(hcd_port_handle_t port_hdl, bool already_disabled);
  73. // ------------------------------------------------- Pipe alloc/free ---------------------------------------------------
  74. /**
  75. * @brief Test the allocation of a pipe
  76. *
  77. * @param port_hdl Port handle
  78. * @param ep_desc Endpoint descriptor
  79. * @param dev_addr Device address of the pipe
  80. * @param dev_speed Device speed of the pipe
  81. * @return hcd_pipe_handle_t Pipe handle
  82. */
  83. hcd_pipe_handle_t test_hcd_pipe_alloc(hcd_port_handle_t port_hdl, const usb_ep_desc_t *ep_desc, uint8_t dev_addr, usb_speed_t dev_speed);
  84. /**
  85. * @brief Test the freeing of a pipe
  86. *
  87. * @param pipe_hdl Pipe handle
  88. */
  89. void test_hcd_pipe_free(hcd_pipe_handle_t pipe_hdl);
  90. /**
  91. * @brief Allocate a URB
  92. *
  93. * @param num_isoc_packets Number of isochronous packets
  94. * @param data_buffer_size Size of the data buffer of the URB
  95. * @return urb_t* URB
  96. */
  97. urb_t *test_hcd_alloc_urb(int num_isoc_packets, size_t data_buffer_size);
  98. /**
  99. * @brief Free a URB
  100. *
  101. * @param urb URB
  102. */
  103. void test_hcd_free_urb(urb_t *urb);
  104. // --------------------------------------------------- Enumeration -----------------------------------------------------
  105. /**
  106. * @brief Do some basic enumeration of the device
  107. *
  108. * For tests that need a device to have been enumerated (such as bulk tests). This function will enumerate that device
  109. * using the device's default pipe. The minimal enumeration will include
  110. *
  111. * - Getting the device's descriptor and updating the default pipe's MPS
  112. * - Setting the device's address and updating the default pipe to use that address
  113. * - Setting the device to configuration 1 (i.e., the first configuration found
  114. *
  115. * @param default_pipe The connected device's default pipe
  116. * @return uint8_t The address of the device after enumeration
  117. */
  118. uint8_t test_hcd_enum_device(hcd_pipe_handle_t default_pipe);