PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  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 0x16
  948. /**
  949. * @brief Success to connect
  950. * @details This indicates the status of the connection of Socket n.\n
  951. * It changes to @ref SOCK_ESTABLISHED when the b>TCP SERVER</b>processed the SYN packet from the b>TCP CLIENT</b>during @ref SOCK_LISTEN, or
  952. * when the CONNECT command is successful.\n
  953. * During @ref SOCK_ESTABLISHED, DATA packet can be transferred using SEND or RECV command.
  954. */
  955. #define SOCK_ESTABLISHED 0x17
  956. /**
  957. * @brief Closing state
  958. * @details These indicate Socket n is closing.\n
  959. * These are shown in disconnect-process such as active-close and passive-close.\n
  960. * When Disconnect-process is successfully completed, or when timeout occurs, these change to @ref SOCK_CLOSED.
  961. */
  962. #define SOCK_FIN_WAIT 0x18
  963. /**
  964. * @brief Closing state
  965. * @details These indicate Socket n is closing.\n
  966. * These are shown in disconnect-process such as active-close and passive-close.\n
  967. * When Disconnect-process is successfully completed, or when timeout occurs, these change to @ref SOCK_CLOSED.
  968. */
  969. #define SOCK_CLOSING 0x1A
  970. /**
  971. * @brief Closing state
  972. * @details These indicate Socket n is closing.\n
  973. * These are shown in disconnect-process such as active-close and passive-close.\n
  974. * When Disconnect-process is successfully completed, or when timeout occurs, these change to @ref SOCK_CLOSED.
  975. */
  976. #define SOCK_TIME_WAIT 0x1B
  977. /**
  978. * @brief Closing state
  979. * @details This indicates Socket n received the disconnect-request (FIN packet) from the connected peer.\n
  980. * This is half-closing status, and data can be transferred.\n
  981. * For full-closing, DISCON command is used. But For just-closing, CLOSE command is used.
  982. */
  983. #define SOCK_CLOSE_WAIT 0x1C
  984. /**
  985. * @brief Closing state
  986. * @details This indicates Socket n is waiting for the response (FIN/ACK packet) to the disconnect-request (FIN packet) by passive-close.\n
  987. * It changes to @ref SOCK_CLOSED when Socket n received the response successfully, or when timeout occurs (@ref Sn_IR[TIMEOUT] = .
  988. */
  989. #define SOCK_LAST_ACK 0x1D
  990. /**
  991. * @brief UDP socket
  992. * @details This indicates Socket n is opened in UDP mode(Sn_MR(P[3:0]) = 010.\n
  993. * It changes to SOCK_UPD when Sn_MR(P[3:0]) = 010 and OPEN command is ordered.\n
  994. * Unlike TCP mode, data can be transfered without the connection-process.
  995. */
  996. #define SOCK_UDP 0x22
  997. //#define SOCK_IPRAW 0x32 /**< IP raw mode socket */
  998. /**
  999. * @brief MAC raw mode socket
  1000. * @details This indicates Socket 0 is opened in MACRAW mode (S0_MR(P[3:0]) = 100and is valid only in Socket 0.\n
  1001. * It changes to SOCK_MACRAW when S0_MR(P[3:0] = 100and OPEN command is ordered.\n
  1002. * Like UDP mode socket, MACRAW mode Socket 0 can transfer a MAC packet (Ethernet frame) without the connection-process.
  1003. */
  1004. #define SOCK_MACRAW 0x42
  1005. //#define SOCK_PPPOE 0x5F
  1006. /* IP PROTOCOL */
  1007. #define IPPROTO_IP 0 //< Dummy for IP
  1008. #define IPPROTO_ICMP 1 //< Control message protocol
  1009. #define IPPROTO_IGMP 2 //< Internet group management protocol
  1010. #define IPPROTO_GGP 3 //< Gateway^2 (deprecated)
  1011. #define IPPROTO_TCP 6 //< TCP
  1012. #define IPPROTO_PUP 12 //< PUP
  1013. #define IPPROTO_UDP 17 //< UDP
  1014. #define IPPROTO_IDP 22 //< XNS idp
  1015. #define IPPROTO_ND 77 //< UNOFFICIAL net disk protocol
  1016. #define IPPROTO_RAW 255 //< Raw IP packet
  1017. /**
  1018. * @brief Enter a critical section
  1019. *
  1020. * @details It is provided to protect your shared code which are executed without distribution. \n \n
  1021. *
  1022. * In non-OS environment, It can be just implemented by disabling whole interrupt.\n
  1023. * In OS environment, You can replace it to critical section api supported by OS.
  1024. *
  1025. * \sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF()
  1026. * \sa WIZCHIP_CRITICAL_EXIT()
  1027. */
  1028. #define WIZCHIP_CRITICAL_ENTER() WIZCHIP.CRIS._enter()
  1029. /**
  1030. * @brief Exit a critical section
  1031. *
  1032. * @details It is provided to protect your shared code which are executed without distribution. \n\n
  1033. *
  1034. * In non-OS environment, It can be just implemented by disabling whole interrupt. \n
  1035. * In OS environment, You can replace it to critical section api supported by OS.
  1036. *
  1037. * @sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF()
  1038. * @sa WIZCHIP_CRITICAL_ENTER()
  1039. */
  1040. #define WIZCHIP_CRITICAL_EXIT() WIZCHIP.CRIS._exit()
  1041. ////////////////////////
  1042. // Basic I/O Function //
  1043. ////////////////////////
  1044. /**
  1045. * @ingroup Basic_IO_function
  1046. * @brief It reads 1 byte value from a register.
  1047. * @param AddrSel Register address
  1048. * @return The value of register
  1049. */
  1050. uint8_t WIZCHIP_READ (uint32_t AddrSel);
  1051. /**
  1052. * @ingroup Basic_IO_function
  1053. * @brief It writes 1 byte value to a register.
  1054. * @param AddrSel Register address
  1055. * @param wb Write data
  1056. * @return void
  1057. */
  1058. void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb );
  1059. /**
  1060. * @ingroup Basic_IO_function
  1061. * @brief It reads sequence data from registers.
  1062. * @param AddrSel Register address
  1063. * @param pBuf Pointer buffer to read data
  1064. * @param len Data length
  1065. */
  1066. void WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
  1067. /**
  1068. * @ingroup Basic_IO_function
  1069. * @brief It writes sequence data to registers.
  1070. * @param AddrSel Register address
  1071. * @param pBuf Pointer buffer to write data
  1072. * @param len Data length
  1073. */
  1074. void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
  1075. /////////////////////////////////
  1076. // Common Register I/O function //
  1077. /////////////////////////////////
  1078. /**
  1079. * @ingroup Common_register_access_function
  1080. * @brief Set Mode Register
  1081. * @param (uint8_t)mr The value to be set.
  1082. * @sa getMR()
  1083. */
  1084. #define setMR(mr) \
  1085. WIZCHIP_WRITE(MR,mr)
  1086. /**
  1087. * @ingroup Common_register_access_function
  1088. * @brief Get Mode Register
  1089. * @return uint8_t. The value of Mode register.
  1090. * @sa setMR()
  1091. */
  1092. #define getMR() \
  1093. WIZCHIP_READ(MR)
  1094. /**
  1095. * @ingroup Common_register_access_function
  1096. * @brief Set gateway IP address
  1097. * @param (uint8_t*)gar Pointer variable to set gateway IP address. It should be allocated 4 bytes.
  1098. * @sa getGAR()
  1099. */
  1100. #define setGAR(gar) \
  1101. WIZCHIP_WRITE_BUF(GAR,gar,4)
  1102. /**
  1103. * @ingroup Common_register_access_function
  1104. * @brief Get gateway IP address
  1105. * @param (uint8_t*)gar Pointer variable to get gateway IP address. It should be allocated 4 bytes.
  1106. * @sa setGAR()
  1107. */
  1108. #define getGAR(gar) \
  1109. WIZCHIP_READ_BUF(GAR,gar,4)
  1110. /**
  1111. * @ingroup Common_register_access_function
  1112. * @brief Set subnet mask address
  1113. * @param (uint8_t*)subr Pointer variable to set subnet mask address. It should be allocated 4 bytes.
  1114. * @sa getSUBR()
  1115. */
  1116. #define setSUBR(subr) \
  1117. WIZCHIP_WRITE_BUF(SUBR, subr,4)
  1118. /**
  1119. * @ingroup Common_register_access_function
  1120. * @brief Get subnet mask address
  1121. * @param (uint8_t*)subr Pointer variable to get subnet mask address. It should be allocated 4 bytes.
  1122. * @sa setSUBR()
  1123. */
  1124. #define getSUBR(subr) \
  1125. WIZCHIP_READ_BUF(SUBR, subr, 4)
  1126. /**
  1127. * @ingroup Common_register_access_function
  1128. * @brief Set local MAC address
  1129. * @param (uint8_t*)shar Pointer variable to set local MAC address. It should be allocated 6 bytes.
  1130. * @sa getSHAR()
  1131. */
  1132. #define setSHAR(shar) \
  1133. WIZCHIP_WRITE_BUF(SHAR, shar, 6)
  1134. /**
  1135. * @ingroup Common_register_access_function
  1136. * @brief Get local MAC address
  1137. * @param (uint8_t*)shar Pointer variable to get local MAC address. It should be allocated 6 bytes.
  1138. * @sa setSHAR()
  1139. */
  1140. #define getSHAR(shar) \
  1141. WIZCHIP_READ_BUF(SHAR, shar, 6)
  1142. /**
  1143. * @ingroup Common_register_access_function
  1144. * @brief Set local IP address
  1145. * @param (uint8_t*)sipr Pointer variable to set local IP address. It should be allocated 4 bytes.
  1146. * @sa getSIPR()
  1147. */
  1148. #define setSIPR(sipr) \
  1149. WIZCHIP_WRITE_BUF(SIPR, sipr, 4)
  1150. /**
  1151. * @ingroup Common_register_access_function
  1152. * @brief Get local IP address
  1153. * @param (uint8_t*)sipr Pointer variable to get local IP address. It should be allocated 4 bytes.
  1154. * @sa setSIPR()
  1155. */
  1156. #define getSIPR(sipr) \
  1157. WIZCHIP_READ_BUF(SIPR, sipr, 4)
  1158. /**
  1159. * @ingroup Common_register_access_function
  1160. * @brief Set INTLEVEL register
  1161. * @param (uint16_t)intlevel Value to set @ref INTLEVEL register.
  1162. * @sa getINTLEVEL()
  1163. */
  1164. #define setINTLEVEL(intlevel) {\
  1165. WIZCHIP_WRITE(INTLEVEL, (uint8_t)(intlevel >> 8)); \
  1166. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(INTLEVEL,1), (uint8_t) intlevel); \
  1167. }
  1168. /**
  1169. * @ingroup Common_register_access_function
  1170. * @brief Get INTLEVEL register
  1171. * @return uint16_t. Value of @ref INTLEVEL register.
  1172. * @sa setINTLEVEL()
  1173. */
  1174. #define getINTLEVEL() \
  1175. ((WIZCHIP_READ(INTLEVEL) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(INTLEVEL,1)))
  1176. /**
  1177. * @ingroup Common_register_access_function
  1178. * @brief Set @ref IR register
  1179. * @param (uint8_t)ir Value to set @ref IR register.
  1180. * @sa getIR()
  1181. */
  1182. #define setIR(ir) \
  1183. WIZCHIP_WRITE(IR, (ir & 0xF0))
  1184. /**
  1185. * @ingroup Common_register_access_function
  1186. * @brief Get @ref IR register
  1187. * @return uint8_t. Value of @ref IR register.
  1188. * @sa setIR()
  1189. */
  1190. #define getIR() \
  1191. (WIZCHIP_READ(IR) & 0xF0)
  1192. /**
  1193. * @ingroup Common_register_access_function
  1194. * @brief Set @ref IMR register
  1195. * @param (uint8_t)imr Value to set @ref IMR register.
  1196. * @sa getIMR()
  1197. */
  1198. #define setIMR(imr) \
  1199. WIZCHIP_WRITE(IMR, imr)
  1200. /**
  1201. * @ingroup Common_register_access_function
  1202. * @brief Get @ref IMR register
  1203. * @return uint8_t. Value of @ref IMR register.
  1204. * @sa setIMR()
  1205. */
  1206. #define getIMR() \
  1207. WIZCHIP_READ(IMR)
  1208. /**
  1209. * @ingroup Common_register_access_function
  1210. * @brief Set @ref SIR register
  1211. * @param (uint8_t)sir Value to set @ref SIR register.
  1212. * @sa getSIR()
  1213. */
  1214. #define setSIR(sir) \
  1215. WIZCHIP_WRITE(SIR, sir)
  1216. /**
  1217. * @ingroup Common_register_access_function
  1218. * @brief Get @ref SIR register
  1219. * @return uint8_t. Value of @ref SIR register.
  1220. * @sa setSIR()
  1221. */
  1222. #define getSIR() \
  1223. WIZCHIP_READ(SIR)
  1224. /**
  1225. * @ingroup Common_register_access_function
  1226. * @brief Set @ref SIMR register
  1227. * @param (uint8_t)simr Value to set @ref SIMR register.
  1228. * @sa getSIMR()
  1229. */
  1230. #define setSIMR(simr) \
  1231. WIZCHIP_WRITE(SIMR, simr)
  1232. /**
  1233. * @ingroup Common_register_access_function
  1234. * @brief Get @ref SIMR register
  1235. * @return uint8_t. Value of @ref SIMR register.
  1236. * @sa setSIMR()
  1237. */
  1238. #define getSIMR() \
  1239. WIZCHIP_READ(SIMR)
  1240. /**
  1241. * @ingroup Common_register_access_function
  1242. * @brief Set @ref RTR register
  1243. * @param (uint16_t)rtr Value to set @ref RTR register.
  1244. * @sa getRTR()
  1245. */
  1246. #define setRTR(rtr) {\
  1247. WIZCHIP_WRITE(RTR, (uint8_t)(rtr >> 8)); \
  1248. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(RTR,1), (uint8_t) rtr); \
  1249. }
  1250. /**
  1251. * @ingroup Common_register_access_function
  1252. * @brief Get @ref RTR register
  1253. * @return uint16_t. Value of @ref RTR register.
  1254. * @sa setRTR()
  1255. */
  1256. #define getRTR() \
  1257. ((WIZCHIP_READ(RTR) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(RTR,1)))
  1258. /**
  1259. * @ingroup Common_register_access_function
  1260. * @brief Set @ref RCR register
  1261. * @param (uint8_t)rcr Value to set @ref RCR register.
  1262. * @sa getRCR()
  1263. */
  1264. #define setRCR(rcr) \
  1265. WIZCHIP_WRITE(RCR, rcr)
  1266. /**
  1267. * @ingroup Common_register_access_function
  1268. * @brief Get @ref RCR register
  1269. * @return uint8_t. Value of @ref RCR register.
  1270. * @sa setRCR()
  1271. */
  1272. #define getRCR() \
  1273. WIZCHIP_READ(RCR)
  1274. //================================================== test done ===========================================================
  1275. /**
  1276. * @ingroup Common_register_access_function
  1277. * @brief Set @ref PTIMER register
  1278. * @param (uint8_t)ptimer Value to set @ref PTIMER register.
  1279. * @sa getPTIMER()
  1280. */
  1281. #define setPTIMER(ptimer) \
  1282. WIZCHIP_WRITE(PTIMER, ptimer)
  1283. /**
  1284. * @ingroup Common_register_access_function
  1285. * @brief Get @ref PTIMER register
  1286. * @return uint8_t. Value of @ref PTIMER register.
  1287. * @sa setPTIMER()
  1288. */
  1289. #define getPTIMER() \
  1290. WIZCHIP_READ(PTIMER)
  1291. /**
  1292. * @ingroup Common_register_access_function
  1293. * @brief Set @ref PMAGIC register
  1294. * @param (uint8_t)pmagic Value to set @ref PMAGIC register.
  1295. * @sa getPMAGIC()
  1296. */
  1297. #define setPMAGIC(pmagic) \
  1298. WIZCHIP_WRITE(PMAGIC, pmagic)
  1299. /**
  1300. * @ingroup Common_register_access_function
  1301. * @brief Get @ref PMAGIC register
  1302. * @return uint8_t. Value of @ref PMAGIC register.
  1303. * @sa setPMAGIC()
  1304. */
  1305. #define getPMAGIC() \
  1306. WIZCHIP_READ(PMAGIC)
  1307. /**
  1308. * @ingroup Common_register_access_function
  1309. * @brief Set PHAR address
  1310. * @param (uint8_t*)phar Pointer variable to set PPP destination MAC register address. It should be allocated 6 bytes.
  1311. * @sa getPHAR()
  1312. */
  1313. #define setPHAR(phar) \
  1314. WIZCHIP_WRITE_BUF(PHAR, phar, 6)
  1315. /**
  1316. * @ingroup Common_register_access_function
  1317. * @brief Get local IP address
  1318. * @param (uint8_t*)phar Pointer variable to PPP destination MAC register address. It should be allocated 6 bytes.
  1319. * @sa setPHAR()
  1320. */
  1321. #define getPHAR(phar) \
  1322. WIZCHIP_READ_BUF(PHAR, phar, 6)
  1323. /**
  1324. * @ingroup Common_register_access_function
  1325. * @brief Set @ref PSID register
  1326. * @param (uint16_t)psid Value to set @ref PSID register.
  1327. * @sa getPSID()
  1328. */
  1329. #define setPSID(psid) {\
  1330. WIZCHIP_WRITE(PSID, (uint8_t)(psid >> 8)); \
  1331. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(PSID,1), (uint8_t) psid); \
  1332. }
  1333. /**
  1334. * @ingroup Common_register_access_function
  1335. * @brief Get @ref PSID register
  1336. * @return uint16_t. Value of @ref PSID register.
  1337. * @sa setPSID()
  1338. */
  1339. //uint16_t getPSID(void);
  1340. #define getPSID() \
  1341. ((WIZCHIP_READ(PSID) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(PSID,1)))
  1342. /**
  1343. * @ingroup Common_register_access_function
  1344. * @brief Set @ref PMRU register
  1345. * @param (uint16_t)pmru Value to set @ref PMRU register.
  1346. * @sa getPMRU()
  1347. */
  1348. #define setPMRU(pmru) { \
  1349. WIZCHIP_WRITE(PMRU, (uint8_t)(pmru>>8)); \
  1350. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(PMRU,1), (uint8_t) pmru); \
  1351. }
  1352. /**
  1353. * @ingroup Common_register_access_function
  1354. * @brief Get @ref PMRU register
  1355. * @return uint16_t. Value of @ref PMRU register.
  1356. * @sa setPMRU()
  1357. */
  1358. #define getPMRU() \
  1359. ((WIZCHIP_READ(PMRU) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(PMRU,1)))
  1360. /**
  1361. * @ingroup Common_register_access_function
  1362. * @brief Get unreachable IP address
  1363. * @param (uint8_t*)uipr Pointer variable to get unreachable IP address. It should be allocated 4 bytes.
  1364. */
  1365. #define getUIPR(uipr) \
  1366. WIZCHIP_READ_BUF(UIPR,uipr,6)
  1367. /**
  1368. * @ingroup Common_register_access_function
  1369. * @brief Get @ref UPORTR register
  1370. * @return uint16_t. Value of @ref UPORTR register.
  1371. */
  1372. #define getUPORTR() \
  1373. ((WIZCHIP_READ(UPORTR) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(UPORTR,1)))
  1374. /**
  1375. * @ingroup Common_register_access_function
  1376. * @brief Set @ref PHYCFGR register
  1377. * @param (uint8_t)phycfgr Value to set @ref PHYCFGR register.
  1378. * @sa getPHYCFGR()
  1379. */
  1380. #define setPHYCFGR(phycfgr) \
  1381. WIZCHIP_WRITE(PHYCFGR, phycfgr)
  1382. /**
  1383. * @ingroup Common_register_access_function
  1384. * @brief Get @ref PHYCFGR register
  1385. * @return uint8_t. Value of @ref PHYCFGR register.
  1386. * @sa setPHYCFGR()
  1387. */
  1388. #define getPHYCFGR() \
  1389. WIZCHIP_READ(PHYCFGR)
  1390. /**
  1391. * @ingroup Common_register_access_function
  1392. * @brief Get @ref VERSIONR register
  1393. * @return uint8_t. Value of @ref VERSIONR register.
  1394. */
  1395. #define getVERSIONR() \
  1396. WIZCHIP_READ(VERSIONR)
  1397. /////////////////////////////////////
  1398. ///////////////////////////////////
  1399. // Socket N register I/O function //
  1400. ///////////////////////////////////
  1401. /**
  1402. * @ingroup Socket_register_access_function
  1403. * @brief Set @ref Sn_MR register
  1404. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1405. * @param (uint8_t)mr Value to set @ref Sn_MR
  1406. * @sa getSn_MR()
  1407. */
  1408. #define setSn_MR(sn, mr) \
  1409. WIZCHIP_WRITE(Sn_MR(sn),mr)
  1410. /**
  1411. * @ingroup Socket_register_access_function
  1412. * @brief Get @ref Sn_MR register
  1413. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1414. * @return uint8_t. Value of @ref Sn_MR.
  1415. * @sa setSn_MR()
  1416. */
  1417. #define getSn_MR(sn) \
  1418. WIZCHIP_READ(Sn_MR(sn))
  1419. /**
  1420. * @ingroup Socket_register_access_function
  1421. * @brief Set @ref Sn_CR register
  1422. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1423. * @param (uint8_t)cr Value to set @ref Sn_CR
  1424. * @sa getSn_CR()
  1425. */
  1426. #define setSn_CR(sn, cr) \
  1427. WIZCHIP_WRITE(Sn_CR(sn), cr)
  1428. /**
  1429. * @ingroup Socket_register_access_function
  1430. * @brief Get @ref Sn_CR register
  1431. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1432. * @return uint8_t. Value of @ref Sn_CR.
  1433. * @sa setSn_CR()
  1434. */
  1435. #define getSn_CR(sn) \
  1436. WIZCHIP_READ(Sn_CR(sn))
  1437. /**
  1438. * @ingroup Socket_register_access_function
  1439. * @brief Set @ref Sn_IR register
  1440. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1441. * @param (uint8_t)ir Value to set @ref Sn_IR
  1442. * @sa getSn_IR()
  1443. */
  1444. #define setSn_IR(sn, ir) \
  1445. WIZCHIP_WRITE(Sn_IR(sn), (ir & 0x1F))
  1446. /**
  1447. * @ingroup Socket_register_access_function
  1448. * @brief Get @ref Sn_IR register
  1449. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1450. * @return uint8_t. Value of @ref Sn_IR.
  1451. * @sa setSn_IR()
  1452. */
  1453. #define getSn_IR(sn) \
  1454. (WIZCHIP_READ(Sn_IR(sn)) & 0x1F)
  1455. /**
  1456. * @ingroup Socket_register_access_function
  1457. * @brief Set @ref Sn_IMR register
  1458. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1459. * @param (uint8_t)imr Value to set @ref Sn_IMR
  1460. * @sa getSn_IMR()
  1461. */
  1462. #define setSn_IMR(sn, imr) \
  1463. WIZCHIP_WRITE(Sn_IMR(sn), (imr & 0x1F))
  1464. /**
  1465. * @ingroup Socket_register_access_function
  1466. * @brief Get @ref Sn_IMR register
  1467. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1468. * @return uint8_t. Value of @ref Sn_IMR.
  1469. * @sa setSn_IMR()
  1470. */
  1471. #define getSn_IMR(sn) \
  1472. (WIZCHIP_READ(Sn_IMR(sn)) & 0x1F)
  1473. /**
  1474. * @ingroup Socket_register_access_function
  1475. * @brief Get @ref Sn_SR register
  1476. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1477. * @return uint8_t. Value of @ref Sn_SR.
  1478. */
  1479. #define getSn_SR(sn) \
  1480. WIZCHIP_READ(Sn_SR(sn))
  1481. /**
  1482. * @ingroup Socket_register_access_function
  1483. * @brief Set @ref Sn_PORT register
  1484. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1485. * @param (uint16_t)port Value to set @ref Sn_PORT.
  1486. * @sa getSn_PORT()
  1487. */
  1488. #define setSn_PORT(sn, port) { \
  1489. WIZCHIP_WRITE(Sn_PORT(sn), (uint8_t)(port >> 8)); \
  1490. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1), (uint8_t) port); \
  1491. }
  1492. /**
  1493. * @ingroup Socket_register_access_function
  1494. * @brief Get @ref Sn_PORT register
  1495. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1496. * @return uint16_t. Value of @ref Sn_PORT.
  1497. * @sa setSn_PORT()
  1498. */
  1499. #define getSn_PORT(sn) \
  1500. ((WIZCHIP_READ(Sn_PORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1)))
  1501. /**
  1502. * @ingroup Socket_register_access_function
  1503. * @brief Set @ref Sn_DHAR register
  1504. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1505. * @param (uint8_t*)dhar Pointer variable to set socket n destination hardware address. It should be allocated 6 bytes.
  1506. * @sa getSn_DHAR()
  1507. */
  1508. #define setSn_DHAR(sn, dhar) \
  1509. WIZCHIP_WRITE_BUF(Sn_DHAR(sn), dhar, 6)
  1510. /**
  1511. * @ingroup Socket_register_access_function
  1512. * @brief Get @ref Sn_MR register
  1513. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1514. * @param (uint8_t*)dhar Pointer variable to get socket n destination hardware address. It should be allocated 6 bytes.
  1515. * @sa setSn_DHAR()
  1516. */
  1517. #define getSn_DHAR(sn, dhar) \
  1518. WIZCHIP_READ_BUF(Sn_DHAR(sn), dhar, 6)
  1519. /**
  1520. * @ingroup Socket_register_access_function
  1521. * @brief Set @ref Sn_DIPR register
  1522. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1523. * @param (uint8_t*)dipr Pointer variable to set socket n destination IP address. It should be allocated 4 bytes.
  1524. * @sa getSn_DIPR()
  1525. */
  1526. #define setSn_DIPR(sn, dipr) \
  1527. WIZCHIP_WRITE_BUF(Sn_DIPR(sn), dipr, 4)
  1528. /**
  1529. * @ingroup Socket_register_access_function
  1530. * @brief Get @ref Sn_DIPR register
  1531. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1532. * @param (uint8_t*)dipr Pointer variable to get socket n destination IP address. It should be allocated 4 bytes.
  1533. * @sa SetSn_DIPR()
  1534. */
  1535. #define getSn_DIPR(sn, dipr) \
  1536. WIZCHIP_READ_BUF(Sn_DIPR(sn), dipr, 4)
  1537. /**
  1538. * @ingroup Socket_register_access_function
  1539. * @brief Set @ref Sn_DPORT register
  1540. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1541. * @param (uint16_t)dport Value to set @ref Sn_DPORT
  1542. * @sa getSn_DPORT()
  1543. */
  1544. #define setSn_DPORT(sn, dport) { \
  1545. WIZCHIP_WRITE(Sn_DPORT(sn), (uint8_t) (dport>>8)); \
  1546. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1), (uint8_t) dport); \
  1547. }
  1548. /**
  1549. * @ingroup Socket_register_access_function
  1550. * @brief Get @ref Sn_DPORT register
  1551. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1552. * @return uint16_t. Value of @ref Sn_DPORT.
  1553. * @sa setSn_DPORT()
  1554. */
  1555. #define getSn_DPORT(sn) \
  1556. ((WIZCHIP_READ(Sn_DPORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1)))
  1557. /**
  1558. * @ingroup Socket_register_access_function
  1559. * @brief Set @ref Sn_MSSR register
  1560. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1561. * @param (uint16_t)mss Value to set @ref Sn_MSSR
  1562. * @sa setSn_MSSR()
  1563. */
  1564. #define setSn_MSSR(sn, mss) { \
  1565. WIZCHIP_WRITE(Sn_MSSR(sn), (uint8_t)(mss>>8)); \
  1566. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1), (uint8_t) mss); \
  1567. }
  1568. /**
  1569. * @ingroup Socket_register_access_function
  1570. * @brief Get @ref Sn_MSSR register
  1571. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1572. * @return uint16_t. Value of @ref Sn_MSSR.
  1573. * @sa setSn_MSSR()
  1574. */
  1575. #define getSn_MSSR(sn) \
  1576. ((WIZCHIP_READ(Sn_MSSR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1)))
  1577. /**
  1578. * @ingroup Socket_register_access_function
  1579. * @brief Set @ref Sn_TOS register
  1580. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1581. * @param (uint8_t)tos Value to set @ref Sn_TOS
  1582. * @sa getSn_TOS()
  1583. */
  1584. #define setSn_TOS(sn, tos) \
  1585. WIZCHIP_WRITE(Sn_TOS(sn), tos)
  1586. /**
  1587. * @ingroup Socket_register_access_function
  1588. * @brief Get @ref Sn_TOS register
  1589. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1590. * @return uint8_t. Value of Sn_TOS.
  1591. * @sa setSn_TOS()
  1592. */
  1593. #define getSn_TOS(sn) \
  1594. WIZCHIP_READ(Sn_TOS(sn))
  1595. /**
  1596. * @ingroup Socket_register_access_function
  1597. * @brief Set @ref Sn_TTL register
  1598. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1599. * @param (uint8_t)ttl Value to set @ref Sn_TTL
  1600. * @sa getSn_TTL()
  1601. */
  1602. #define setSn_TTL(sn, ttl) \
  1603. WIZCHIP_WRITE(Sn_TTL(sn), ttl)
  1604. /**
  1605. * @ingroup Socket_register_access_function
  1606. * @brief Get @ref Sn_TTL register
  1607. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1608. * @return uint8_t. Value of @ref Sn_TTL.
  1609. * @sa setSn_TTL()
  1610. */
  1611. #define getSn_TTL(sn) \
  1612. WIZCHIP_READ(Sn_TTL(sn))
  1613. /**
  1614. * @ingroup Socket_register_access_function
  1615. * @brief Set @ref Sn_RXBUF_SIZE register
  1616. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1617. * @param (uint8_t)rxbufsize Value to set @ref Sn_RXBUF_SIZE
  1618. * @sa getSn_RXBUF_SIZE()
  1619. */
  1620. #define setSn_RXBUF_SIZE(sn, rxbufsize) \
  1621. WIZCHIP_WRITE(Sn_RXBUF_SIZE(sn),rxbufsize)
  1622. /**
  1623. * @ingroup Socket_register_access_function
  1624. * @brief Get @ref Sn_RXBUF_SIZE register
  1625. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1626. * @return uint8_t. Value of @ref Sn_RXBUF_SIZE.
  1627. * @sa setSn_RXBUF_SIZE()
  1628. */
  1629. #define getSn_RXBUF_SIZE(sn) \
  1630. WIZCHIP_READ(Sn_RXBUF_SIZE(sn))
  1631. /**
  1632. * @ingroup Socket_register_access_function
  1633. * @brief Set @ref Sn_TXBUF_SIZE register
  1634. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1635. * @param (uint8_t)txbufsize Value to set @ref Sn_TXBUF_SIZE
  1636. * @sa getSn_TXBUF_SIZE()
  1637. */
  1638. #define setSn_TXBUF_SIZE(sn, txbufsize) \
  1639. WIZCHIP_WRITE(Sn_TXBUF_SIZE(sn), txbufsize)
  1640. /**
  1641. * @ingroup Socket_register_access_function
  1642. * @brief Get @ref Sn_TXBUF_SIZE register
  1643. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1644. * @return uint8_t. Value of @ref Sn_TXBUF_SIZE.
  1645. * @sa setSn_TXBUF_SIZE()
  1646. */
  1647. #define getSn_TXBUF_SIZE(sn) \
  1648. WIZCHIP_READ(Sn_TXBUF_SIZE(sn))
  1649. /**
  1650. * @ingroup Socket_register_access_function
  1651. * @brief Get @ref Sn_TX_FSR register
  1652. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1653. * @return uint16_t. Value of @ref Sn_TX_FSR.
  1654. */
  1655. uint16_t getSn_TX_FSR(uint8_t sn);
  1656. /**
  1657. * @ingroup Socket_register_access_function
  1658. * @brief Get @ref Sn_TX_RD register
  1659. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1660. * @return uint16_t. Value of @ref Sn_TX_RD.
  1661. */
  1662. #define getSn_TX_RD(sn) \
  1663. ((WIZCHIP_READ(Sn_TX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_RD(sn),1)))
  1664. /**
  1665. * @ingroup Socket_register_access_function
  1666. * @brief Set @ref Sn_TX_WR register
  1667. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1668. * @param (uint16_t)txwr Value to set @ref Sn_TX_WR
  1669. * @sa GetSn_TX_WR()
  1670. */
  1671. #define setSn_TX_WR(sn, txwr) { \
  1672. WIZCHIP_WRITE(Sn_TX_WR(sn), (uint8_t)(txwr>>8)); \
  1673. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1), (uint8_t) txwr); \
  1674. }
  1675. /**
  1676. * @ingroup Socket_register_access_function
  1677. * @brief Get @ref Sn_TX_WR register
  1678. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1679. * @return uint16_t. Value of @ref Sn_TX_WR.
  1680. * @sa setSn_TX_WR()
  1681. */
  1682. #define getSn_TX_WR(sn) \
  1683. ((WIZCHIP_READ(Sn_TX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1)))
  1684. /**
  1685. * @ingroup Socket_register_access_function
  1686. * @brief Get @ref Sn_RX_RSR register
  1687. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1688. * @return uint16_t. Value of @ref Sn_RX_RSR.
  1689. */
  1690. uint16_t getSn_RX_RSR(uint8_t sn);
  1691. /**
  1692. * @ingroup Socket_register_access_function
  1693. * @brief Set @ref Sn_RX_RD register
  1694. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1695. * @param (uint16_t)rxrd Value to set @ref Sn_RX_RD
  1696. * @sa getSn_RX_RD()
  1697. */
  1698. #define setSn_RX_RD(sn, rxrd) { \
  1699. WIZCHIP_WRITE(Sn_RX_RD(sn), (uint8_t)(rxrd>>8)); \
  1700. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1), (uint8_t) rxrd); \
  1701. }
  1702. /**
  1703. * @ingroup Socket_register_access_function
  1704. * @brief Get @ref Sn_RX_RD register
  1705. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1706. * @regurn uint16_t. Value of @ref Sn_RX_RD.
  1707. * @sa setSn_RX_RD()
  1708. */
  1709. #define getSn_RX_RD(sn) \
  1710. ((WIZCHIP_READ(Sn_RX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1)))
  1711. /**
  1712. * @ingroup Socket_register_access_function
  1713. * @brief Get @ref Sn_RX_WR register
  1714. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1715. * @return uint16_t. Value of @ref Sn_RX_WR.
  1716. */
  1717. #define getSn_RX_WR(sn) \
  1718. ((WIZCHIP_READ(Sn_RX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_WR(sn),1)))
  1719. /**
  1720. * @ingroup Socket_register_access_function
  1721. * @brief Set @ref Sn_FRAG register
  1722. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1723. * @param (uint16_t)frag Value to set @ref Sn_FRAG
  1724. * @sa getSn_FRAD()
  1725. */
  1726. #define setSn_FRAG(sn, frag) { \
  1727. WIZCHIP_WRITE(Sn_FRAG(sn), (uint8_t)(frag >>8)); \
  1728. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_FRAG(sn),1), (uint8_t) frag); \
  1729. }
  1730. /**
  1731. * @ingroup Socket_register_access_function
  1732. * @brief Get @ref Sn_FRAG register
  1733. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1734. * @return uint16_t. Value of @ref Sn_FRAG.
  1735. * @sa setSn_FRAG()
  1736. */
  1737. #define getSn_FRAG(sn) \
  1738. ((WIZCHIP_READ(Sn_FRAG(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_FRAG(sn),1)))
  1739. /**
  1740. * @ingroup Socket_register_access_function
  1741. * @brief Set @ref Sn_KPALVTR register
  1742. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1743. * @param (uint8_t)kpalvt Value to set @ref Sn_KPALVTR
  1744. * @sa getSn_KPALVTR()
  1745. */
  1746. #define setSn_KPALVTR(sn, kpalvt) \
  1747. WIZCHIP_WRITE(Sn_KPALVTR(sn), kpalvt)
  1748. /**
  1749. * @ingroup Socket_register_access_function
  1750. * @brief Get @ref Sn_KPALVTR register
  1751. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1752. * @return uint8_t. Value of @ref Sn_KPALVTR.
  1753. * @sa setSn_KPALVTR()
  1754. */
  1755. #define getSn_KPALVTR(sn) \
  1756. WIZCHIP_READ(Sn_KPALVTR(sn))
  1757. //////////////////////////////////////
  1758. /////////////////////////////////////
  1759. // Sn_TXBUF & Sn_RXBUF IO function //
  1760. /////////////////////////////////////
  1761. /**
  1762. * @brief Gets the max buffer size of socket sn passed as parameter.
  1763. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1764. * @return uint16_t. Value of Socket n RX max buffer size.
  1765. */
  1766. #define getSn_RxMAX(sn) \
  1767. (getSn_RXBUF_SIZE(sn) << 10)
  1768. /**
  1769. * @brief Gets the max buffer size of socket sn passed as parameters.
  1770. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1771. * @return uint16_t. Value of Socket n TX max buffer size.
  1772. */
  1773. //uint16_t getSn_TxMAX(uint8_t sn);
  1774. #define getSn_TxMAX(sn) \
  1775. (getSn_TXBUF_SIZE(sn) << 10)
  1776. /**
  1777. * @ingroup Basic_IO_function
  1778. * @brief It copies data to internal TX memory
  1779. *
  1780. * @details This function reads the Tx write pointer register and after that,
  1781. * it copies the <i>wizdata(pointer buffer)</i> of the length of <i>len(variable)</i> bytes to internal TX memory
  1782. * and updates the Tx write pointer register.
  1783. * This function is being called by send() and sendto() function also.
  1784. *
  1785. * @note User should read upper byte first and lower byte later to get proper value.
  1786. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1787. * @param wizdata Pointer buffer to write data
  1788. * @param len Data length
  1789. * @sa wiz_recv_data()
  1790. */
  1791. void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len);
  1792. /**
  1793. * @ingroup Basic_IO_function
  1794. * @brief It copies data to your buffer from internal RX memory
  1795. *
  1796. * @details This function read the Rx read pointer register and after that,
  1797. * it copies the received data from internal RX memory
  1798. * to <i>wizdata(pointer variable)</i> of the length of <i>len(variable)</i> bytes.
  1799. * This function is being called by recv() also.
  1800. *
  1801. * @note User should read upper byte first and lower byte later to get proper value.
  1802. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1803. * @param wizdata Pointer buffer to read data
  1804. * @param len Data length
  1805. * @sa wiz_send_data()
  1806. */
  1807. void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len);
  1808. /**
  1809. * @ingroup Basic_IO_function
  1810. * @brief It discard the received data in RX memory.
  1811. * @details It discards the data of the length of <i>len(variable)</i> bytes in internal RX memory.
  1812. * @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
  1813. * @param len Data length
  1814. */
  1815. void wiz_recv_ignore(uint8_t sn, uint16_t len);
  1816. #endif // _W5500_H_