Subversion Repositories zxusbnet

Rev

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