esp_eth.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // Copyright 2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "esp_eth_com.h"
  19. #include "esp_eth_mac.h"
  20. #include "esp_eth_phy.h"
  21. /**
  22. * @brief Handle of Ethernet driver
  23. *
  24. */
  25. typedef void *esp_eth_handle_t;
  26. /**
  27. * @brief Configuration of Ethernet driver
  28. *
  29. */
  30. typedef struct {
  31. /**
  32. * @brief Ethernet MAC object
  33. *
  34. */
  35. esp_eth_mac_t *mac;
  36. /**
  37. * @brief Ethernet PHY object
  38. *
  39. */
  40. esp_eth_phy_t *phy;
  41. /**
  42. * @brief Period time of checking Ethernet link status
  43. *
  44. */
  45. uint32_t check_link_period_ms;
  46. /**
  47. * @brief Input frame buffer to user's stack
  48. *
  49. * @param[in] eth_handle: handle of Ethernet driver
  50. * @param[in] buffer: frame buffer that will get input to upper stack
  51. * @param[in] length: length of the frame buffer
  52. *
  53. * @return
  54. * - ESP_OK: input frame buffer to upper stack successfully
  55. * - ESP_FAIL: error occurred when inputting buffer to upper stack
  56. *
  57. */
  58. esp_err_t (*stack_input)(esp_eth_handle_t eth_handle, uint8_t *buffer, uint32_t length);
  59. /**
  60. * @brief Callback function invoked when lowlevel initialization is finished
  61. *
  62. * @param[in] eth_handle: handle of Ethernet driver
  63. *
  64. * @return
  65. * - ESP_OK: process extra lowlevel initialization successfully
  66. * - ESP_FAIL: error occurred when processing extra lowlevel initialization
  67. */
  68. esp_err_t (*on_lowlevel_init_done)(esp_eth_handle_t eth_handle);
  69. /**
  70. * @brief Callback function invoked when lowlevel deinitialization is finished
  71. *
  72. * @param[in] eth_handle: handle of Ethernet driver
  73. *
  74. * @return
  75. * - ESP_OK: process extra lowlevel deinitialization successfully
  76. * - ESP_FAIL: error occurred when processing extra lowlevel deinitialization
  77. */
  78. esp_err_t (*on_lowlevel_deinit_done)(esp_eth_handle_t eth_handle);
  79. } esp_eth_config_t;
  80. /**
  81. * @brief Default configuration for Ethernet driver
  82. *
  83. */
  84. #define ETH_DEFAULT_CONFIG(emac, ephy) \
  85. { \
  86. .mac = emac, \
  87. .phy = ephy, \
  88. .check_link_period_ms = 2000, \
  89. .stack_input = NULL, \
  90. .on_lowlevel_init_done = NULL, \
  91. .on_lowlevel_deinit_done = NULL, \
  92. }
  93. /**
  94. * @brief Install Ethernet driver
  95. *
  96. * @param[in] config: configuration of the Ethernet driver
  97. * @param[out] out_hdl: handle of Ethernet driver
  98. *
  99. * @return
  100. * - ESP_OK: install esp_eth driver successfully
  101. * - ESP_ERR_INVALID_ARG: install esp_eth driver failed because of some invalid argument
  102. * - ESP_ERR_NO_MEM: install esp_eth driver failed because there's no memory for driver
  103. * - ESP_FAIL: install esp_eth driver failed because some other error occurred
  104. */
  105. esp_err_t esp_eth_driver_install(const esp_eth_config_t *config, esp_eth_handle_t *out_hdl);
  106. /**
  107. * @brief Uninstall Ethernet driver
  108. *
  109. * @param[in] hdl: handle of Ethernet driver
  110. *
  111. * @return
  112. * - ESP_OK: uninstall esp_eth driver successfully
  113. * - ESP_ERR_INVALID_ARG: uninstall esp_eth driver failed because of some invalid argument
  114. * - ESP_FAIL: uninstall esp_eth driver failed because some other error occurred
  115. */
  116. esp_err_t esp_eth_driver_uninstall(esp_eth_handle_t hdl);
  117. /**
  118. * @brief General Transmit
  119. *
  120. * @param[in] hdl: handle of Ethernet driver
  121. * @param[in] buf: buffer of the packet to transfer
  122. * @param[in] length: length of the buffer to transfer
  123. *
  124. * @return
  125. * - ESP_OK: transmit frame buffer successfully
  126. * - ESP_ERR_INVALID_ARG: transmit frame buffer failed because of some invalid argument
  127. * - ESP_FAIL: transmit frame buffer failed because some other error occurred
  128. */
  129. esp_err_t esp_eth_transmit(esp_eth_handle_t hdl, uint8_t *buf, uint32_t length);
  130. /**
  131. * @brief General Receive
  132. *
  133. * @param[in] hdl: handle of Ethernet driver
  134. * @param[out] buf: buffer to preserve the received packet
  135. * @param[out] length: length of the received packet
  136. *
  137. * @note Before this function got invoked, the value of "length" should set by user, equals the size of buffer.
  138. * After the function returned, the value of "length" means the real length of received data.
  139. *
  140. * @return
  141. * - ESP_OK: receive frame buffer successfully
  142. * - ESP_ERR_INVALID_ARG: receive frame buffer failed because of some invalid argument
  143. * - ESP_ERR_INVALID_SIZE: input buffer size is not enough to hold the incoming data.
  144. * in this case, value of returned "length" indicates the real size of incoming data.
  145. * - ESP_FAIL: receive frame buffer failed because some other error occurred
  146. */
  147. esp_err_t esp_eth_receive(esp_eth_handle_t hdl, uint8_t *buf, uint32_t *length);
  148. /**
  149. * @brief Misc IO function of Etherent driver
  150. *
  151. * @param[in] hdl: handle of Ethernet driver
  152. * @param[in] cmd: IO control command
  153. * @param[in] data: specificed data for command
  154. *
  155. * @return
  156. * - ESP_OK: process io command successfully
  157. * - ESP_ERR_INVALID_ARG: process io command failed because of some invalid argument
  158. * - ESP_FAIL: process io command failed because some other error occurred
  159. */
  160. esp_err_t esp_eth_ioctl(esp_eth_handle_t hdl, esp_eth_io_cmd_t cmd, void *data);
  161. #ifdef __cplusplus
  162. }
  163. #endif