emac_common.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright 2015-2016 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _EMAC_COMMON_H_
  14. #define _EMAC_COMMON_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "esp_eth.h"
  19. #include "emac_dev.h"
  20. typedef uint32_t emac_sig_t;
  21. typedef uint32_t emac_par_t;
  22. typedef struct {
  23. emac_sig_t sig;
  24. emac_par_t par;
  25. } emac_event_t;
  26. enum emac_runtime_status {
  27. EMAC_RUNTIME_NOT_INIT = 0,
  28. EMAC_RUNTIME_INIT,
  29. EMAC_RUNTIME_START,
  30. EMAC_RUNTIME_STOP,
  31. };
  32. enum {
  33. SIG_EMAC_RX_UNAVAIL,
  34. SIG_EMAC_TX_DONE,
  35. SIG_EMAC_RX_DONE,
  36. SIG_EMAC_START,
  37. SIG_EMAC_STOP,
  38. SIG_EMAC_CHECK_LINK,
  39. SIG_EMAC_MAX
  40. };
  41. struct emac_config_data {
  42. eth_phy_base_t phy_addr;
  43. eth_mode_t mac_mode;
  44. eth_clock_mode_t clock_mode;
  45. struct dma_extended_desc *dma_etx;
  46. uint32_t cur_tx;
  47. uint32_t dirty_tx;
  48. int32_t cnt_tx;
  49. struct dma_extended_desc *dma_erx;
  50. uint32_t cur_rx;
  51. uint32_t dirty_rx;
  52. int32_t cnt_rx;
  53. uint32_t rx_need_poll;
  54. bool phy_link_up;
  55. enum emac_runtime_status emac_status;
  56. uint8_t macaddr[6];
  57. eth_phy_func phy_init;
  58. eth_tcpip_input_func emac_tcpip_input;
  59. eth_gpio_config_func emac_gpio_config;
  60. eth_phy_check_link_func emac_phy_check_link;
  61. eth_phy_check_init_func emac_phy_check_init;
  62. eth_phy_get_speed_mode_func emac_phy_get_speed_mode;
  63. eth_phy_get_duplex_mode_func emac_phy_get_duplex_mode;
  64. bool emac_flow_ctrl_enable;
  65. bool emac_flow_ctrl_partner_support;
  66. eth_phy_get_partner_pause_enable_func emac_phy_get_partner_pause_enable;
  67. eth_phy_power_enable_func emac_phy_power_enable;
  68. uint32_t reset_timeout_ms;
  69. bool promiscuous_enable;
  70. };
  71. enum emac_post_type {
  72. EMAC_POST_ASYNC,
  73. EMAC_POST_SYNC,
  74. };
  75. struct emac_post_cmd {
  76. void *cmd;
  77. enum emac_post_type post_type;
  78. };
  79. struct emac_tx_cmd {
  80. uint8_t *buf;
  81. uint16_t size;
  82. int8_t err;
  83. };
  84. struct emac_open_cmd {
  85. int8_t err;
  86. };
  87. struct emac_close_cmd {
  88. int8_t err;
  89. };
  90. #define DMA_RX_BUF_NUM CONFIG_DMA_RX_BUF_NUM
  91. #define DMA_TX_BUF_NUM CONFIG_DMA_TX_BUF_NUM
  92. #define EMAC_TASK_PRIORITY CONFIG_EMAC_TASK_PRIORITY
  93. #define EMAC_TASK_STACK_SIZE CONFIG_EMAC_TASK_STACK_SIZE
  94. #define DMA_RX_BUF_SIZE 1600
  95. #define DMA_TX_BUF_SIZE 1600
  96. #define FLOW_CONTROL_HIGH_WATERMARK 3
  97. #define FLOW_CONTROL_LOW_WATERMARK 6
  98. #define PHY_LINK_CHECK_NUM 5
  99. #define EMAC_CMD_OK 0
  100. #define EMAC_CMD_FAIL -1
  101. #ifdef __cplusplus
  102. }
  103. #endif
  104. #endif