emac_dev.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #include <stdint.h>
  16. #include "soc/emac_reg_v2.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #define EMAC_INTR_ENABLE_BIT (EMAC_TRANSMIT_INTERRUPT_ENABLE | EMAC_RECEIVE_INTERRUPT_ENABLE | EMAC_RECEIVE_BUFFER_UNAVAILABLE_ENABLE | EMAC_NORMAL_INTERRUPT_SUMMARY_ENABLE)
  21. struct dma_desc {
  22. uint32_t desc0;
  23. uint32_t desc1;
  24. uint32_t desc2;
  25. uint32_t desc3;
  26. };
  27. 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. };
  34. void emac_enable_clk(bool enable);
  35. void 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. uint32_t inline emac_read_tx_cur_reg(void)
  49. {
  50. return REG_READ(EMAC_DMATXCURRDESC_REG);
  51. }
  52. uint32_t inline emac_read_rx_cur_reg(void)
  53. {
  54. return REG_READ(EMAC_DMARXCURRDESC_REG);
  55. }
  56. void inline emac_poll_tx_cmd(void)
  57. {
  58. //write any to wake up dma
  59. REG_WRITE(EMAC_DMATXPOLLDEMAND_REG, 1);
  60. }
  61. void inline emac_poll_rx_cmd(void)
  62. {
  63. //write any to wake up dma
  64. REG_WRITE(EMAC_DMARXPOLLDEMAND_REG, 1);
  65. }
  66. void inline emac_disable_rx_intr(void)
  67. {
  68. REG_CLR_BIT(EMAC_DMAINTERRUPT_EN_REG, EMAC_RECEIVE_INTERRUPT_ENABLE);
  69. }
  70. void inline emac_enable_rx_intr(void)
  71. {
  72. REG_SET_BIT(EMAC_DMAINTERRUPT_EN_REG, EMAC_RECEIVE_INTERRUPT_ENABLE);
  73. }
  74. void inline emac_disable_rx_unavail_intr(void)
  75. {
  76. REG_CLR_BIT(EMAC_DMAINTERRUPT_EN_REG, EMAC_RECEIVE_BUFFER_UNAVAILABLE_ENABLE);
  77. }
  78. void inline emac_enable_rx_unavail_intr(void)
  79. {
  80. REG_SET_BIT(EMAC_DMAINTERRUPT_EN_REG, EMAC_RECEIVE_BUFFER_UNAVAILABLE_ENABLE);
  81. }
  82. void IRAM_ATTR inline emac_send_pause_frame_enable(void)
  83. {
  84. REG_SET_BIT(EMAC_EX_PHYINF_CONF_REG, EMAC_EX_SBD_FLOWCTRL);
  85. }
  86. void inline emac_send_pause_zero_frame_enable(void)
  87. {
  88. REG_CLR_BIT(EMAC_EX_PHYINF_CONF_REG, EMAC_EX_SBD_FLOWCTRL);
  89. }
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93. #endif