emac_common.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #include <stdint.h>
  16. #include "esp_err.h"
  17. #include "emac_dev.h"
  18. #include "esp_eth.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef uint32_t emac_sig_t;
  23. typedef uint32_t emac_par_t;
  24. typedef struct {
  25. emac_sig_t sig;
  26. emac_par_t par;
  27. } emac_event_t;
  28. enum emac_runtime_status {
  29. EMAC_RUNTIME_NOT_INIT = 0,
  30. EMAC_RUNTIME_INIT,
  31. EMAC_RUNTIME_START,
  32. EMAC_RUNTIME_STOP,
  33. };
  34. enum {
  35. SIG_EMAC_RX_UNAVAIL,
  36. SIG_EMAC_TX_DONE,
  37. SIG_EMAC_RX_DONE,
  38. SIG_EMAC_START,
  39. SIG_EMAC_STOP,
  40. SIG_EMAC_CHECK_LINK,
  41. SIG_EMAC_MAX
  42. };
  43. struct emac_config_data {
  44. eth_phy_base_t phy_addr;
  45. eth_mode_t mac_mode;
  46. eth_clock_mode_t clock_mode;
  47. struct dma_extended_desc *dma_etx;
  48. uint32_t cur_tx;
  49. uint32_t dirty_tx;
  50. int32_t cnt_tx;
  51. struct dma_extended_desc *dma_erx;
  52. uint32_t cur_rx;
  53. uint32_t dirty_rx;
  54. int32_t cnt_rx;
  55. uint32_t rx_need_poll;
  56. bool phy_link_up;
  57. enum emac_runtime_status emac_status;
  58. uint8_t macaddr[6];
  59. eth_phy_func phy_init;
  60. eth_tcpip_input_func emac_tcpip_input;
  61. eth_gpio_config_func emac_gpio_config;
  62. eth_phy_check_link_func emac_phy_check_link;
  63. eth_phy_check_init_func emac_phy_check_init;
  64. eth_phy_get_speed_mode_func emac_phy_get_speed_mode;
  65. eth_phy_get_duplex_mode_func emac_phy_get_duplex_mode;
  66. bool emac_flow_ctrl_enable;
  67. bool emac_flow_ctrl_partner_support;
  68. eth_phy_get_partner_pause_enable_func emac_phy_get_partner_pause_enable;
  69. eth_phy_power_enable_func emac_phy_power_enable;
  70. uint32_t reset_timeout_ms;
  71. };
  72. enum emac_post_type {
  73. EMAC_POST_ASYNC,
  74. EMAC_POST_SYNC,
  75. };
  76. struct emac_post_cmd {
  77. void *cmd;
  78. enum emac_post_type post_type;
  79. };
  80. struct emac_tx_cmd {
  81. uint8_t *buf;
  82. uint16_t size;
  83. int8_t err;
  84. };
  85. struct emac_open_cmd {
  86. int8_t err;
  87. };
  88. struct emac_close_cmd {
  89. int8_t err;
  90. };
  91. #define DMA_RX_BUF_NUM CONFIG_DMA_RX_BUF_NUM
  92. #define DMA_TX_BUF_NUM CONFIG_DMA_TX_BUF_NUM
  93. #define EMAC_TASK_PRIORITY CONFIG_EMAC_TASK_PRIORITY
  94. #define EMAC_TASK_STACK_SIZE CONFIG_EMAC_TASK_STACK_SIZE
  95. #define DMA_RX_BUF_SIZE 1600
  96. #define DMA_TX_BUF_SIZE 1600
  97. //rest buf num
  98. #define FLOW_CONTROL_HIGH_WATERMARK 3
  99. //used buf num
  100. #define FLOW_CONTROL_LOW_WATERMARK 6
  101. #define PHY_LINK_CHECK_NUM 5
  102. #define EMAC_CMD_OK 0
  103. #define EMAC_CMD_FAIL -1
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif