PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/libs/network/wiznet/W5500/w5500.h

https://github.com/shehperd/Espruino
C Header | 2054 lines | 327 code | 238 blank | 1489 comment | 0 complexity | af4095def74d731cd2ea1d244afdcabd MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. //*****************************************************************************
  2. //
  3. //! \file w5500.h
  4. //! \brief W5500 HAL Header File.
  5. //! \version 1.0.0
  6. //! \date 2013/10/21
  7. //! \par Revision history
  8. //! <2013/10/21> 1st Release
  9. //! \author MidnightCow
  10. //! \copyright
  11. //!
  12. //! Copyright (c) 2013, WIZnet Co., LTD.
  13. //! All rights reserved.
  14. //!
  15. //! Redistribution and use in source and binary forms, with or without
  16. //! modification, are permitted provided that the following conditions
  17. //! are met:
  18. //!
  19. //! * Redistributions of source code must retain the above copyright
  20. //! notice, this list of conditions and the following disclaimer.
  21. //! * Redistributions in binary form must reproduce the above copyright
  22. //! notice, this list of conditions and the following disclaimer in the
  23. //! documentation and/or other materials provided with the distribution.
  24. //! * Neither the name of the <ORGANIZATION> nor the names of its
  25. //! contributors may be used to endorse or promote products derived
  26. //! from this software without specific prior written permission.
  27. //!
  28. //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  29. //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30. //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31. //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  32. //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  34. //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  35. //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  37. //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  38. //! THE POSSIBILITY OF SUCH DAMAGE.
  39. //
  40. //*****************************************************************************
  41. #ifndef _W5500_H_
  42. #define _W5500_H_
  43. #include <stdint.h>
  44. #include "Ethernet/wizchip_conf.h"
  45. #define _W5500_IO_BASE_ 0x00000000
  46. #define _W5500_SPI_READ_ (0x00 << 2) //< SPI interface Read operation in Control Phase
  47. #define _W5500_SPI_WRITE_ (0x01 << 2) //< SPI interface Write operation in Control Phase
  48. #define WIZCHIP_CREG_BLOCK 0x00 //< Common register block
  49. #define WIZCHIP_SREG_BLOCK(N) (1+4*N) //< Socket N register block
  50. #define WIZCHIP_TXBUF_BLOCK(N) (2+4*N) //< Socket N Tx buffer address block
  51. #define WIZCHIP_RXBUF_BLOCK(N) (3+4*N) //< Socket N Rx buffer address block
  52. #define WIZCHIP_OFFSET_INC(ADDR, N) (ADDR + (N<<8)) //< Increase offset address
  53. ///////////////////////////////////////
  54. // Definition For Legacy Chip Driver //
  55. ///////////////////////////////////////
  56. #define IINCHIP_READ(ADDR) WIZCHIP_READ(ADDR) ///< The defined for legacy chip driver
  57. #define IINCHIP_WRITE(ADDR,VAL) WIZCHIP_WRITE(ADDR,VAL) ///< The defined for legacy chip driver
  58. #define IINCHIP_READ_BUF(ADDR,BUF,LEN) WIZCHIP_READ_BUF(ADDR,BUF,LEN) ///< The defined for legacy chip driver
  59. #define IINCHIP_WRITE_BUF(ADDR,BUF,LEN) WIZCHIP_WRITE(ADDR,BUF,LEN) ///< The defined for legacy chip driver
  60. //////////////////////////////
  61. //-------------------------- defgroup ---------------------------------
  62. /**
  63. * @defgroup W5500 W5500
  64. *
  65. * @brief WHIZCHIP register defines and I/O functions of @b W5500.
  66. *
  67. * - @ref WIZCHIP_register : @ref Common_register_group and @ref Socket_register_group
  68. * - @ref WIZCHIP_IO_Functions : @ref Basic_IO_function, @ref Common_register_access_function and @ref Socket_register_access_function
  69. */
  70. /**
  71. * @defgroup WIZCHIP_register WIZCHIP register
  72. * @ingroup W5500
  73. *
  74. * @brief WHIZCHIP register defines register group of @b W5500.
  75. *
  76. * - @ref Common_register_group : Common register group
  77. * - @ref Socket_register_group : \c SOCKET n register group
  78. */
  79. /**
  80. * @defgroup WIZCHIP_IO_Functions WIZCHIP I/O functions
  81. * @ingroup W5500
  82. *
  83. * @brief This supports the basic I/O functions for @ref WIZCHIP_register.
  84. *
  85. * - <b> Basic I/O function </b> \n
  86. * WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() \n\n
  87. *
  88. * - @ref Common_register_group <b>access functions</b> \n
  89. * -# @b Mode \n
  90. * getMR(), setMR()
  91. * -# @b Interrupt \n
  92. * getIR(), setIR(), getIMR(), setIMR(), getSIR(), setSIR(), getSIMR(), setSIMR(), getINTLEVEL(), setINTLEVEL()
  93. * -# <b> Network Information </b> \n
  94. * getSHAR(), setSHAR(), getGAR(), setGAR(), getSUBR(), setSUBR(), getSIPR(), setSIPR()
  95. * -# @b Retransmission \n
  96. * getRCR(), setRCR(), getRTR(), setRTR()
  97. * -# @b PPPoE \n
  98. * getPTIMER(), setPTIMER(), getPMAGIC(), getPMAGIC(), getPSID(), setPSID(), getPHAR(), setPHAR(), getPMRU(), setPMRU()
  99. * -# <b> ICMP packet </b>\n
  100. * getUIPR(), getUPORTR()
  101. * -# @b etc. \n
  102. * getPHYCFGR(), setPHYCFGR(), getVERSIONR() \n\n
  103. *
  104. * - \ref Socket_register_group <b>access functions</b> \n
  105. * -# <b> SOCKET control</b> \n
  106. * getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_IMR(), setSn_IMR(), getSn_IR(), setSn_IR()
  107. * -# <b> SOCKET information</b> \n
  108. * getSn_SR(), getSn_DHAR(), setSn_DHAR(), getSn_PORT(), setSn_PORT(), getSn_DIPR(), setSn_DIPR(), getSn_DPORT(), setSn_DPORT()
  109. * getSn_MSSR(), setSn_MSSR()
  110. * -# <b> SOCKET communication </b> \n
  111. * getSn_RXBUF_SIZE(), setSn_RXBUF_SIZE(), getSn_TXBUF_SIZE(), setSn_TXBUF_SIZE() \n
  112. * getSn_TX_RD(), getSn_TX_WR(), setSn_TX_WR() \n
  113. * getSn_RX_RD(), setSn_RX_RD(), getSn_RX_WR() \n
  114. * getSn_TX_FSR(), getSn_RX_RSR(), getSn_KPALVTR(), setSn_KPALVTR()
  115. * -# <b> IP header field </b> \n
  116. * getSn_FRAG(), setSn_FRAG(), getSn_TOS(), setSn_TOS() \n
  117. * getSn_TTL(), setSn_TTL()
  118. */
  119. /**
  120. * @defgroup Common_register_group Common register
  121. * @ingroup WIZCHIP_register
  122. *
  123. * @brief Common register group\n
  124. * It set the basic for the networking\n
  125. * It set the configuration such as interrupt, network information, ICMP, etc.
  126. * @details
  127. * @sa MR : Mode register.
  128. * @sa GAR, SUBR, SHAR, SIPR
  129. * @sa INTLEVEL, IR, IMR, SIR, SIMR : Interrupt.
  130. * @sa RTR, RCR : Data retransmission.
  131. * @sa PTIMER, PMAGIC, PHAR, PSID, PMRU : PPPoE.
  132. * @sa UIPR, UPORTR : ICMP message.
  133. * @sa PHYCFGR, VERSIONR : etc.
  134. */
  135. /**
  136. * @defgroup Socket_register_group Socket register
  137. * @ingroup WIZCHIP_register
  138. *
  139. * @brief Socket register group.\n
  140. * Socket register configures and control SOCKETn which is necessary to data communication.
  141. * @details
  142. * @sa Sn_MR, Sn_CR, Sn_IR, Sn_IMR : SOCKETn Control
  143. * @sa Sn_SR, Sn_PORT, Sn_DHAR, Sn_DIPR, Sn_DPORT : SOCKETn Information
  144. * @sa Sn_MSSR, Sn_TOS, Sn_TTL, Sn_KPALVTR, Sn_FRAG : Internet protocol.
  145. * @sa Sn_RXBUF_SIZE, Sn_TXBUF_SIZE, Sn_TX_FSR, Sn_TX_RD, Sn_TX_WR, Sn_RX_RSR, Sn_RX_RD, Sn_RX_WR : Data communication
  146. */
  147. /**
  148. * @defgroup Basic_IO_function Basic I/O function
  149. * @ingroup WIZCHIP_IO_Functions
  150. * @brief These are basic input/output functions to read values from register or write values to register.
  151. */
  152. /**
  153. * @defgroup Common_register_access_function Common register access functions
  154. * @ingroup WIZCHIP_IO_Functions
  155. * @brief These are functions to access <b>common registers</b>.
  156. */
  157. /**
  158. * @defgroup Socket_register_access_function Socket register access functions
  159. * @ingroup WIZCHIP_IO_Functions
  160. * @brief These are functions to access <b>socket registers</b>.
  161. */
  162. //------------------------------- defgroup end --------------------------------------------
  163. //----------------------------- W5500 Common Registers IOMAP -----------------------------
  164. /**
  165. * @ingroup Common_register_group
  166. * @brief Mode Register address(R/W)\n
  167. * @ref MR is used for S/W reset, ping block mode, PPPoE mode and etc.
  168. * @details Each bit of @ref MR defined as follows.
  169. * <table>
  170. * <tr> <td>7</td> <td>6</td> <td>5</td> <td>4</td> <td>3</td> <td>2</td> <td>1</td> <td>0</td> </tr>
  171. * <tr> <td>RST</td> <td>Reserved</td> <td>WOL</td> <td>PB</td> <td>PPPoE</td> <td>Reserved</td> <td>FARP</td> <td>Reserved</td> </tr>
  172. * </table>
  173. * - \ref MR_RST : Reset
  174. * - \ref MR_WOL : Wake on LAN
  175. * - \ref MR_PB : Ping block
  176. * - \ref MR_PPPOE : PPPoE mode
  177. * - \ref MR_FARP : Force ARP mode
  178. */
  179. #define MR (_W5500_IO_BASE_ + (0x0000 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  180. /**
  181. * @ingroup Common_register_group
  182. * @brief Gateway IP Register address(R/W)
  183. * @details @ref GAR configures the default gateway address.
  184. */
  185. #define GAR (_W5500_IO_BASE_ + (0x0001 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  186. /**
  187. * @ingroup Common_register_group
  188. * @brief Subnet mask Register address(R/W)
  189. * @details @ref SUBR configures the subnet mask address.
  190. */
  191. #define SUBR (_W5500_IO_BASE_ + (0x0005 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  192. /**
  193. * @ingroup Common_register_group
  194. * @brief Source MAC Register address(R/W)
  195. * @details @ref SHAR configures the source hardware address.
  196. */
  197. #define SHAR (_W5500_IO_BASE_ + (0x0009 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  198. /**
  199. * @ingroup Common_register_group
  200. * @brief Source IP Register address(R/W)
  201. * @details @ref SIPR configures the source IP address.
  202. */
  203. #define SIPR (_W5500_IO_BASE_ + (0x000F << 8) + (WIZCHIP_CREG_BLOCK << 3))
  204. /**
  205. * @ingroup Common_register_group
  206. * @brief Set Interrupt low level timer register address(R/W)
  207. * @details @ref INTLEVEL configures the Interrupt Assert Time.
  208. */
  209. #define INTLEVEL (_W5500_IO_BASE_ + (0x0013 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  210. /**
  211. * @ingroup Common_register_group
  212. * @brief Interrupt Register(R/W)
  213. * @details @ref IR indicates the interrupt status. Each bit of @ref IR will be still until the bit will be written to by the host.
  214. * If @ref IR is not equal to x00 INTn PIN is asserted to low until it is x00\n\n
  215. * Each bit of @ref IR defined as follows.
  216. * <table>
  217. * <tr> <td>7</td> <td>6</td> <td>5</td> <td>4</td> <td>3</td> <td>2</td> <td>1</td> <td>0</td> </tr>
  218. * <tr> <td>CONFLICT</td> <td>UNREACH</td> <td>PPPoE</td> <td>MP</td> <td>Reserved</td> <td>Reserved</td> <td>Reserved</td> <td>Reserved</td> </tr>
  219. * </table>
  220. * - \ref IR_CONFLICT : IP conflict
  221. * - \ref IR_UNREACH : Destination unreachable
  222. * - \ref IR_PPPoE : PPPoE connection close
  223. * - \ref IR_MP : Magic packet
  224. */
  225. #define IR (_W5500_IO_BASE_ + (0x0015 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  226. /**
  227. * @ingroup Common_register_group
  228. * @brief Interrupt mask register(R/W)
  229. * @details @ref IMR is used to mask interrupts. Each bit of @ref IMR corresponds to each bit of @ref IR.
  230. * When a bit of @ref IMR is and the corresponding bit of @ref IR is an interrupt will be issued. In other words,
  231. * if a bit of @ref IMR is an interrupt will not be issued even if the corresponding bit of @ref IR is \n\n
  232. * Each bit of @ref IMR defined as the following.
  233. * <table>
  234. * <tr> <td>7</td> <td>6</td> <td>5</td> <td>4</td> <td>3</td> <td>2</td> <td>1</td> <td>0</td> </tr>
  235. * <tr> <td>IM_IR7</td> <td>IM_IR6</td> <td>IM_IR5</td> <td>IM_IR4</td> <td>Reserved</td> <td>Reserved</td> <td>Reserved</td> <td>Reserved</td> </tr>
  236. * </table>
  237. * - \ref IM_IR7 : IP Conflict Interrupt Mask
  238. * - \ref IM_IR6 : Destination unreachable Interrupt Mask
  239. * - \ref IM_IR5 : PPPoE Close Interrupt Mask
  240. * - \ref IM_IR4 : Magic Packet Interrupt Mask
  241. */
  242. #define IMR (_W5500_IO_BASE_ + (0x0016 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  243. /**
  244. * @ingroup Common_register_group
  245. * @brief Socket Interrupt Register(R/W)
  246. * @details @ref SIR indicates the interrupt status of Socket.\n
  247. * Each bit of @ref SIR be still until @ref Sn_IR is cleared by the host.\n
  248. * If @ref Sn_IR is not equal to x00 the n-th bit of @ref SIR is and INTn PIN is asserted until @ref SIR is x00 */
  249. #define SIR (_W5500_IO_BASE_ + (0x0017 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  250. /**
  251. * @ingroup Common_register_group
  252. * @brief Socket Interrupt Mask Register(R/W)
  253. * @details Each bit of @ref SIMR corresponds to each bit of @ref SIR.
  254. * When a bit of @ref SIMR is and the corresponding bit of @ref SIR is Interrupt will be issued.
  255. * In other words, if a bit of @ref SIMR is an interrupt will be not issued even if the corresponding bit of @ref SIR is
  256. */
  257. #define SIMR (_W5500_IO_BASE_ + (0x0018 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  258. /**
  259. * @ingroup Common_register_group
  260. * @brief Timeout register address( 1 is 100us )(R/W)
  261. * @details @ref RTR configures the retransmission timeout period. The unit of timeout period is 100us and the default of @ref RTR is x07D0or 000
  262. * And so the default timeout period is 200ms(100us X 2000). During the time configured by @ref RTR, W5500 waits for the peer response
  263. * to the packet that is transmitted by \ref Sn_CR (CONNECT, DISCON, CLOSE, SEND, SEND_MAC, SEND_KEEP command).
  264. * If the peer does not respond within the @ref RTR time, W5500 retransmits the packet or issues timeout.
  265. */
  266. #define RTR (_W5500_IO_BASE_ + (0x0019 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  267. /**
  268. * @ingroup Common_register_group
  269. * @brief Retry count register(R/W)
  270. * @details @ref RCR configures the number of time of retransmission.
  271. * When retransmission occurs as many as ref RCR+1 Timeout interrupt is issued (@ref Sn_IR[TIMEOUT] = .
  272. */
  273. #define RCR (_W5500_IO_BASE_ + (0x001B << 8) + (WIZCHIP_CREG_BLOCK << 3))
  274. /**
  275. * @ingroup Common_register_group
  276. * @brief PPP LCP Request Timer register in PPPoE mode(R/W)
  277. * @details @ref PTIMER configures the time for sending LCP echo request. The unit of time is 25ms.
  278. */
  279. #define PTIMER (_W5500_IO_BASE_ + (0x001C << 8) + (WIZCHIP_CREG_BLOCK << 3))
  280. /**
  281. * @ingroup Common_register_group
  282. * @brief PPP LCP Magic number register in PPPoE mode(R/W)
  283. * @details @ref PMAGIC configures the 4bytes magic number to be used in LCP negotiation.
  284. */
  285. #define PMAGIC (_W5500_IO_BASE_ + (0x001D << 8) + (WIZCHIP_CREG_BLOCK << 3))
  286. /**
  287. * @ingroup Common_register_group
  288. * @brief PPP Destination MAC Register address(R/W)
  289. * @details @ref PHAR configures the PPPoE server hardware address that is acquired during PPPoE connection process.
  290. */
  291. #define PHAR (_W5500_IO_BASE_ + (0x001E << 8) + (WIZCHIP_CREG_BLOCK << 3))
  292. /**
  293. * @ingroup Common_register_group
  294. * @brief PPP Session Identification Register(R/W)
  295. * @details @ref PSID configures the PPPoE sever session ID acquired during PPPoE connection process.
  296. */
  297. #define PSID (_W5500_IO_BASE_ + (0x0024 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  298. /**
  299. * @ingroup Common_register_group
  300. * @brief PPP Maximum Segment Size(MSS) register(R/W)
  301. * @details @ref PMRU configures the maximum receive unit of PPPoE.
  302. */
  303. #define PMRU (_W5500_IO_BASE_ + (0x0026 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  304. /**
  305. * @ingroup Common_register_group
  306. * @brief Unreachable IP register address in UDP mode(R)
  307. * @details W5500 receives an ICMP packet(Destination port unreachable) when data is sent to a port number
  308. * which socket is not open and @ref UNREACH bit of @ref IR becomes and @ref UIPR & @ref UPORTR indicates
  309. * the destination IP address & port number respectively.
  310. */
  311. #define UIPR (_W5500_IO_BASE_ + (0x0028 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  312. /**
  313. * @ingroup Common_register_group
  314. * @brief Unreachable Port register address in UDP mode(R)
  315. * @details W5500 receives an ICMP packet(Destination port unreachable) when data is sent to a port number
  316. * which socket is not open and @ref UNREACH bit of @ref IR becomes and @ref UIPR & @ref UPORTR
  317. * indicates the destination IP address & port number respectively.
  318. */
  319. #define UPORTR (_W5500_IO_BASE_ + (0x002C << 8) + (WIZCHIP_CREG_BLOCK << 3))
  320. /**
  321. * @ingroup Common_register_group
  322. * @brief PHY Status Register(R/W)
  323. * @details @ref PHYCFGR configures PHY operation mode and resets PHY. In addition, @ref PHYCFGR indicates the status of PHY such as duplex, Speed, Link.
  324. */
  325. #define PHYCFGR (_W5500_IO_BASE_ + (0x002E << 8) + (WIZCHIP_CREG_BLOCK << 3))
  326. // Reserved (_W5500_IO_BASE_ + (0x002F << 8) + (WIZCHIP_CREG_BLOCK << 3))
  327. // Reserved (_W5500_IO_BASE_ + (0x0030 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  328. // Reserved (_W5500_IO_BASE_ + (0x0031 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  329. // Reserved (_W5500_IO_BASE_ + (0x0032 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  330. // Reserved (_W5500_IO_BASE_ + (0x0033 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  331. // Reserved (_W5500_IO_BASE_ + (0x0034 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  332. // Reserved (_W5500_IO_BASE_ + (0x0035 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  333. // Reserved (_W5500_IO_BASE_ + (0x0036 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  334. // Reserved (_W5500_IO_BASE_ + (0x0037 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  335. // Reserved (_W5500_IO_BASE_ + (0x0038 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  336. /**
  337. * @ingroup Common_register_group
  338. * @brief chip version register address(R)
  339. * @details @ref VERSIONR always indicates the W5500 version as @b 0x04.
  340. */
  341. #define VERSIONR (_W5500_IO_BASE_ + (0x0039 << 8) + (WIZCHIP_CREG_BLOCK << 3))
  342. //----------------------------- W5500 Socket Registers IOMAP -----------------------------
  343. /**
  344. * @ingroup Socket_register_group
  345. * @brief socket Mode register(R/W)
  346. * @details @ref Sn_MR configures the option or protocol type of Socket n.\n\n
  347. * Each bit of @ref Sn_MR defined as the following.
  348. * <table>
  349. * <tr> <td>7</td> <td>6</td> <td>5</td> <td>4</td> <td>3</td> <td>2</td> <td>1</td> <td>0</td> </tr>
  350. * <tr> <td>MULTI/MFEN</td> <td>BCASTB</td> <td>ND/MC/MMB</td> <td>UCASTB/MIP6B</td> <td>Protocol[3]</td> <td>Protocol[2]</td> <td>Protocol[1]</td> <td>Protocol[0]</td> </tr>
  351. * </table>
  352. * - @ref Sn_MR_MULTI : Support UDP Multicasting
  353. * - @ref Sn_MR_BCASTB : Broadcast block <b>in UDP Multicasting</b>
  354. * - @ref Sn_MR_ND : No Delayed Ack(TCP) flag
  355. * - @ref Sn_MR_MC : IGMP version used <b>in UDP mulitcasting</b>
  356. * - @ref Sn_MR_MMB : Multicast Blocking <b>in @ref Sn_MR_MACRAW mode</b>
  357. * - @ref Sn_MR_UCASTB : Unicast Block <b>in UDP Multicating</b>
  358. * - @ref Sn_MR_MIP6B : IPv6 packet Blocking <b>in @ref Sn_MR_MACRAW mode</b>
  359. * - <b>Protocol</b>
  360. * <table>
  361. * <tr> <td><b>Protocol[3]</b></td> <td><b>Protocol[2]</b></td> <td><b>Protocol[1]</b></td> <td><b>Protocol[0]</b></td> <td>@b Meaning</td> </tr>
  362. * <tr> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>Closed</td> </tr>
  363. * <tr> <td>0</td> <td>0</td> <td>0</td> <td>1</td> <td>TCP</td> </tr>
  364. * <tr> <td>0</td> <td>0</td> <td>1</td> <td>0</td> <td>UDP</td> </tr>
  365. * <tr> <td>0</td> <td>1</td> <td>0</td> <td>0</td> <td>MACRAW</td> </tr>
  366. * </table>
  367. * - @ref Sn_MR_MACRAW : MAC LAYER RAW SOCK \n
  368. * - @ref Sn_MR_UDP : UDP
  369. * - @ref Sn_MR_TCP : TCP
  370. * - @ref Sn_MR_CLOSE : Unused socket
  371. * @note MACRAW mode should be only used in Socket 0.
  372. */
  373. #define Sn_MR(N) (_W5500_IO_BASE_ + (0x0000 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  374. /**
  375. * @ingroup Socket_register_group
  376. * @brief Socket command register(R/W)
  377. * @details This is used to set the command for Socket n such as OPEN, CLOSE, CONNECT, LISTEN, SEND, and RECEIVE.\n
  378. * After W5500 accepts the command, the @ref Sn_CR register is automatically cleared to 0x00.
  379. * Even though @ref Sn_CR is cleared to 0x00, the command is still being processed.\n
  380. * To check whether the command is completed or not, please check the @ref Sn_IR or @ref Sn_SR.
  381. * - @ref Sn_CR_OPEN : Initialize or open socket.
  382. * - @ref Sn_CR_LISTEN : Wait connection request in TCP mode(<b>Server mode</b>)
  383. * - @ref Sn_CR_CONNECT : Send connection request in TCP mode(<b>Client mode</b>)
  384. * - @ref Sn_CR_DISCON : Send closing request in TCP mode.
  385. * - @ref Sn_CR_CLOSE : Close socket.
  386. * - @ref Sn_CR_SEND : Update TX buffer pointer and send data.
  387. * - @ref Sn_CR_SEND_MAC : Send data with MAC address, so without ARP process.
  388. * - @ref Sn_CR_SEND_KEEP : Send keep alive message.
  389. * - @ref Sn_CR_RECV : Update RX buffer pointer and receive data.
  390. */
  391. #define Sn_CR(N) (_W5500_IO_BASE_ + (0x0001 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  392. /**
  393. * @ingroup Socket_register_group
  394. * @brief Socket interrupt register(R)
  395. * @details @ref Sn_IR indicates the status of Socket Interrupt such as establishment, termination, receiving data, timeout).\n
  396. * When an interrupt occurs and the corresponding bit of @ref Sn_IMR is the corresponding bit of @ref Sn_IR becomes \n
  397. * In order to clear the @ref Sn_IR bit, the host should write the bit to \n
  398. * <table>
  399. * <tr> <td>7</td> <td>6</td> <td>5</td> <td>4</td> <td>3</td> <td>2</td> <td>1</td> <td>0</td> </tr>
  400. * <tr> <td>Reserved</td> <td>Reserved</td> <td>Reserved</td> <td>SEND_OK</td> <td>TIMEOUT</td> <td>RECV</td> <td>DISCON</td> <td>CON</td> </tr>
  401. * </table>
  402. * - \ref Sn_IR_SENDOK : <b>SEND_OK Interrupt</b>
  403. * - \ref Sn_IR_TIMEOUT : <b>TIMEOUT Interrupt</b>
  404. * - \ref Sn_IR_RECV : <b>RECV Interrupt</b>
  405. * - \ref Sn_IR_DISCON : <b>DISCON Interrupt</b>
  406. * - \ref Sn_IR_CON : <b>CON Interrupt</b>
  407. */
  408. #define Sn_IR(N) (_W5500_IO_BASE_ + (0x0002 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  409. /**
  410. * @ingroup Socket_register_group
  411. * @brief Socket status register(R)
  412. * @details @ref Sn_SR indicates the status of Socket n.\n
  413. * The status of Socket n is changed by @ref Sn_CR or some special control packet as SYN, FIN packet in TCP.
  414. * @par Normal status
  415. * - @ref SOCK_CLOSED : Closed
  416. * - @ref SOCK_INIT : Initiate state
  417. * - @ref SOCK_LISTEN : Listen state
  418. * - @ref SOCK_ESTABLISHED : Success to connect
  419. * - @ref SOCK_CLOSE_WAIT : Closing state
  420. * - @ref SOCK_UDP : UDP socket
  421. * - @ref SOCK_MACRAW : MAC raw mode socket
  422. *@par Temporary status during changing the status of Socket n.
  423. * - @ref SOCK_SYNSENT : This indicates Socket n sent the connect-request packet (SYN packet) to a peer.
  424. * - @ref SOCK_SYNRECV : It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer.
  425. * - @ref SOCK_FIN_WAIT : Connection state
  426. * - @ref SOCK_CLOSING : Closing state
  427. * - @ref SOCK_TIME_WAIT : Closing state
  428. * - @ref SOCK_LAST_ACK : Closing state
  429. */
  430. #define Sn_SR(N) (uint32_t)(_W5500_IO_BASE_ + (0x0003 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  431. /**
  432. * @ingroup Socket_register_group
  433. * @brief source port register(R/W)
  434. * @details @ref Sn_PORT configures the source port number of Socket n.
  435. * It is valid when Socket n is used in TCP/UPD mode. It should be set before OPEN command is ordered.
  436. */
  437. #define Sn_PORT(N) (_W5500_IO_BASE_ + (0x0004 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  438. /**
  439. * @ingroup Socket_register_group
  440. * @brief Peer MAC register address(R/W)
  441. * @details @ref Sn_DHAR configures the destination hardware address of Socket n when using SEND_MAC command in UDP mode or
  442. * it indicates that it is acquired in ARP-process by CONNECT/SEND command.
  443. */
  444. #define Sn_DHAR(N) (_W5500_IO_BASE_ + (0x0006 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  445. /**
  446. * @ingroup Socket_register_group
  447. * @brief Peer IP register address(R/W)
  448. * @details @ref Sn_DIPR configures or indicates the destination IP address of Socket n. It is valid when Socket n is used in TCP/UDP mode.
  449. * In TCP client mode, it configures an IP address of �TCP serverbefore CONNECT command.
  450. * In TCP server mode, it indicates an IP address of �TCP clientafter successfully establishing connection.
  451. * In UDP mode, it configures an IP address of peer to be received the UDP packet by SEND or SEND_MAC command.
  452. */
  453. #define Sn_DIPR(N) (_W5500_IO_BASE_ + (0x000C << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  454. /**
  455. * @ingroup Socket_register_group
  456. * @brief Peer port register address(R/W)
  457. * @details @ref Sn_DPORT configures or indicates the destination port number of Socket n. It is valid when Socket n is used in TCP/UDP mode.
  458. * In �TCP clientmode, it configures the listen port number of �TCP serverbefore CONNECT command.
  459. * In �TCP Servermode, it indicates the port number of TCP client after successfully establishing connection.
  460. * In UDP mode, it configures the port number of peer to be transmitted the UDP packet by SEND/SEND_MAC command.
  461. */
  462. #define Sn_DPORT(N) (_W5500_IO_BASE_ + (0x0010 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  463. /**
  464. * @ingroup Socket_register_group
  465. * @brief Maximum Segment Size(Sn_MSSR0) register address(R/W)
  466. * @details @ref Sn_MSSR configures or indicates the MTU(Maximum Transfer Unit) of Socket n.
  467. */
  468. #define Sn_MSSR(N) (_W5500_IO_BASE_ + (0x0012 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  469. // Reserved (_W5500_IO_BASE_ + (0x0014 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  470. /**
  471. * @ingroup Socket_register_group
  472. * @brief IP Type of Service(TOS) Register(R/W)
  473. * @details @ref Sn_TOS configures the TOS(Type Of Service field in IP Header) of Socket n.
  474. * It is set before OPEN command.
  475. */
  476. #define Sn_TOS(N) (_W5500_IO_BASE_ + (0x0015 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  477. /**
  478. * @ingroup Socket_register_group
  479. * @brief IP Time to live(TTL) Register(R/W)
  480. * @details @ref Sn_TTL configures the TTL(Time To Live field in IP header) of Socket n.
  481. * It is set before OPEN command.
  482. */
  483. #define Sn_TTL(N) (_W5500_IO_BASE_ + (0x0016 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  484. // Reserved (_W5500_IO_BASE_ + (0x0017 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  485. // Reserved (_W5500_IO_BASE_ + (0x0018 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  486. // Reserved (_W5500_IO_BASE_ + (0x0019 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  487. // Reserved (_W5500_IO_BASE_ + (0x001A << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  488. // Reserved (_W5500_IO_BASE_ + (0x001B << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  489. // Reserved (_W5500_IO_BASE_ + (0x001C << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  490. // Reserved (_W5500_IO_BASE_ + (0x001D << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  491. /**
  492. * @ingroup Socket_register_group
  493. * @brief Receive memory size register(R/W)
  494. * @details @ref Sn_RXBUF_SIZE configures the RX buffer block size of Socket n.
  495. * Socket n RX Buffer Block size can be configured with 1,2,4,8, and 16 Kbytes.
  496. * If a different size is configured, the data cannot be normally received from a peer.
  497. * Although Socket n RX Buffer Block size is initially configured to 2Kbytes,
  498. * user can re-configure its size using @ref Sn_RXBUF_SIZE. The total sum of @ref Sn_RXBUF_SIZE can not be exceed 16Kbytes.
  499. * When exceeded, the data reception error is occurred.
  500. */
  501. #define Sn_RXBUF_SIZE(N) (_W5500_IO_BASE_ + (0x001E << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  502. /**
  503. * @ingroup Socket_register_group
  504. * @brief Transmit memory size register(R/W)
  505. * @details @ref Sn_TXBUF_SIZE configures the TX buffer block size of Socket n. Socket n TX Buffer Block size can be configured with 1,2,4,8, and 16 Kbytes.
  506. * If a different size is configured, the data can�t be normally transmitted to a peer.
  507. * Although Socket n TX Buffer Block size is initially configured to 2Kbytes,
  508. * user can be re-configure its size using @ref Sn_TXBUF_SIZE. The total sum of @ref Sn_TXBUF_SIZE can not be exceed 16Kbytes.
  509. * When exceeded, the data transmission error is occurred.
  510. */
  511. #define Sn_TXBUF_SIZE(N) (_W5500_IO_BASE_ + (0x001F << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  512. /**
  513. * @ingroup Socket_register_group
  514. * @brief Transmit free memory size register(R)
  515. * @details @ref Sn_TX_FSR indicates the free size of Socket n TX Buffer Block. It is initialized to the configured size by @ref Sn_TXBUF_SIZE.
  516. * Data bigger than @ref Sn_TX_FSR should not be saved in the Socket n TX Buffer because the bigger data overwrites the previous saved data not yet sent.
  517. * Therefore, check before saving the data to the Socket n TX Buffer, and if data is equal or smaller than its checked size,
  518. * transmit the data with SEND/SEND_MAC command after saving the data in Socket n TX buffer. But, if data is bigger than its checked size,
  519. * transmit the data after dividing into the checked size and saving in the Socket n TX buffer.
  520. */
  521. #define Sn_TX_FSR(N) (_W5500_IO_BASE_ + (0x0020 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  522. /**
  523. * @ingroup Socket_register_group
  524. * @brief Transmit memory read pointer register address(R)
  525. * @details @ref Sn_TX_RD is initialized by OPEN command. However, if Sn_MR(P[3:0]) is TCP mode(001, it is re-initialized while connecting with TCP.
  526. * After its initialization, it is auto-increased by SEND command.
  527. * SEND command transmits the saved data from the current @ref Sn_TX_RD to the @ref Sn_TX_WR in the Socket n TX Buffer.
  528. * After transmitting the saved data, the SEND command increases the @ref Sn_TX_RD as same as the @ref Sn_TX_WR.
  529. * If its increment value exceeds the maximum value 0xFFFF, (greater than 0x10000 and the carry bit occurs),
  530. * then the carry bit is ignored and will automatically update with the lower 16bits value.
  531. */
  532. #define Sn_TX_RD(N) (_W5500_IO_BASE_ + (0x0022 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  533. /**
  534. * @ingroup Socket_register_group
  535. * @brief Transmit memory write pointer register address(R/W)
  536. * @details @ref Sn_TX_WR is initialized by OPEN command. However, if Sn_MR(P[3:0]) is TCP mode(001, it is re-initialized while connecting with TCP.\n
  537. * It should be read or be updated like as follows.\n
  538. * 1. Read the starting address for saving the transmitting data.\n
  539. * 2. Save the transmitting data from the starting address of Socket n TX buffer.\n
  540. * 3. After saving the transmitting data, update @ref Sn_TX_WR to the increased value as many as transmitting data size.
  541. * If the increment value exceeds the maximum value 0xFFFF(greater than 0x10000 and the carry bit occurs),
  542. * then the carry bit is ignored and will automatically update with the lower 16bits value.\n
  543. * 4. Transmit the saved data in Socket n TX Buffer by using SEND/SEND command
  544. */
  545. #define Sn_TX_WR(N) (_W5500_IO_BASE_ + (0x0024 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  546. /**
  547. * @ingroup Socket_register_group
  548. * @brief Received data size register(R)
  549. * @details @ref Sn_RX_RSR indicates the data size received and saved in Socket n RX Buffer.
  550. * @ref Sn_RX_RSR does not exceed the @ref Sn_RXBUF_SIZE and is calculated as the difference between
  551. * �Socket n RX Write Pointer (@ref Sn_RX_WR)and �Socket n RX Read Pointer (@ref Sn_RX_RD)
  552. */
  553. #define Sn_RX_RSR(N) (_W5500_IO_BASE_ + (0x0026 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  554. /**
  555. * @ingroup Socket_register_group
  556. * @brief Read point of Receive memory(R/W)
  557. * @details @ref Sn_RX_RD is initialized by OPEN command. Make sure to be read or updated as follows.\n
  558. * 1. Read the starting save address of the received data.\n
  559. * 2. Read data from the starting address of Socket n RX Buffer.\n
  560. * 3. After reading the received data, Update @ref Sn_RX_RD to the increased value as many as the reading size.
  561. * If the increment value exceeds the maximum value 0xFFFF, that is, is greater than 0x10000 and the carry bit occurs,
  562. * update with the lower 16bits value ignored the carry bit.\n
  563. * 4. Order RECV command is for notifying the updated @ref Sn_RX_RD to W5500.
  564. */
  565. #define Sn_RX_RD(N) (_W5500_IO_BASE_ + (0x0028 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  566. /**
  567. * @ingroup Socket_register_group
  568. * @brief Write point of Receive memory(R)
  569. * @details @ref Sn_RX_WR is initialized by OPEN command and it is auto-increased by the data reception.
  570. * If the increased value exceeds the maximum value 0xFFFF, (greater than 0x10000 and the carry bit occurs),
  571. * then the carry bit is ignored and will automatically update with the lower 16bits value.
  572. */
  573. #define Sn_RX_WR(N) (_W5500_IO_BASE_ + (0x002A << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  574. /**
  575. * @ingroup Socket_register_group
  576. * @brief socket interrupt mask register(R)
  577. * @details @ref Sn_IMR masks the interrupt of Socket n.
  578. * Each bit corresponds to each bit of @ref Sn_IR. When a Socket n Interrupt is occurred and the corresponding bit of @ref Sn_IMR is
  579. * the corresponding bit of @ref Sn_IR becomes When both the corresponding bit of @ref Sn_IMR and @ref Sn_IR are and the n-th bit of @ref IR is
  580. * Host is interrupted by asserted INTn PIN to low.
  581. */
  582. #define Sn_IMR(N) (_W5500_IO_BASE_ + (0x002C << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  583. /**
  584. * @ingroup Socket_register_group
  585. * @brief Fragment field value in IP header register(R/W)
  586. * @details @ref Sn_FRAG configures the FRAG(Fragment field in IP header).
  587. */
  588. #define Sn_FRAG(N) (_W5500_IO_BASE_ + (0x002D << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  589. /**
  590. * @ingroup Socket_register_group
  591. * @brief Keep Alive Timer register(R/W)
  592. * @details @ref Sn_KPALVTR configures the transmitting timer of �KEEP ALIVE(KA)packet of SOCKETn. It is valid only in TCP mode,
  593. * and ignored in other modes. The time unit is 5s.
  594. * KA packet is transmittable after @ref Sn_SR is changed to SOCK_ESTABLISHED and after the data is transmitted or received to/from a peer at least once.
  595. * In case of '@ref Sn_KPALVTR > 0', W5500 automatically transmits KA packet after time-period for checking the TCP connection (Auto-keepalive-process).
  596. * In case of '@ref Sn_KPALVTR = 0', Auto-keep-alive-process will not operate,
  597. * and KA packet can be transmitted by SEND_KEEP command by the host (Manual-keep-alive-process).
  598. * Manual-keep-alive-process is ignored in case of '@ref Sn_KPALVTR > 0'.
  599. */
  600. #define Sn_KPALVTR(N) (_W5500_IO_BASE_ + (0x002F << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  601. //#define Sn_TSR(N) (_W5500_IO_BASE_ + (0x0030 << 8) + (WIZCHIP_SREG_BLOCK(N) << 3))
  602. //----------------------------- W5500 Register values -----------------------------
  603. /* MODE register values */
  604. /**
  605. * @brief Reset
  606. * @details If this bit is All internal registers will be initialized. It will be automatically cleared as after S/W reset.
  607. */
  608. #define MR_RST 0x80
  609. /**
  610. * @brief Wake on LAN
  611. * @details 0 : Disable WOL mode\n
  612. * 1 : Enable WOL mode\n
  613. * If WOL mode is enabled and the received magic packet over UDP has been normally processed, the Interrupt PIN (INTn) asserts to low.
  614. * When using WOL mode, the UDP Socket should be opened with any source port number. (Refer to Socket n Mode Register (@ref Sn_MR) for opening Socket.)
  615. * @note The magic packet over UDP supported by W5500 consists of 6 bytes synchronization stream (xFFFFFFFFFFFF and
  616. * 16 times Target MAC address stream in UDP payload. The options such like password are ignored. You can use any UDP source port number for WOL mode.
  617. */
  618. #define MR_WOL 0x20
  619. /**
  620. * @brief Ping block
  621. * @details 0 : Disable Ping block\n
  622. * 1 : Enable Ping block\n
  623. * If the bit is it blocks the response to a ping request.
  624. */
  625. #define MR_PB 0x10
  626. /**
  627. * @brief Enable PPPoE
  628. * @details 0 : DisablePPPoE mode\n
  629. * 1 : EnablePPPoE mode\n
  630. * If you use ADSL, this bit should be
  631. */
  632. #define MR_PPPOE 0x08
  633. /**
  634. * @brief Enable UDP_FORCE_ARP CHECHK
  635. * @details 0 : Disable Force ARP mode\n
  636. * 1 : Enable Force ARP mode\n
  637. * In Force ARP mode, It forces on sending ARP Request whenever data is sent.
  638. */
  639. #define MR_FARP 0x02
  640. /* IR register values */
  641. /**
  642. * @brief Check IP conflict.
  643. * @details Bit is set as when own source IP address is same with the sender IP address in the received ARP request.
  644. */
  645. #define IR_CONFLICT 0x80
  646. /**
  647. * @brief Get the destination unreachable message in UDP sending.
  648. * @details When receiving the ICMP (Destination port unreachable) packet, this bit is set as
  649. * When this bit is Destination Information such as IP address and Port number may be checked with the corresponding @ref UIPR & @ref UPORTR.
  650. */
  651. #define IR_UNREACH 0x40
  652. /**
  653. * @brief Get the PPPoE close message.
  654. * @details When PPPoE is disconnected during PPPoE mode, this bit is set.
  655. */
  656. #define IR_PPPoE 0x20
  657. /**
  658. * @brief Get the magic packet interrupt.
  659. * @details When WOL mode is enabled and receives the magic packet over UDP, this bit is set.
  660. */
  661. #define IR_MP 0x10
  662. /* PHYCFGR register value */
  663. #define PHYCFGR_RST ~(1<<7) //< For PHY reset, must operate AND mask.
  664. #define PHYCFGR_OPMD (1<<6) // Configre PHY with OPMDC value
  665. #define PHYCFGR_OPMDC_ALLA (7<<3)
  666. #define PHYCFGR_OPMDC_PDOWN (6<<3)
  667. #define PHYCFGR_OPMDC_NA (5<<3)
  668. #define PHYCFGR_OPMDC_100FA (4<<3)
  669. #define PHYCFGR_OPMDC_100F (3<<3)
  670. #define PHYCFGR_OPMDC_100H (2<<3)
  671. #define PHYCFGR_OPMDC_10F (1<<3)
  672. #define PHYCFGR_OPMDC_10H (0<<3)
  673. #define PHYCFGR_DPX_FULL (1<<2)
  674. #define PHYCFGR_DPX_HALF (0<<2)
  675. #define PHYCFGR_SPD_100 (1<<1)
  676. #define PHYCFGR_SPD_10 (0<<1)
  677. #define PHYCFGR_LNK_ON (1<<0)
  678. #define PHYCFGR_LNK_OFF (0<<0)
  679. /* IMR register values */
  680. /**
  681. * @brief IP Conflict Interrupt Mask.
  682. * @details 0: Disable IP Conflict Interrupt\n
  683. * 1: Enable IP Conflict Interrupt
  684. */
  685. #define IM_IR7 0x80
  686. /**
  687. * @brief Destination unreachable Interrupt Mask.
  688. * @details 0: Disable Destination unreachable Interrupt\n
  689. * 1: Enable Destination unreachable Interrupt
  690. */
  691. #define IM_IR6 0x40
  692. /**
  693. * @brief PPPoE Close Interrupt Mask.
  694. * @details 0: Disable PPPoE Close Interrupt\n
  695. * 1: Enable PPPoE Close Interrupt
  696. */
  697. #define IM_IR5 0x20
  698. /**
  699. * @brief Magic Packet Interrupt Mask.
  700. * @details 0: Disable Magic Packet Interrupt\n
  701. * 1: Enable Magic Packet Interrupt
  702. */
  703. #define IM_IR4 0x10
  704. /* Sn_MR Default values */
  705. /**
  706. * @brief Support UDP Multicasting
  707. * @details 0 : disable Multicasting\n
  708. * 1 : enable Multicasting\n
  709. * This bit is applied only during UDP mode(P[3:0] = 010.\n
  710. * To use multicasting, @ref Sn_DIPR & @ref Sn_DPORT should be respectively configured with the multicast group IP address & port number
  711. * before Socket n is opened by OPEN command of @ref Sn_CR.
  712. */
  713. #define Sn_MR_MULTI 0x80
  714. /**
  715. * @brief Broadcast block in UDP Multicasting.
  716. * @details 0 : disable Broadcast Blocking\n
  717. * 1 : enable Broadcast Blocking\n
  718. * This bit blocks to receive broadcasting packet during UDP mode(P[3:0] = 010.\m
  719. * In addition, This bit does when MACRAW mode(P[3:0] = 100
  720. */
  721. #define Sn_MR_BCASTB 0x40
  722. /**
  723. * @brief No Delayed Ack(TCP), Multicast flag
  724. * @details 0 : Disable No Delayed ACK option\n
  725. * 1 : Enable No Delayed ACK option\n
  726. * This bit is applied only during TCP mode (P[3:0] = 001.\n
  727. * When this bit is It sends the ACK packet without delay as soon as a Data packet is received from a peer.\n
  728. * When this bit is It sends the ACK packet after waiting for the timeout time configured by @ref RTR.
  729. */
  730. #define Sn_MR_ND 0x20
  731. /**
  732. * @brief Unicast Block in UDP Multicasting
  733. * @details 0 : disable Unicast Blocking\n
  734. * 1 : enable Unicast Blocking\n
  735. * This bit blocks receiving the unicast packet during UDP mode(P[3:0] = 010 and MULTI =
  736. */
  737. #define Sn_MR_UCASTB 0x10
  738. /**
  739. * @brief MAC LAYER RAW SOCK
  740. * @details This configures the protocol mode of Socket n.
  741. * @note MACRAW mode should be only used in Socket 0.
  742. */
  743. #define Sn_MR_MACRAW 0x04
  744. //#define Sn_MR_IPRAW 0x03 /**< IP LAYER RAW SOCK */
  745. /**
  746. * @brief UDP
  747. * @details This configures the protocol mode of Socket n.
  748. */
  749. #define Sn_MR_UDP 0x02
  750. /**
  751. * @brief TCP
  752. * @details This configures the protocol mode of Socket n.
  753. */
  754. #define Sn_MR_TCP 0x01
  755. /**
  756. * @brief Unused socket
  757. * @details This configures the protocol mode of Socket n.
  758. */
  759. #define Sn_MR_CLOSE 0x00
  760. /* Sn_MR values used with Sn_MR_MACRAW */
  761. /**
  762. * @brief MAC filter enable in @ref Sn_MR_MACRAW mode
  763. * @details 0 : disable MAC Filtering\n
  764. * 1 : enable MAC Filtering\n
  765. * This bit is applied only during MACRAW mode(P[3:0] = 100.\n
  766. * When set as W5500 can only receive broadcasting packet or packet sent to itself.
  767. * When this bit is W5500 can receive all packets on Ethernet.
  768. * If user wants to implement Hybrid TCP/IP stack,
  769. * it is recommended that this bit is set as for reducing host overhead to process the all received packets.
  770. */
  771. #define Sn_MR_MFEN Sn_MR_MULTI
  772. /**
  773. * @brief Multicast Blocking in @ref Sn_MR_MACRAW mode
  774. * @details 0 : using IGMP version 2\n
  775. * 1 : using IGMP version 1\n
  776. * This bit is applied only during UDP mode(P[3:0] = 010 and MULTI =
  777. * It configures the version for IGMP messages (Join/Leave/Report).
  778. */
  779. #define Sn_MR_MMB Sn_MR_ND
  780. /**
  781. * @brief IPv6 packet Blocking in @ref Sn_MR_MACRAW mode
  782. * @details 0 : disable IPv6 Blocking\n
  783. * 1 : enable IPv6 Blocking\n
  784. * This bit is applied only during MACRAW mode (P[3:0] = 100. It blocks to receiving the IPv6 packet.
  785. */
  786. #define Sn_MR_MIP6B Sn_MR_UCASTB
  787. /* Sn_MR value used with Sn_MR_UDP & Sn_MR_MULTI */
  788. /**
  789. * @brief IGMP version used in UDP mulitcasting
  790. * @details 0 : disable Multicast Blocking\n
  791. * 1 : enable Multicast Blocking\n
  792. * This bit is applied only when MACRAW mode(P[3:0] = 100. It blocks to receive the packet with multicast MAC address.
  793. */
  794. #define Sn_MR_MC Sn_MR_ND
  795. /* Sn_MR alternate values */
  796. /**
  797. * @brief For Berkeley Socket API
  798. */
  799. #define SOCK_STREAM Sn_MR_TCP
  800. /**
  801. * @brief For Berkeley Socket API
  802. */
  803. #define SOCK_DGRAM Sn_MR_UDP
  804. /* Sn_CR values */
  805. /**
  806. * @brief Initialize or open socket
  807. * @details Socket n is initialized and opened according to the protocol selected in Sn_MR(P3:P0).
  808. * The table below shows the value of @ref Sn_SR corresponding to @ref Sn_MR.\n
  809. * <table>
  810. * <tr> <td>\b Sn_MR (P[3:0])</td> <td>\b Sn_SR</td> </tr>
  811. * <tr> <td>Sn_MR_CLOSE (000</td> <td></td> </tr>
  812. * <tr> <td>Sn_MR_TCP (001</td> <td>SOCK_INIT (0x13)</td> </tr>
  813. * <tr> <td>Sn_MR_UDP (010</td> <td>SOCK_UDP (0x22)</td> </tr>
  814. * <tr> <td>S0_MR_MACRAW (100</td> <td>SOCK_MACRAW (0x02)</td> </tr>
  815. * </table>
  816. */
  817. #define Sn_CR_OPEN 0x01
  818. /**
  819. * @brief Wait connection request in TCP mode(Server mode)
  820. * @details This is valid only in TCP mode (Sn_MR(P3:P0) = Sn_MR_TCP).
  821. * In this mode, Socket n operates as a �TCP serverand waits for connection-request (SYN packet) from any �TCP client
  822. * The @ref Sn_SR changes the state from SOCK_INIT to SOCKET_LISTEN.
  823. * When a �TCP clientconnection request is successfully established,
  824. * the @ref Sn_SR changes from SOCK_LISTEN to SOCK_ESTABLISHED and the Sn_IR(0) becomes
  825. * But when a �TCP clientconnection request is failed, Sn_IR(3) becomes and the status of @ref Sn_SR changes to SOCK_CLOSED.
  826. */
  827. #define Sn_CR_LISTEN 0x02
  828. /**
  829. * @brief Send connection request in TCP mode(Client mode)
  830. * @details To connect, a connect-request (SYN packet) is sent to b>TCP server</b>configured by @ref Sn_DIPR & Sn_DPORT(destination address & port).
  831. * If the connect-request is successful, the @ref Sn_SR is changed to @ref SOCK_ESTABLISHED and the Sn_IR(0) becomes \n\n
  832. * The connect-request fails in the following three cases.\n
  833. * 1. When a @b ARPTO occurs (@ref Sn_IR[3] = ) because destination hardware address is not acquired through the ARP-process.\n
  834. * 2. When a @b SYN/ACK packet is not received and @b TCPTO (Sn_IR(3) = )\n
  835. * 3. When a @b RST packet is received instead of a @b SYN/ACK packet. In these cases, @ref Sn_SR is changed to @ref SOCK_CLOSED.
  836. * @note This is valid only in TCP mode and operates when Socket n acts as b>TCP client</b>
  837. */
  838. #define Sn_CR_CONNECT 0x04
  839. /**
  840. * @brief Send closing request in TCP mode
  841. * @details Regardless of b>TCP server</b>or b>TCP client</b> the DISCON command processes the disconnect-process (b>Active close</b>or b>Passive close</b>.\n
  842. * @par Active close
  843. * it transmits disconnect-request(FIN packet) to the connected peer\n
  844. * @par Passive close
  845. * When FIN packet is received from peer, a FIN packet is replied back to the peer.\n
  846. * @details When the disconnect-process is successful (that is, FIN/ACK packet is received successfully), @ref Sn_SR is changed to @ref SOCK_CLOSED.\n
  847. * Otherwise, TCPTO occurs (Sn_IR(3)=)= and then @ref Sn_SR is changed to @ref SOCK_CLOSED.
  848. * @note Valid only in TCP mode.
  849. */
  850. #define Sn_CR_DISCON 0x08
  851. /**
  852. * @brief Close socket
  853. * @details Sn_SR is changed to @ref SOCK_CLOSED.
  854. */
  855. #define Sn_CR_CLOSE 0x10
  856. /**
  857. * @brief Update TX buffer pointer and send data
  858. * @details SEND transmits all the data in the Socket n TX buffer.\n
  859. * For more details, please refer to Socket n TX Free Size Register (@ref Sn_TX_FSR), Socket n,
  860. * TX Write Pointer Register(@ref Sn_TX_WR), and Socket n TX Read Pointer Register(@ref Sn_TX_RD).
  861. */
  862. #define Sn_CR_SEND 0x20
  863. /**
  864. * @brief Send data with MAC address, so without ARP process
  865. * @details The basic operation is same as SEND.\n
  866. * Normally SEND transmits data after destination hardware address is acquired by the automatic ARP-process(Address Resolution Protocol).\n
  867. * But SEND_MAC transmits data without the automatic ARP-process.\n
  868. * In this case, the destination hardware address is acquired from @ref Sn_DHAR configured by host, instead of APR-process.
  869. * @note Valid only in UDP mode.
  870. */
  871. #define Sn_CR_SEND_MAC 0x21
  872. /**
  873. * @brief Send keep alive message
  874. * @details It checks the connection status by sending 1byte keep-alive packet.\n
  875. * If the peer can not respond to the keep-alive packet during timeout time, the connection is terminated and the timeout interrupt will occur.
  876. * @note Valid only in TCP mode.
  877. */
  878. #define Sn_CR_SEND_KEEP 0x22
  879. /**
  880. * @brief Update RX buffer pointer and receive data
  881. * @details RECV completes the processing of the received data in Socket n RX Buffer by using a RX read pointer register (@ref Sn_RX_RD).\n
  882. * For more details, refer to Socket n RX Received Size Register (@ref Sn_RX_RSR), Socket n RX Write Pointer Register (@ref Sn_RX_WR),
  883. * and Socket n RX Read Pointer Register (@ref Sn_RX_RD).
  884. */
  885. #define Sn_CR_RECV 0x40
  886. /* Sn_IR values */
  887. /**
  888. * @brief SEND_OK Interrupt
  889. * @details This is issued when SEND command is completed.
  890. */
  891. #define Sn_IR_SENDOK 0x10
  892. /**
  893. * @brief TIMEOUT Interrupt
  894. * @details This is issued when ARPTO or TCPTO occurs.
  895. */
  896. #define Sn_IR_TIMEOUT 0x08
  897. /**
  898. * @brief RECV Interrupt
  899. * @details This is issued whenever data is received from a peer.
  900. */
  901. #define Sn_IR_RECV 0x04
  902. /**
  903. * @brief DISCON Interrupt
  904. * @details This is issued when FIN or FIN/ACK packet is received from a peer.
  905. */
  906. #define Sn_IR_DISCON 0x02
  907. /**
  908. * @brief CON Interrupt
  909. * @details This is issued one time when the connection with peer is successful and then @ref Sn_SR is changed to @ref SOCK_ESTABLISHED.
  910. */
  911. #define Sn_IR_CON 0x01
  912. /* Sn_SR values */
  913. /**
  914. * @brief Closed
  915. * @details This indicates that Socket n is released.\N
  916. * When DICON, CLOSE command is ordered, or when a timeout occurs, it is changed to @ref SOCK_CLOSED regardless of previous status.
  917. */
  918. #define SOCK_CLOSED 0x00
  919. /**
  920. * @brief Initiate state
  921. * @details This indicates Socket n is opened with TCP mode.\N
  922. * It is changed to @ref SOCK_INIT when Sn_MR(P[3:0]) = 001and OPEN command is ordered.\N
  923. * After @ref SOCK_INIT, user can use LISTEN /CONNECT command.
  924. */
  925. #define SOCK_INIT 0x13
  926. /**
  927. * @brief Listen state
  928. * @details This indicates Socket n is operating as b>TCP server</b>mode and waiting for connection-request (SYN packet) from a peer (b>TCP client</b>.\n
  929. * It will change to @ref SOCK_ESTALBLISHED when the connection-request is successfully accepted.\n
  930. * Otherwise it will change to @ref SOCK_CLOSED after TCPTO occurred (Sn_IR(TIMEOUT) = .
  931. */
  932. #define SOCK_LISTEN 0x14
  933. /**
  934. * @brief Connection state
  935. * @details This indicates Socket n sent the connect-request packet (SYN packet) to a peer.\n
  936. * It is temporarily shown when @ref Sn_SR is changed from @ref SOCK_INIT to @ref SOCK_ESTABLISHED by CONNECT command.\n
  937. * If connect-accept(SYN/ACK packet) is received from the peer at SOCK_SYNSENT, it changes to @ref SOCK_ESTABLISHED.\n
  938. * Otherwise, it changes to @ref SOCK_CLOSED after TCPTO (@ref Sn_IR[TIMEOUT] = is occurred.
  939. */
  940. #define SOCK_SYNSENT 0x15
  941. /**
  942. * @brief Connection state
  943. * @details It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer.\n
  944. * If socket n sends the response (SYN/ACK packet) to the peer successfully, it changes to @ref SOCK_ESTABLISHED. \n
  945. * If not, it changes to @ref SOCK_CLOSED after timeout occurs (@ref Sn_IR[TIMEOUT] = .
  946. */
  947. #define SOCK_SYNRECV

Large files files are truncated, but you can click here to view the full file