dm9k.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /****************************************************************************
  2. * Copyright (C), 2009-2010, www.armfly.com 安富莱电子
  3. *
  4. * 文件名: dm9k_uip.c
  5. * 内容简述: Davicom DM9KA uP NIC fast Ethernet driver for uIP.
  6. *
  7. * 文件历史:
  8. * 版本号 日期 作者 说明
  9. * v0.1 2010-01-18 armfly 创建该文件
  10. *
  11. */
  12. #ifndef _DM9K_H_
  13. #define _DM9K_H_
  14. #include "dwt.h"
  15. #include "includes.h"
  16. #include "lwip_dm9k.h"
  17. #include <inttypes.h>
  18. // #define TCP_PORT 8080
  19. #define NET_BASE_ADDR 0x68400000
  20. #define NET_REG_ADDR (*((volatile uint16_t *)NET_BASE_ADDR))
  21. #define NET_REG_DATA (*((volatile uint16_t *)(NET_BASE_ADDR + 0x00080000)))
  22. //#define DM9KA_FLOW_CONTROL
  23. //#define DM9KA_UPTO_100M
  24. //#define Fifo_Point_Check
  25. //#define Point_Error_Reset
  26. #define Fix_Note_Address
  27. //#define FifoPointCheck
  28. /* DM9KA 接收函数设置宏 */
  29. //#define Rx_Int_enable
  30. #define Max_Int_Count 1
  31. #define Max_Ethernet_Lenth 1536
  32. #define Broadcast_Jump
  33. #define Max_Broadcast_Lenth 500
  34. /* DM9KA 传送函数设置宏 */
  35. #define Max_Send_Pack 2
  36. #define ETH_ADDR_LEN 6
  37. // uint8_t SendPackOk = 0;
  38. // uint8_t is_fsmc_ok = 0; /* 用于指示FSMC是否初始化 */
  39. /* DM9K REGISTER LIST */
  40. #define DM9K_REG_NCR 0x00
  41. #define DM9K_REG_NSR 0x01
  42. #define DM9K_REG_TCR 0x02
  43. #define DM9K_REG_TSR1 0x03
  44. #define DM9K_REG_TSR2 0x04
  45. #define DM9K_REG_RCR 0x05
  46. #define DM9K_REG_RSR 0x06
  47. #define DM9K_REG_ROCR 0x07
  48. #define DM9K_REG_BPTR 0x08
  49. #define DM9K_REG_FCTR 0x09
  50. #define DM9K_REG_FCR 0x0A
  51. #define DM9K_REG_EPCR 0x0B
  52. #define DM9K_REG_EPAR 0x0C
  53. #define DM9K_REG_EPDRL 0x0D
  54. #define DM9K_REG_EPDRH 0x0E
  55. #define DM9K_REG_WAR 0x0F
  56. #define DM9K_REG_PAR 0x10
  57. #define DM9K_REG_MAR 0x16
  58. #define DM9K_REG_GPCR 0x1E
  59. #define DM9K_REG_GPR 0x1F
  60. #define DM9K_REG_VID_L 0x28
  61. #define DM9K_REG_VID_H 0x29
  62. #define DM9K_REG_PID_L 0x2A
  63. #define DM9K_REG_PID_H 0x2B
  64. #define DM9K_REG_CHIPR 0x2C
  65. #define DM9K_REG_TCR2 0x2D
  66. #define DM9K_REG_OTCR 0x2E
  67. #define DM9K_REG_SMCR 0x2F
  68. #define DM9K_REG_ETXCSR 0x30
  69. #define DM9K_REG_TCSCR 0x31
  70. #define DM9K_REG_RCSCSR 0x32
  71. #define DM9K_REG_MRCMDX 0xF0
  72. #define DM9K_REG_MRCMD 0xF2
  73. #define DM9K_REG_MRRL 0xF4
  74. #define DM9K_REG_MRRH 0xF5
  75. #define DM9K_REG_MWCMDX 0xF6
  76. #define DM9K_REG_MWCMD 0xF8
  77. #define DM9K_REG_MWRL 0xFA
  78. #define DM9K_REG_MWRH 0xFB
  79. #define DM9K_REG_TXPLL 0xFC
  80. #define DM9K_REG_TXPLH 0xFD
  81. #define DM9K_REG_ISR 0xFE
  82. #define DM9K_REG_IMR 0xFF
  83. /* 相关宏设置 */
  84. #define DM9KA_ID_OK 0x0A469000
  85. #define DM9K_BYTE_MODE 0x01
  86. #define DM9K_WORD_MODE 0x00
  87. #define DM9K_PHY 0x40
  88. #define DM9K_PKT_RDY 0x01
  89. #define DM9K_PKT_NORDY 0x00
  90. #define DM9K_REG_RESET 0x03
  91. #define DM9K_RX_INTR 0x01 /* 接收中断判断 bit */
  92. #define DM9K_TX_INTR 0x02 /* 传送中断判断 bit */
  93. #define DM9K_OVERFLOW_INTR 0x04 /* 内存溢出中断判断 bit */
  94. #define DM9K_LINK_CHANG 0x20 /* 连接变动中断判断 bit */
  95. #define DM9K_PHY_ON 0x00 /* 设定 PHY 开启 */
  96. #define DM9K_PHY_OFF 0x01 /* 设定 PHY 关闭 */
  97. #define DM9K_RCR_SET 0x31 /* 设定 接收功能 (不收 CRC 及 超长包) */
  98. #define DM9K_TCR_SET 0x01 /* 设定 传送功能 */
  99. #define DM9K_RCR_OFF 0x00 /* 设定 接收功能关关闭设置 */
  100. #define DM9K_BPTR_SET 0x37 /* 设定 Back Pressure 条件设置 */
  101. #define DM9K_FCTR_SET 0x38 /* 设定 Flow Control 条件设置 */
  102. #define DM9K_TCR2_SET 0x80 /* 设置 LED 显示模式 */
  103. #define DM9K_OTCR_SET 0x80 /* 设置 DM9K 工作频率 0x80 = 100Mhz */
  104. #define DM9K_ETXCSR_SET 0x83 /* 设置 Early Tramsmit 条件设置 */
  105. #define DM9K_FCR_SET 0x28 /* 开启 网络流控功能设置 */
  106. #define DM9K_TCSCR_SET 0x07 /* 设定 CHECKSUM 传送运算 设置 */
  107. #define DM9K_RCSCSR_SET 0x03 /* 设定 CHECKSUM 接收检查 设置 */
  108. #define DM9K_IMR_SET 0x81 /* 设定 启用中断使能 条件设置 */
  109. #define DM9K_IMR_OFF 0x80 /* 设定 关闭中断使能 条件设置 */
  110. // DM9K内部PHY寄存器
  111. #define DM9K_PHY_BMCR 0x00
  112. #define DM9K_PHY_BMSR 0x01
  113. #define DM9K_PHY_PHYID1 0x02
  114. #define DM9K_PHY_PHYID2 0x03
  115. #define DM9K_PHY_ANAR 0x04
  116. #define DM9K_PHY_ANLPAR 0x05
  117. #define DM9K_PHY_ANER 0x06
  118. #define DM9K_PHY_DSCR 0x10
  119. #define DM9K_PHY_DSCSR 0x11
  120. #define DM9K_PHY_10BTCSR 0x12
  121. #define DM9K_PHY_PWDOR 0x13
  122. #define DM9K_PHY_SCR 0x14
  123. /* EXPORTED SUBPROGRAM SPECIFICATIONS */
  124. void dm9k_init(void);
  125. uint8_t dm9k_linkstat(void);
  126. void dm9k_send_packet(uint8_t *p_char, uint16_t length);
  127. uint16_t dm9k_receive_packet(uint8_t *_uip_buf);
  128. void etherdev_send(uint8_t *p_char, uint16_t length);
  129. uint16_t etherdev_read(uint8_t *p_char);
  130. void dm9k_WriteReg(uint8_t reg, uint8_t writedata);
  131. uint8_t dm9k_ReadReg(uint8_t reg);
  132. void etherdev_chkmedia(void);
  133. uint32_t dm9k_ReadID(void);
  134. #endif