emac_dev.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_set_clk_rmii(void);
  36. void emac_set_clk_mii(void);
  37. void emac_reset(void);
  38. void emac_set_gpio_pin_rmii(void);
  39. void emac_set_gpio_pin_mii(void);
  40. uint32_t emac_read_mac_version(void);
  41. void emac_dma_init(void);
  42. void emac_mac_init(void);
  43. void emac_enable_dma_tx(void);
  44. void emac_enable_dma_rx(void);
  45. void emac_disable_dma_tx(void);
  46. void emac_disable_dma_rx(void);
  47. uint32_t inline emac_read_tx_cur_reg(void)
  48. {
  49. return REG_READ(EMAC_DMATXCURRDESC_REG);
  50. }
  51. uint32_t inline emac_read_rx_cur_reg(void)
  52. {
  53. return REG_READ(EMAC_DMARXCURRDESC_REG);
  54. }
  55. void inline emac_poll_tx_cmd(void)
  56. {
  57. //write any to wake up dma
  58. REG_WRITE(EMAC_DMATXPOLLDEMAND_REG, 1);
  59. }
  60. void inline emac_poll_rx_cmd(void)
  61. {
  62. //write any to wake up dma
  63. REG_WRITE(EMAC_DMARXPOLLDEMAND_REG, 1);
  64. }
  65. void inline emac_disable_rx_intr(void)
  66. {
  67. REG_CLR_BIT(EMAC_DMAINTERRUPT_EN_REG,EMAC_RECEIVE_INTERRUPT_ENABLE);
  68. }
  69. void inline emac_enable_rx_intr(void)
  70. {
  71. REG_SET_BIT(EMAC_DMAINTERRUPT_EN_REG,EMAC_RECEIVE_INTERRUPT_ENABLE);
  72. }
  73. void inline emac_disable_rx_unavail_intr(void)
  74. {
  75. REG_CLR_BIT(EMAC_DMAINTERRUPT_EN_REG,EMAC_RECEIVE_BUFFER_UNAVAILABLE_ENABLE);
  76. }
  77. void inline emac_enable_rx_unavail_intr(void)
  78. {
  79. REG_SET_BIT(EMAC_DMAINTERRUPT_EN_REG,EMAC_RECEIVE_BUFFER_UNAVAILABLE_ENABLE);
  80. }
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif