emac_common.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. struct dma_extended_desc *dma_etx;
  47. uint32_t cur_tx;
  48. uint32_t dirty_tx;
  49. int32_t cnt_tx;
  50. struct dma_extended_desc *dma_erx;
  51. uint32_t cur_rx;
  52. uint32_t dirty_rx;
  53. int32_t cnt_rx;
  54. uint32_t rx_need_poll;
  55. bool phy_link_up;
  56. enum emac_runtime_status emac_status;
  57. uint8_t macaddr[6];
  58. eth_phy_func phy_init;
  59. eth_tcpip_input_func emac_tcpip_input;
  60. eth_gpio_config_func emac_gpio_config;
  61. eth_phy_check_link_func emac_phy_check_link;
  62. eth_phy_check_init_func emac_phy_check_init;
  63. eth_phy_get_speed_mode_func emac_phy_get_speed_mode;
  64. eth_phy_get_duplex_mode_func emac_phy_get_duplex_mode;
  65. bool emac_flow_ctrl_enable;
  66. bool emac_flow_ctrl_partner_support;
  67. eth_phy_get_partner_pause_enable_func emac_phy_get_partner_pause_enable;
  68. eth_phy_power_enable_func emac_phy_power_enable;
  69. };
  70. enum emac_post_type {
  71. EMAC_POST_ASYNC,
  72. EMAC_POST_SYNC,
  73. };
  74. struct emac_post_cmd {
  75. void *cmd;
  76. enum emac_post_type post_type;
  77. };
  78. struct emac_tx_cmd {
  79. uint8_t *buf;
  80. uint16_t size;
  81. int8_t err;
  82. };
  83. struct emac_open_cmd {
  84. int8_t err;
  85. };
  86. struct emac_close_cmd {
  87. int8_t err;
  88. };
  89. #if CONFIG_ETHERNET
  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. #else
  94. #define DMA_RX_BUF_NUM 1
  95. #define DMA_TX_BUF_NUM 1
  96. #define EMAC_TASK_PRIORITY 10
  97. #endif
  98. #define DMA_RX_BUF_SIZE 1600
  99. #define DMA_TX_BUF_SIZE 1600
  100. //rest buf num
  101. #define FLOW_CONTROL_HIGH_WATERMARK 3
  102. //used buf num
  103. #define FLOW_CONTROL_LOW_WATERMARK 6
  104. #define PHY_LINK_CHECK_NUM 5
  105. #define EMAC_CMD_OK 0
  106. #define EMAC_CMD_FAIL -1
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif