emac_dev.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_DEV_H_
  14. #define _EMAC_DEV_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "esp_types.h"
  19. #include "soc/emac_reg_v2.h"
  20. #define EMAC_INTR_ENABLE_BIT (EMAC_DMAIN_TIE | EMAC_DMAIN_RIE | EMAC_DMAIN_RBUE | EMAC_DMAIN_NISE)
  21. struct dma_desc {
  22. uint32_t desc0;
  23. uint32_t desc1;
  24. uint32_t desc2;
  25. uint32_t desc3;
  26. };
  27. typedef struct dma_extended_desc {
  28. struct dma_desc basic;
  29. uint32_t desc4;
  30. uint32_t desc5;
  31. uint32_t desc6;
  32. uint32_t desc7;
  33. } dma_extended_desc_t;
  34. void emac_enable_clk(bool enable);
  35. esp_err_t emac_reset(void);
  36. void emac_set_gpio_pin_rmii(void);
  37. void emac_set_gpio_pin_mii(void);
  38. uint32_t emac_read_mac_version(void);
  39. void emac_dma_init(void);
  40. void emac_mac_init(void);
  41. void emac_enable_dma_tx(void);
  42. void emac_enable_dma_rx(void);
  43. void emac_disable_dma_tx(void);
  44. void emac_disable_dma_rx(void);
  45. void emac_enable_flowctrl(void);
  46. void emac_disable_flowctrl(void);
  47. void emac_mac_enable_txrx(void);
  48. void emac_enable_promiscuous(void);
  49. void emac_disable_promiscuous(void);
  50. static inline uint32_t emac_read_tx_cur_reg(void)
  51. {
  52. return REG_READ(EMAC_DMATXCURRDESC_REG);
  53. }
  54. static inline uint32_t emac_read_rx_cur_reg(void)
  55. {
  56. return REG_READ(EMAC_DMARXCURRDESC_REG);
  57. }
  58. static inline void emac_poll_tx_cmd(void)
  59. {
  60. //write any to wake up dma
  61. REG_WRITE(EMAC_DMATXPOLLDEMAND_REG, 1);
  62. }
  63. static inline void emac_poll_rx_cmd(void)
  64. {
  65. //write any to wake up dma
  66. REG_WRITE(EMAC_DMARXPOLLDEMAND_REG, 1);
  67. }
  68. static inline void emac_disable_rx_intr(void)
  69. {
  70. REG_CLR_BIT(EMAC_DMAIN_EN_REG, EMAC_DMAIN_RIE);
  71. }
  72. static inline void emac_enable_rx_intr(void)
  73. {
  74. REG_SET_BIT(EMAC_DMAIN_EN_REG, EMAC_DMAIN_RIE);
  75. }
  76. static inline void emac_disable_rx_unavail_intr(void)
  77. {
  78. REG_CLR_BIT(EMAC_DMAIN_EN_REG, EMAC_DMAIN_RBUE);
  79. }
  80. static inline void emac_enable_rx_unavail_intr(void)
  81. {
  82. REG_SET_BIT(EMAC_DMAIN_EN_REG, EMAC_DMAIN_RBUE);
  83. }
  84. static inline void IRAM_ATTR emac_send_pause_frame_enable(void)
  85. {
  86. REG_SET_BIT(EMAC_EX_PHYINF_CONF_REG, EMAC_EX_SBD_FLOWCTRL);
  87. }
  88. static inline void emac_send_pause_zero_frame_enable(void)
  89. {
  90. REG_CLR_BIT(EMAC_EX_PHYINF_CONF_REG, EMAC_EX_SBD_FLOWCTRL);
  91. }
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif