Subversion Repositories zxusbnet

Rev

Rev 151 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. //#define TXFIFO_SIZE 2048
  2. #define WIZ_BASE_ADDR 0X0000
  3.  
  4. //extern unsigned int MTYPER;  
  5. //extern unsigned char WIZ_REG_MTYPER1;  
  6.  
  7. #define WMR ((unsigned char*)(WIZ_BASE_ADDR+0x0000))
  8. #define WMRX ((unsigned int*)(WIZ_BASE_ADDR+0x0000))
  9. #define SHAR ((unsigned char*)(WIZ_BASE_ADDR+0x0008))
  10. //#define SHAR ((unsigned char*)(WIZ_BASE_ADDR+0x0008))
  11. #define GAR ((unsigned char*)(WIZ_BASE_ADDR+0x0010))
  12. #define SUBR ((unsigned char*)(WIZ_BASE_ADDR+0x0014))
  13. #define SIPR ((unsigned char*)(WIZ_BASE_ADDR+0x0018))
  14. #define TMSR ((unsigned char*)(WIZ_BASE_ADDR+0x0020))
  15. #define RMSR ((unsigned char*)(WIZ_BASE_ADDR+0x0028))
  16. #define MTYPER ((unsigned char*)(WIZ_BASE_ADDR+0x0030))
  17. #define WID ((unsigned char*)(WIZ_BASE_ADDR+0x00fe))
  18. #define WIDW ((unsigned int*)(WIZ_BASE_ADDR+0x00fe))
  19.  
  20.  
  21. #define S_MR(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x0200))
  22. #define S_CR(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x0202))
  23. #define S_IMR(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x0204))
  24. #define S_IR(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x0206))
  25. #define S_SSR(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x0208))
  26. #define S_PORTR(soc_) ((unsigned int*)(WIZ_BASE_ADDR+soc_*0x40+0x020a))
  27. #define S_DHAR(soc_) ((unsigned int*)(WIZ_BASE_ADDR+soc_*0x40+0x020c))
  28. #define S_DHAR2(soc_) ((unsigned int*)(WIZ_BASE_ADDR+soc_*0x40+0x020E))
  29. #define S_DHAR4(soc_) ((unsigned int*)(WIZ_BASE_ADDR+soc_*0x40+0x0210))
  30. #define S_DPORTR(soc_) ((unsigned int*)(WIZ_BASE_ADDR+soc_*0x40+0x0212))
  31. #define S_DIPR(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x0214))
  32. #define S_DIPR1(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x0215))
  33. #define S_DIPR2(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x0216))
  34. #define S_DIPR3(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x0217))
  35. #define S_MSSR(soc_) ((unsigned int*)(WIZ_BASE_ADDR+soc_*0x40+0x0218))
  36. #define S_KPALVTR(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x021A))
  37. #define S_PROTOR(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x021B))
  38. #define S_TOSR(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x021C))
  39. #define S_TTLR(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x021E))
  40. #define S_TX_WRSR(soc_) ((unsigned int*)(WIZ_BASE_ADDR+soc_*0x40+0x0222))
  41. #define S_TX_FSR(soc_) ((unsigned int*)(WIZ_BASE_ADDR+soc_*0x40+0x0226))
  42. #define S_RX_RSR(soc_) ((unsigned int*)(WIZ_BASE_ADDR+soc_*0x40+0x022A))
  43. #define S_FRAGR(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x022C))
  44. #define S_TX(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x022E))
  45. #define S_TX1(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x022f))
  46. #define S_RX(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x0230))
  47. #define S_RX1(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x40+0x0231))
  48. #define S_RX_LEN(soc_) ((unsigned int*)(WIZ_BASE_ADDR+soc_*0x40+0x0230))
  49. #define S_RX_FAKE(soc_) ((unsigned char*)(WIZ_BASE_ADDR+soc_*0x0200+0x3000))
  50. /************************************/
  51. /* The bit of MR regsiter defintion */
  52. /************************************/
  53. #define MR_DBW             (1 << 15)            /**< Data bus width bit of MR. */
  54. #define MR_MPF             (1 << 14)            /**< Mac layer pause frame bit of MR. */
  55. #define MR_WDF(X)          ((X & 0x07) << 11)   /**< Write data fetch time bit of  MR. */
  56. #define MR_RDH             (1 << 10)            /**< Read data hold time bit of MR. */
  57. #define MR_FS              (1 << 8)             /**< FIFO swap bit of MR. */
  58. #define MR_RST             (1 << 7)             /**< S/W reset bit of MR. */
  59. #define MR_MT              (1 << 5)             /**< Memory test bit of MR. */
  60. #define MR_PB              (1 << 4)             /**< Ping block bit of MR. */
  61. #define MR_PPPoE           (1 << 3)             /**< PPPoE bit of MR. */
  62. #define MR_DBS             (1 << 2)             /**< Data bus swap of MR. */
  63. #define MR_IND             (1 << 0)             /**< Indirect mode bit of MR. */
  64.  
  65.  
  66. /***************************************/
  67. /* The bit of Sn_MR regsiter defintion */
  68. /***************************************/
  69. #define Sn_MR_ALIGN        (1 << 8)             /**< Alignment bit of Sn_MR. */
  70. #define Sn_MR_MULTI        (1 << 7)             /**< Multicasting bit of Sn_MR. */
  71. #define Sn_MR_MF           (1 << 6)             /**< MAC filter bit of Sn_MR. */
  72. #define Sn_MR_IGMPv        (1 << 5)             /**< IGMP version bit of Sn_MR. */
  73. #define Sn_MR_ND           (1 << 5)             /**< No delayed ack bit of Sn_MR. */
  74. #define Sn_MR_CLOSE        0x00                 /**< Protocol bits of Sn_MR. */
  75. #define Sn_MR_TCP          0x01                 /**< Protocol bits of Sn_MR. */
  76. #define Sn_MR_UDP          0x02                 /**< Protocol bits of Sn_MR. */
  77. #define Sn_MR_IPRAW        0x03                 /**< Protocol bits of Sn_MR. */
  78. #define Sn_MR_MACRAW       0x04                 /**< Protocol bits of Sn_MR. */
  79. #define Sn_MR_PPPoE        0x05                 /**< Protocol bits of Sn_MR. */
  80.  
  81. /******************************/
  82. /* The values of CR defintion */
  83. /******************************/
  84. #define Sn_CR_OPEN         0x01                 /**< OPEN command value of Sn_CR. */
  85. #define Sn_CR_LISTEN       0x02                 /**< LISTEN command value of Sn_CR. */
  86. #define Sn_CR_CONNECT      0x04                 /**< CONNECT command value of Sn_CR. */
  87. #define Sn_CR_DISCON       0x08                 /**< DISCONNECT command value of Sn_CR. */
  88. #define Sn_CR_CLOSE        0x10                 /**< CLOSE command value of Sn_CR. */
  89. #define Sn_CR_SEND         0x20                 /**< SEND command value of Sn_CR. */
  90. #define Sn_CR_SEND_MAC     0x21                 /**< SEND_MAC command value of Sn_CR. */
  91. #define Sn_CR_SEND_KEEP    0x22                 /**< SEND_KEEP command value of Sn_CR */
  92. #define Sn_CR_RECV         0x40                 /**< RECV command value of Sn_CR */
  93. #define Sn_CR_PCON         0x23                 /**< PCON command value of Sn_CR */
  94. #define Sn_CR_PDISCON      0x24                 /**< PDISCON command value of Sn_CR */
  95. #define Sn_CR_PCR          0x25                 /**< PCR command value of Sn_CR */
  96. #define Sn_CR_PCN          0x26                 /**< PCN command value of Sn_CR */
  97. #define Sn_CR_PCJ          0x27                 /**< PCJ command value of Sn_CR */
  98.  
  99. /**********************************/
  100. /* The values of Sn_SSR defintion */
  101. /**********************************/
  102. #define SOCK_CLOSED        0x00                 /**< SOCKETn is released */
  103. #define SOCK_ARP           0x01                 /**< ARP-request is transmitted in order to acquire destination hardware address. */
  104. #define SOCK_INIT          0x13                 /**< SOCKETn is open as TCP mode. */
  105. #define SOCK_LISTEN        0x14                 /**< SOCKETn operates as "TCP SERVER" and waits for connection-request (SYN packet) from "TCP CLIENT". */
  106. #define SOCK_SYNSENT       0x15                 /**< Connect-request(SYN packet) is transmitted to "TCP SERVER". */
  107. #define SOCK_SYNRECV       0x16                 /**< Connect-request(SYN packet) is received from "TCP CLIENT". */
  108. #define SOCK_ESTABLISHED   0x17                 /**< TCP connection is established. */
  109. #define SOCK_FIN_WAIT      0x18                 /**< SOCKETn is closing. */
  110. #define SOCK_CLOSING       0x1A                 /**< SOCKETn is closing. */
  111. #define SOCK_TIME_WAIT     0x1B                 /**< SOCKETn is closing. */
  112. #define SOCK_CLOSE_WAIT    0x1C                 /**< Disconnect-request(FIN packet) is received from the peer. */
  113. #define SOCK_LAST_ACK      0x1D                 /**< SOCKETn is closing. */
  114. #define SOCK_UDP           0x22                 /**< SOCKETn is open as UDP mode. */
  115. #define SOCK_IPRAW         0x32                 /**< SOCKETn is open as IPRAW mode. */
  116. #define SOCK_MACRAW        0x42                 /**< SOCKET0 is open as MACRAW mode. */
  117. #define SOCK_PPPoE         0x5F                 /**< SOCKET0 is open as PPPoE mode. */
  118.  
  119. /*********************************/
  120. /* The values of Sn_IR defintion */
  121. /*********************************/
  122. #define Sn_IR_PRECV        0x80                 /**< PPP receive bit of Sn_IR */
  123. #define Sn_IR_PFAIL        0x40                 /**< PPP fail bit of Sn_IR */
  124. #define Sn_IR_PNEXT        0x20                 /**< PPP next phase bit of Sn_IR */
  125. #define Sn_IR_SENDOK       0x10                 /**< Send OK bit of Sn_IR */
  126. #define Sn_IR_TIMEOUT      0x08                 /**< Timout bit of Sn_IR */
  127. #define Sn_IR_RECV         0x04                 /**< Receive bit of Sn_IR */
  128. #define Sn_IR_DISCON       0x02                 /**< Disconnect bit of Sn_IR */
  129. #define Sn_IR_CON          0x01                 /**< Connect bit of Sn_IR */
  130.  
  131. extern unsigned int rx_rd;
  132.        
  133. #define WIZ_RD_BUF(soc_,buf_,len_) {\
  134.         unsigned int i=(len_+1)>>1;\
  135.         unsigned char* buf__=buf_;      \
  136.         while (i){                                      \
  137.                 i--;                                    \
  138.                 *(buf__++)=*S_RX1(soc_);        \
  139.                 *(buf__++)=*S_RX(soc_);}}      
  140.  
  141. #define WIZ_READ_BUF(soc_,buf_,len_) WIZ_RD_BUF(soc_,buf_,len_);        \
  142.         *S_CR(soc_) = Sn_CR_RECV;       \
  143.         while(*S_CR(soc_));
  144.                        
  145. #define WIZ_WRITE_BUF(soc_,buf_,len_) {unsigned int i=(len_);unsigned char* buf__=(buf_);\
  146.         if(i&1)i++;\
  147.         while (i){\
  148.                 i--;i--;\
  149.                 *S_TX1(soc_) = *buf__;\
  150.                 buf__++; \
  151.                 *S_TX(soc_) = *buf__;\
  152.                 buf__++;}}\
  153.         *S_TX_WRSR(soc_) = (len_);\
  154.         *S_CR(soc_) = Sn_CR_SEND;\
  155.         while(*S_CR(soc_));
  156.  
  157. #define WIZ_SOCKET(soc_,smode_,port_) do{       \
  158.         *S_CR(soc_) =Sn_CR_CLOSE;\
  159.                 *S_MR(soc_) = smode_; /* sets TCP mode */\
  160.                 *S_PORTR(soc_) = port_; /* sets source port number */\
  161.                 *S_CR(soc_) = Sn_CR_OPEN; /* sets OPEN command */\
  162.                 while(*S_CR(soc_));\
  163.         }while(*S_SSR(soc_) != SOCK_INIT)
  164.        
  165. #define WIZ_LISTEN(soc_) *S_CR(soc_) = Sn_CR_LISTEN
  166.  
  167. #define WIZ_DISCONNECT(soc_) {*S_CR(soc_) = Sn_CR_DISCON;while(*S_CR(soc_));}
  168.  
  169. #define WIZ_CLOSE(soc_) *S_CR(soc_) = Sn_CR_CLOSE
  170.  
  171. #define PACK_SIZE(soc_,len_) {((unsigned char*)(&len_))[1]=*S_RX1(soc_);\
  172.         ((unsigned char*)(&len_))[0]=*S_RX(soc_);}
  173.  
  174. #define WIZ_SYS_INIT(tx_,rx_)                           \
  175.         output(0x82ab,input(0x82ab)&(0xff^0x08));       \
  176.         memcpy(TMSR,tx_,8);                             \
  177.         memcpy(RMSR,rx_,8);                             \
  178.         output(0x82ab,input(0x82ab)|0x08);     
  179.        
  180. #define WIZ_IP_INIT(shar_,gar_,subr_,sipr_)             \
  181.         output(0x82ab,input(0x82ab)&(0xff^0x08));       \
  182.         memcpy(SHAR,shar_,6);                           \
  183.         memcpy(GAR,gar_,4);                                     \
  184.         memcpy(SUBR,subr_,4);                           \
  185.         memcpy(SIPR,sipr_,4);                           \
  186.         output(0x82ab,input(0x82ab)|0x08);     
  187.        
  188. #define WIZ_SOC_IPSET(soc_,ip_,port_)   \
  189.         S_DIPR(soc_)[1]=ip_[0];  /* set TCP SERVER IP address*/\
  190.         S_DIPR(soc_)[0]=ip_[1];  /* set TCP SERVER IP address*/\
  191.         S_DIPR(soc_)[3]=ip_[2];  /* set TCP SERVER IP address*/\
  192.         S_DIPR(soc_)[2]=ip_[3];  /* set TCP SERVER IP address*/\
  193.         *S_DPORTR(soc_) = port_  /* set TCP SERVER listen port number*/
  194.        
  195.                
  196. #define WIZ_CONNECT(soc_,ip_,port_)     \
  197.         WIZ_SOC_IPSET(soc_,ip_,port_);\
  198.         *S_CR(soc_) = Sn_CR_CONNECT;\
  199.         while(*S_CR(soc_));
  200.