test_hcd_common.h 4.2 KB

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