w5200.h 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110
  1. //* ****************************************************************************
  2. //! \file w5200.h
  3. //! \brief W5200 HAL Header File.
  4. //! \version 1.0.0
  5. //! \date 2015/03/23
  6. //! \par Revision history
  7. //! <2013/10/21> 1st Release
  8. //! \author MidnightCow
  9. //! \copyright
  10. //!
  11. //! Copyright (c) 2013, WIZnet Co., LTD.
  12. //! All rights reserved.
  13. //!
  14. //! Redistribution and use in source and binary forms, with or without
  15. //! modification, are permitted provided that the following conditions
  16. //! are met:
  17. //!
  18. //! * Redistributions of source code must retain the above copyright
  19. //! notice, this list of conditions and the following disclaimer.
  20. //! * Redistributions in binary form must reproduce the above copyright
  21. //! notice, this list of conditions and the following disclaimer in the
  22. //! documentation and/or other materials provided with the distribution.
  23. //! * Neither the name of the <ORGANIZATION> nor the names of its
  24. //! contributors may be used to endorse or promote products derived
  25. //! from this software without specific prior written permission.
  26. //!
  27. //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  31. //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  35. //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36. //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  37. //! THE POSSIBILITY OF SUCH DAMAGE.
  38. //
  39. //*****************************************************************************
  40. #ifndef _W5200_H
  41. #define _W5200_H
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. #include <stdint.h>
  46. #include "wizchip_conf.h"
  47. /// \cond DOXY_APPLY_CODE
  48. #if (_WIZCHIP_ == 5200)
  49. /// \endcond
  50. #define _WIZCHIP_SN_BASE_ (0x4000)
  51. #define _WIZCHIP_SN_SIZE_ (0x0100)
  52. #define _WIZCHIP_IO_TXBUF_ (0x8000) /* Internal Tx buffer address of the iinchip */
  53. #define _WIZCHIP_IO_RXBUF_ (0xC000) /* Internal Rx buffer address of the iinchip */
  54. #define _W5200_SPI_READ_ (0x00 << 7) ///< SPI interface Read operation in Control Phase
  55. #define _W5200_SPI_WRITE_ (0x01 << 7) ///< SPI interface Write operation in Control Phase
  56. #define WIZCHIP_CREG_BLOCK 0x00 ///< Common register block
  57. #define WIZCHIP_SREG_BLOCK(N) (_WIZCHIP_SN_BASE_+ _WIZCHIP_SN_SIZE_*N) ///< Socket N register block
  58. #define WIZCHIP_OFFSET_INC(ADDR, N) (ADDR + N) ///< Increase offset address
  59. #if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_)
  60. #define IDM_AR0 ((_WIZCHIP_IO_BASE_ + 0x0001))
  61. #define IDM_AR1 ((_WIZCHIP_IO_BASE_ + 0x0002))
  62. #define IDM_DR ((_WIZCHIP_IO_BASE_ + 0x0003))
  63. #define _W5200_IO_BASE_ 0x0000
  64. #elif (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)
  65. #define _W5200_IO_BASE_ 0x0000
  66. #endif
  67. ///////////////////////////////////////
  68. // Definition For Legacy Chip Driver //
  69. ///////////////////////////////////////
  70. #define IINCHIP_READ(ADDR) WIZCHIP_READ(ADDR) ///< The defined for legacy chip driver
  71. #define IINCHIP_WRITE(ADDR,VAL) WIZCHIP_WRITE(ADDR,VAL) ///< The defined for legacy chip driver
  72. #define IINCHIP_READ_BUF(ADDR,BUF,LEN) WIZCHIP_READ_BUF(ADDR,BUF,LEN) ///< The defined for legacy chip driver
  73. #define IINCHIP_WRITE_BUF(ADDR,BUF,LEN) WIZCHIP_WRITE(ADDR,BUF,LEN) ///< The defined for legacy chip driver
  74. //----------- defgroup --------------------------------
  75. /**
  76. * @defgroup W5200 W5200
  77. * @brief WHIZCHIP register defines and I/O functions of @b W5200.
  78. *
  79. * - @ref WIZCHIP_register_W5200 : @ref Common_register_group_W5200 and @ref Socket_register_group_W5200
  80. * - @ref WIZCHIP_IO_Functions_W5200 : @ref Basic_IO_function_W5200, @ref Common_register_access_function_W5200 and @ref Socket_register_group_W5200
  81. */
  82. /**
  83. * @defgroup WIZCHIP_register_W5200 WIZCHIP register
  84. * @ingroup W5200
  85. * @brief WIZCHIP register defines register group of <b> W5200 </b>.
  86. *
  87. * - \ref Common_register_group_W5200 : Common register group w5200
  88. * - \ref Socket_register_group_W5200 : \c SOCKET n register group w5200
  89. */
  90. /**
  91. * @defgroup WIZCHIP_IO_Functions_W5200 WIZCHIP I/O functions
  92. * @ingroup W5200
  93. * @brief This supports the basic I/O functions for \ref WIZCHIP_register_W5200.
  94. *
  95. * - <b> Basic I/O function </b> \n
  96. * WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF() \n\n
  97. *
  98. * - \ref Common_register_group_W5200 <b>access functions</b> \n
  99. * -# @b Mode \n
  100. * getMR(), setMR()
  101. * -# @b Interrupt \n
  102. * getIR(), setIR(), getIMR(), setIMR(), getIR2(), setIR2(), getIMR2(), setIMR2(), getINTLEVEL(), setINTLEVEL()
  103. * -# <b> Network Information </b> \n
  104. * getSHAR(), setSHAR(), getGAR(), setGAR(), getSUBR(), setSUBR(), getSIPR(), setSIPR()
  105. * -# @b Retransmission \n
  106. * getRCR(), setRCR(), getRTR(), setRTR()
  107. * -# @b PPPoE \n
  108. * getPTIMER(), setPTIMER(), getPMAGIC(), getPMAGIC()
  109. * -# @b etc. \n
  110. * getPHYSTATUS(), getVERSIONR() \n\n
  111. *
  112. * - \ref Socket_register_group_W5200 <b>access functions</b> \n
  113. * -# <b> SOCKET control</b> \n
  114. * getSn_MR(), setSn_MR(), getSn_CR(), setSn_CR(), getSn_IMR(), setSn_IMR(), getSn_IR(), setSn_IR()
  115. * -# <b> SOCKET information</b> \n
  116. * getSn_SR(), getSn_DHAR(), setSn_DHAR(), getSn_PORT(), setSn_PORT(), getSn_DIPR(), setSn_DIPR(), getSn_DPORT(), setSn_DPORT()
  117. * getSn_MSSR(), setSn_MSSR()
  118. * -# <b> SOCKET communication </b> \n
  119. * getSn_RXMEM_SIZE(), setSn_RXMEM_SIZE(), getSn_TXMEM_SIZE(), setSn_TXMEM_SIZE() \n
  120. * getSn_TX_RD(), getSn_TX_WR(), setSn_TX_WR() \n
  121. * getSn_RX_RD(), setSn_RX_RD(), getSn_RX_WR() \n
  122. * getSn_TX_FSR(), getSn_RX_RSR()
  123. * -# <b> IP header field </b> \n
  124. * getSn_FRAG(), setSn_FRAG(), getSn_TOS(), setSn_TOS() \n
  125. * getSn_TTL(), setSn_TTL()
  126. */
  127. /**
  128. * @defgroup Common_register_group_W5200 Common register
  129. * @ingroup WIZCHIP_register_W5200
  130. * @brief Common register group\n
  131. * It set the basic for the networking\n
  132. * It set the configuration such as interrupt, network information, ICMP, etc.
  133. * @details
  134. * @sa MR : Mode register.
  135. * @sa GAR, SUBR, SHAR, SIPR
  136. * @sa INTLEVEL, IR, _IMR_, IR2, IMR2 : Interrupt.
  137. * @sa _RTR_, _RCR_ : Data retransmission.
  138. * @sa PTIMER, PMAGIC : PPPoE.
  139. * @sa PHYSTATUS, VERSIONR : etc.
  140. */
  141. /**
  142. * @defgroup Socket_register_group_W5200 Socket register
  143. * @ingroup WIZCHIP_register_W5200
  144. * @brief Socket register group\n
  145. * Socket register configures and control SOCKETn which is necessary to data communication.
  146. * @details
  147. * @sa Sn_MR, Sn_CR, Sn_IR, Sn_IMR : SOCKETn Control
  148. * @sa Sn_SR, Sn_PORT, Sn_DHAR, Sn_DIPR, Sn_DPORT : SOCKETn Information
  149. * @sa Sn_MSSR, Sn_TOS, Sn_TTL, Sn_FRAG : Internet protocol.
  150. * @sa Sn_RXMEM_SIZE, Sn_TXMEM_SIZE, Sn_TX_FSR, Sn_TX_RD, Sn_TX_WR, Sn_RX_RSR, Sn_RX_RD, Sn_RX_WR : Data communication
  151. */
  152. /**
  153. * @defgroup Basic_IO_function_W5200 Basic I/O function
  154. * @ingroup WIZCHIP_IO_Functions_W5200
  155. * @brief These are basic input/output functions to read values from register or write values to register.
  156. */
  157. /**
  158. * @defgroup Common_register_access_function_W5200 Common register access functions
  159. * @ingroup WIZCHIP_IO_Functions_W5200
  160. * @brief These are functions to access <b>common registers</b>.
  161. */
  162. /**
  163. * @defgroup Socket_register_access_function_W5200 Socket register access functions
  164. * @ingroup WIZCHIP_IO_Functions_W5200
  165. * @brief These are functions to access <b>socket registers</b>.
  166. */
  167. //-----------------------------------------------------------------------------------
  168. //----------------------------- W5200 Common Registers IOMAP -----------------------------
  169. /**
  170. * @ingroup Common_register_group_W5200
  171. * @brief Mode Register address(R/W)\n
  172. * \ref MR is used for S/W reset, ping block mode, PPPoE mode and etc.
  173. * @details Each bit of \ref MR defined as follows.
  174. * <table>
  175. * <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>
  176. * <tr> <td>RST</td> <td>Reserved</td> <td>WOL</td> <td>PB</td> <td>PPPoE</td> <td>Reserved</td> <td>AI</td> <td>IND</td> </tr>
  177. * </table>
  178. * - \ref MR_RST : Reset
  179. * - \ref MR_WOL : Wake on LAN
  180. * - \ref MR_PB : Ping block
  181. * - \ref MR_PPPOE : PPPoE mode
  182. * - \ref MR_AI : Address Auto-Increment in Indirect Bus Interface
  183. * - \ref MR_IND : Indirect Bus Interface mode
  184. */
  185. #if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_)
  186. #define MR (_WIZCHIP_IO_BASE_ + (0x0000)) // Mode
  187. #else
  188. #define MR (_W5200_IO_BASE_ + (0x0000)) // Mode
  189. #endif
  190. /**
  191. * @ingroup Common_register_group_W5200
  192. * @brief Gateway IP Register address(R/W)
  193. * @details \ref GAR configures the default gateway address.
  194. */
  195. #define GAR (_W5200_IO_BASE_ + (0x0001)) // GW Address
  196. /**
  197. * @ingroup Common_register_group_W5200
  198. * @brief Subnet mask Register address(R/W)
  199. * @details \ref SUBR configures the subnet mask address.
  200. */
  201. #define SUBR (_W5200_IO_BASE_ + (0x0005)) // SN Mask Address
  202. /**
  203. * @ingroup Common_register_group_W5200
  204. * @brief Source MAC Register address(R/W)
  205. * @details \ref SHAR configures the source hardware address.
  206. */
  207. #define SHAR (_W5200_IO_BASE_ + (0x0009)) // Source Hardware Address
  208. /**
  209. * @ingroup Common_register_group_W5200
  210. * @brief Source IP Register address(R/W)
  211. * @details \ref SIPR configures the source IP address.
  212. */
  213. #define SIPR (_W5200_IO_BASE_ + (0x000F)) // Source IP Address
  214. // Reserved (_W5200_IO_BASE_ + (0x0013))
  215. // Reserved (_W5200_IO_BASE_ + (0x0014))
  216. /**
  217. * @ingroup Common_register_group_W5200
  218. * @brief Interrupt Register(R/W)
  219. * @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.
  220. * If \ref IR is not equal to x00 INTn PIN is asserted to low until it is x00\n\n
  221. * Each bit of \ref IR defined as follows.
  222. * <table>
  223. * <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>
  224. * <tr> <td>CONFLICT</td> <td>Reserved</td> <td>PPPoE</td> <td>Reserved</td> <td>Reserved</td> <td>Reserved</td> <td>Reserved</td> <td>Reserved</td> </tr>
  225. * </table>
  226. * - \ref IR_CONFLICT : IP conflict
  227. * - \ref IR_PPPoE : PPPoE connection close
  228. */
  229. #define IR (_W5200_IO_BASE_ + (0x0015)) // Interrupt
  230. /**
  231. * @ingroup Common_register_group_W5200
  232. * @brief Socket Interrupt Mask Register(R/W)
  233. * @details Each bit of \ref _IMR_ corresponds to each bit of \ref IR2.
  234. * When a bit of \ref _IMR_ is and the corresponding bit of \ref IR2 is Interrupt will be issued.
  235. * In other words, if a bit of \ref _IMR_, an interrupt will be not issued even if the corresponding bit of \ref IR2 is set
  236. * @note This Register is same operated as <b>SMIR<b> of W5100, W5300 and W5550.\n
  237. * So, \ref setSIMR() set a value to _IMR_ for integrating with ioLibrary
  238. */
  239. #define _IMR_ (_W5200_IO_BASE_ + (0x0016)) // Socket Interrupt Mask
  240. /**
  241. * @ingroup Common_register_group_W5200
  242. * @brief Timeout register address( 1 is 100us )(R/W)
  243. * @details \ref _RTR_ configures the retransmission timeout period. The unit of timeout period is 100us and the default of \ref _RTR_ is x07D0.
  244. * And so the default timeout period is 200ms(100us X 2000). During the time configured by \ref _RTR_, W5200 waits for the peer response
  245. * to the packet that is transmitted by \ref Sn_CR (CONNECT, DISCON, CLOSE, SEND, SEND_MAC, SEND_KEEP command).
  246. * If the peer does not respond within the \ref _RTR_ time, W5200 retransmits the packet or issues timeout.
  247. */
  248. #define _RTR_ (_W5200_IO_BASE_ + (0x0017)) // Retry Time
  249. /**
  250. * @ingroup Common_register_group_W5200
  251. * @brief Retry count register(R/W)
  252. * @details \ref _RCR_ configures the number of time of retransmission.
  253. * When retransmission occurs as many as ref _RCR_+1 Timeout interrupt is issued (\ref Sn_IR_TIMEOUT = '1').
  254. */
  255. #define _RCR_ (_W5200_IO_BASE_ + (0x0019)) // Retry Count
  256. // Reserved (_W5200_IO_BASE_ + (0x001A))
  257. // Reserved (_W5200_IO_BASE_ + (0x001B))
  258. /**
  259. * @ingroup Common_register_group_W5200
  260. * @brief PPP LCP Request Timer register in PPPoE mode(R)
  261. * @details \ref PATR notifies authentication method that has been agreed at the connection with
  262. * PPPoE Server. W5200 supports two types of Authentication method - PAP and CHAP.
  263. */
  264. #define PATR (_W5200_IO_BASE_ + (0x001C))
  265. /**
  266. * @ingroup Common_register_group_W5200
  267. * @brief PPP LCP Request Timer register in PPPoE mode(R)
  268. * @details \ref PPPALGO notifies authentication algorithm in PPPoE mode. For detailed information,
  269. * please refer to PPPoE application note.
  270. */
  271. #define PPPALGO (_W5200_IO_BASE_ + (0x001E)) // Authentication Algorithm in PPPoE
  272. /**
  273. * @ingroup Common_register_group_W5200
  274. * @brief chip version register address(R)
  275. * @details \ref VERSIONR always indicates the W5200 version as @b 0x03.
  276. */
  277. #define VERSIONR (_W5200_IO_BASE_ + (0x001F)) // Chip version
  278. // Reserved (_W5200_IO_BASE_ + (0x0020))
  279. // Reserved (_W5200_IO_BASE_ + (0x0021))
  280. // Reserved (_W5200_IO_BASE_ + (0x0022))
  281. // Reserved (_W5200_IO_BASE_ + (0x0023))
  282. // Reserved (_W5200_IO_BASE_ + (0x0024))
  283. // Reserved (_W5200_IO_BASE_ + (0x0025))
  284. // Reserved (_W5200_IO_BASE_ + (0x0026))
  285. // Reserved (_W5200_IO_BASE_ + (0x0027))
  286. /**
  287. * @ingroup Common_register_group_W5200
  288. * @brief PPP LCP Request Timer register in PPPoE mode(R)
  289. * @details \ref PTIMER configures the time for sending LCP echo request. The unit of time is 25ms.
  290. */
  291. #define PTIMER (_W5200_IO_BASE_ + (0x0028)) // PPP LCP RequestTimer
  292. /**
  293. * @ingroup Common_register_group_W5200
  294. * @brief PPP LCP Magic number register in PPPoE mode(R)
  295. * @details \ref PMAGIC configures the 4bytes magic number to be used in LCP negotiation.
  296. */
  297. #define PMAGIC (_W5200_IO_BASE_ + (0x0029)) // PPP LCP Magic number
  298. // Reserved (_W5200_IO_BASE_ + (0x002A))
  299. // Reserved (_W5200_IO_BASE_ + (0x002B))
  300. // Reserved (_W5200_IO_BASE_ + (0x002C))
  301. // Reserved (_W5200_IO_BASE_ + (0x002D))
  302. // Reserved (_W5200_IO_BASE_ + (0x002E))
  303. // Reserved (_W5200_IO_BASE_ + (0x002F))
  304. /**
  305. * @ingroup Common_register_group_W5200
  306. * @brief Set Interrupt low level timer register address(R/W)
  307. * @details \ref INTLEVEL configures the Interrupt Assert Time.
  308. */
  309. #define INTLEVEL (_W5200_IO_BASE_ + (0x0030)) // Interrupt Low Level Timer
  310. // Reserved (_W5200_IO_BASE_ + (0x0032))
  311. // Reserved (_W5200_IO_BASE_ + (0x0033))
  312. /**
  313. * @ingroup Common_register_group_W5200
  314. * @brief Socket Interrupt Register(R/W)
  315. * @details \ref IR2 indicates the interrupt status of Socket.\n
  316. * Each bit of \ref IR2 be still until \ref Sn_IR is cleared by the host.\n
  317. * If \ref Sn_IR is not equal to x00 the n-th bit of \ref IR2 is and INTn PIN is asserted until \ref IR2 is x00 */
  318. #define IR2 (_W5200_IO_BASE_ + (0x0034)) // Socket Interrupt
  319. /**
  320. * @ingroup Common_register_group_W5200
  321. * @brief PHYSTATUS(R/W)
  322. * @details \ref PHYSTATUS is the Register to indicate W5200 status of PHY.
  323. * <table>
  324. * <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>
  325. * <tr> <td>Reserved</td> <td>Reserved</td> <td>LINK</td> <td>POWERSAVE</td> <td>POWERDOWN</td> <td>Reserved</td> <td>Reserved</td> <td>Reserved</td> </tr>
  326. * </table>
  327. * - \ref PHYSTATUS_LINK : Link Status Register[Read Only]
  328. * - \ref PHYSTATUS_POWERSAVE : Power save mode of PHY[R/W]
  329. * - \ref PHYSTATUS_POWERDOWN : Power down mode of PHY[R/W]
  330. */
  331. #define PHYSTATUS (_W5200_IO_BASE_ + (0x0035)) // PHY Status
  332. /**
  333. * @ingroup Common_register_group_W5200
  334. * @brief Interrupt mask register(R/W)
  335. * @details \ref IMR2 is used to mask interrupts. Each bit of \ref _IMR_ corresponds to each bit of \ref IR.
  336. * When a bit of \ref IMR2 is and the corresponding bit of \ref IR is an interrupt will be issued. In other words,
  337. * if a bit of \ref IMR2 is an interrupt will not be issued even if the corresponding bit of \ref IR is \n\n
  338. * Each bit of \ref IMR2 defined as the following.
  339. * <table>
  340. * <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>
  341. * <tr> <td>IM_IR7</td> <td>Reserved</td> <td>IM_IR5</td> <td>Reserved</td> <td>Reserved</td> <td>Reserved</td> <td>Reserved</td> <td>Reserved</td> </tr>
  342. * </table>
  343. * - \ref IM_IR7 : IP Conflict Interrupt Mask
  344. * - \ref IM_IR5 : PPPoE Close Interrupt Mask
  345. * @note This Register is same operated as <b>_IMR_<b> of W5100, W5300 and W5550.\n
  346. * So, \ref setIMR() set a value to IMR2 for integrating with ioLibrary
  347. */
  348. #define IMR2 (_W5200_IO_BASE_ + (0x0036)) // Interrupt Mask
  349. //----------------------------- W5200 Socket Registers -----------------------------
  350. //--------------------------- For Backward Compatibility ---------------------------
  351. /**
  352. * @ingroup Socket_register_group_W5200
  353. * @brief socket Mode register(R/W)
  354. * @details \ref Sn_MR configures the option or protocol type of Socket n.\n\n
  355. * Each bit of \ref Sn_MR defined as the following.
  356. * <table>
  357. * <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>
  358. * <tr> <td>MULTI</td> <td>MF</td> <td>ND/MC</td> <td>Reserved</td> <td>Protocol[3]</td> <td>Protocol[2]</td> <td>Protocol[1]</td> <td>Protocol[0]</td> </tr>
  359. * </table>
  360. * - \ref Sn_MR_MULTI : Support UDP Multicasting
  361. * - \ref Sn_MR_MF : Support MACRAW
  362. * - \ref Sn_MR_ND : No Delayed Ack(TCP) flag
  363. * - \ref Sn_MR_MC : IGMP version used <b>in UDP mulitcasting</b>
  364. * - <b>Protocol</b>
  365. * <table>
  366. * <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>
  367. * <tr> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>Closed</td> </tr>
  368. * <tr> <td>0</td> <td>0</td> <td>0</td> <td>1</td> <td>TCP</td> </tr>
  369. * <tr> <td>0</td> <td>0</td> <td>1</td> <td>0</td> <td>UDP</td> </tr>
  370. * <tr> <td>0</td> <td>1</td> <td>0</td> <td>0</td> <td>MACRAW</td> </tr>
  371. * </table>
  372. * - <b>In case of Socket 0</b>
  373. * <table>
  374. * <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>
  375. * <tr> <td>0</td> <td>1</td> <td>0</td> <td>0</td> <td>MACRAW</td> </tr>
  376. * <tr> <td>0</td> <td>1</td> <td>0</td> <td>1</td> <td>PPPoE</td> </tr>
  377. * </table>
  378. * - \ref Sn_MR_MACRAW : MAC LAYER RAW SOCK \n
  379. * - \ref Sn_MR_UDP : UDP
  380. * - \ref Sn_MR_TCP : TCP
  381. * - \ref Sn_MR_CLOSE : Unused socket
  382. * @note MACRAW mode should be only used in Socket 0.
  383. */
  384. #define Sn_MR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0000)) // socket Mode register
  385. /**
  386. * @ingroup Socket_register_group_W5200
  387. * @brief Socket command register(R/W)
  388. * @details This is used to set the command for Socket n such as OPEN, CLOSE, CONNECT, LISTEN, SEND, and RECEIVE.\n
  389. * After W5200 accepts the command, the \ref Sn_CR register is automatically cleared to 0x00.
  390. * Even though \ref Sn_CR is cleared to 0x00, the command is still being processed.\n
  391. * To check whether the command is completed or not, please check the \ref Sn_IR or \ref Sn_SR.
  392. * - \ref Sn_CR_OPEN : Initialize or open socket.
  393. * - \ref Sn_CR_LISTEN : Wait connection request in TCP mode(<b>Server mode</b>)
  394. * - \ref Sn_CR_CONNECT : Send connection request in TCP mode(<b>Client mode</b>)
  395. * - \ref Sn_CR_DISCON : Send closing request in TCP mode.
  396. * - \ref Sn_CR_CLOSE : Close socket.
  397. * - \ref Sn_CR_SEND : Update TX buffer pointer and send data.
  398. * - \ref Sn_CR_SEND_MAC : Send data with MAC address, so without ARP process.
  399. * - \ref Sn_CR_SEND_KEEP : Send keep alive message.
  400. * - \ref Sn_CR_RECV : Update RX buffer pointer and receive data.
  401. * - <b>In case of S0_MR(P3:P0) = S0_MR_PPPoE</b>
  402. * <table>
  403. * <tr> <td><b>Value</b></td> <td><b>Symbol</b></td> <td><b>Description</b></td></tr>
  404. * <tr> <td>0x23</td> <td>PCON</td> <td>PPPoE connection begins by transmitting PPPoE discovery packet</td> </tr>
  405. * <tr> <td>0x24</td> <td>PDISCON</td> <td>Closes PPPoE connection</td> </tr>
  406. * <tr> <td>0x25</td> <td>PCR</td> <td>In each phase, it transmits REQ message.</td> </tr>
  407. * <tr> <td>0x26</td> <td>PCN</td> <td>In each phase, it transmits NAK message.</td> </tr>
  408. * <tr> <td>0x27</td> <td>PCJ</td> <td>In each phase, it transmits REJECT message.</td> </tr>
  409. * </table>
  410. */
  411. #define Sn_CR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0001)) // channel Sn_CR register
  412. /**
  413. * @ingroup Socket_register_group_W5200
  414. * @brief Socket interrupt register(R)
  415. * @details \ref Sn_IR indicates the status of Socket Interrupt such as establishment, termination, receiving data, timeout).\n
  416. * When an interrupt occurs and the corresponding bit of \ref Sn_IMR is the corresponding bit of \ref Sn_IR becomes \n
  417. * In order to clear the \ref Sn_IR bit, the host should write the bit to \n
  418. * <table>
  419. * <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>
  420. * <tr> <td>PRECV</td> <td>PFAIL</td> <td>PNEXT</td> <td>SEND_OK</td> <td>TIMEOUT</td> <td>RECV</td> <td>DISCON</td> <td>CON</td> </tr>
  421. * </table>
  422. * - \ref Sn_IR_PRECV : <b>PPP Receive Interrupt</b>
  423. * - \ref Sn_IR_PFAIL : <b>PPP Fail Interrupt</b>
  424. * - \ref Sn_IR_PNEXT : <b>PPP Next Phase Interrupt</b>
  425. * - \ref Sn_IR_SENDOK : <b>SEND_OK Interrupt</b>
  426. * - \ref Sn_IR_TIMEOUT : <b>TIMEOUT Interrupt</b>
  427. * - \ref Sn_IR_RECV : <b>RECV Interrupt</b>
  428. * - \ref Sn_IR_DISCON : <b>DISCON Interrupt</b>
  429. * - \ref Sn_IR_CON : <b>CON Interrupt</b>
  430. */
  431. #define Sn_IR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0002)) // channel interrupt register
  432. /**
  433. * @ingroup Socket_register_group_W5200
  434. * @brief Socket status register(R)
  435. * @details \ref Sn_SR indicates the status of Socket n.\n
  436. * The status of Socket n is changed by \ref Sn_CR or some special control packet as SYN, FIN packet in TCP.
  437. * @par Normal status
  438. * - \ref SOCK_CLOSED : Closed
  439. * - \ref SOCK_INIT : Initiate state
  440. * - \ref SOCK_LISTEN : Listen state
  441. * - \ref SOCK_ESTABLISHED : Success to connect
  442. * - \ref SOCK_CLOSE_WAIT : Closing state
  443. * - \ref SOCK_UDP : UDP socket
  444. * - \ref SOCK_MACRAW : MAC raw mode socket
  445. *@par Temporary status during changing the status of Socket n.
  446. * - \ref SOCK_SYNSENT : This indicates Socket n sent the connect-request packet (SYN packet) to a peer.
  447. * - \ref SOCK_SYNRECV : It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer.
  448. * - \ref SOCK_FIN_WAIT : Connection state
  449. * - \ref SOCK_CLOSING : Closing state
  450. * - \ref SOCK_TIME_WAIT : Closing state
  451. * - \ref SOCK_LAST_ACK : Closing state
  452. */
  453. #define Sn_SR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0003)) // channel status register
  454. /**
  455. * @ingroup Socket_register_group_W5200
  456. * @brief source port register(R/W)
  457. * @details \ref Sn_PORT configures the source port number of Socket n.
  458. * It is valid when Socket n is used in TCP/UDP mode. It should be set before OPEN command is ordered.
  459. */
  460. #define Sn_PORT(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0004)) // source port register
  461. /**
  462. * @ingroup Socket_register_group_W5200
  463. * @brief Peer MAC register address(R/W)
  464. * @details \ref Sn_DHAR configures the destination hardware address of Socket n when using SEND_MAC command in UDP mode or
  465. * it indicates that it is acquired in ARP-process by CONNECT/SEND command.
  466. */
  467. #define Sn_DHAR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0006)) // Peer MAC register address
  468. /**
  469. * @ingroup Socket_register_group_W5200
  470. * @brief Peer IP register address(R/W)
  471. * @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.
  472. * In TCP client mode, it configures an IP address of TCP server before CONNECT command.
  473. * In TCP server mode, it indicates an IP address of TCP client after successfully establishing connection.
  474. * In UDP mode, it configures an IP address of peer to be received the UDP packet by SEND or SEND_MAC command.
  475. */
  476. #define Sn_DIPR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x000C)) // Peer IP register address
  477. /**
  478. * @ingroup Socket_register_group_W5200
  479. * @brief Peer port register address(R/W)
  480. * @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.
  481. * In TCP clientmode, it configures the listen port number of TCP server before CONNECT command.
  482. * In TCP Servermode, it indicates the port number of TCP client after successfully establishing connection.
  483. * In UDP mode, it configures the port number of peer to be transmitted the UDP packet by SEND/SEND_MAC command.
  484. */
  485. #define Sn_DPORT(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0010)) // Peer port register address
  486. /**
  487. * @ingroup Socket_register_group_W5200
  488. * @brief Maximum Segment Size(Sn_MSSR0) register address(R/W)
  489. * @details \ref Sn_MSSR configures or indicates the MTU(Maximum Transfer Unit) of Socket n.
  490. */
  491. #define Sn_MSSR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0012)) // Maximum Segment Size(Sn_MSSR0) register address
  492. /**
  493. * @ingroup Socket_register_group_W5200
  494. * @brief IP Protocol(PROTO) Register(R/W)
  495. * @details \ref Sn_PROTO that sets the protocol number field of the IP header at the IP layer. It is
  496. * valid only in IPRAW mode, and ignored in other modes.
  497. */
  498. #define Sn_PROTO(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0014)) // Protocol of IP Header field register in IP raw mode
  499. /**
  500. * @ingroup Socket_register_group_W5200
  501. * @brief IP Type of Service(TOS) Register(R/W)
  502. * @details \ref Sn_TOS configures the TOS(Type Of Service field in IP Header) of Socket n.
  503. * It is set before OPEN command.
  504. */
  505. #define Sn_TOS(sn) (WIZCHIP_SREG_BLOCK(sn) + 0x0015) // IP Type of Service(TOS) Register
  506. /**
  507. * @ingroup Socket_register_group_W5200
  508. * @brief IP Time to live(TTL) Register(R/W)
  509. * @details \ref Sn_TTL configures the TTL(Time To Live field in IP header) of Socket n.
  510. * It is set before OPEN command.
  511. */
  512. #define Sn_TTL(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0016)) // IP Time to live(TTL) Register
  513. // Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0017))
  514. // Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0018))
  515. // Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0019))
  516. // Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001A))
  517. // Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001B))
  518. // Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001C))
  519. // Reserved (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001D))
  520. /**
  521. * @ingroup Socket_register_group_W5200
  522. * @brief Receive memory size register(R/W)
  523. * @details \ref Sn_RXMEM_SIZE configures the RX buffer block size of Socket n.
  524. * Socket n RX Buffer Block size can be configured with 1,2,4,8, and 16 Kbytes.
  525. * If a different size is configured, the data cannot be normally received from a peer.
  526. * Although Socket n RX Buffer Block size is initially configured to 2Kbytes,
  527. * user can re-configure its size using \ref Sn_RXMEM_SIZE. The total sum of \ref Sn_RXMEM_SIZE can not be exceed 16Kbytes.
  528. * When exceeded, the data reception error is occurred.
  529. */
  530. #define Sn_RXMEM_SIZE(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001E)) // Receive memory size reigster
  531. /**
  532. * @ingroup Socket_register_group_W5200
  533. * @brief Transmit memory size register(R/W)
  534. * @details \ref Sn_TXMEM_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.
  535. * If a different size is configured, the data can't be normally transmitted to a peer.
  536. * Although Socket n TX Buffer Block size is initially configured to 2Kbytes,
  537. * user can be re-configure its size using \ref Sn_TXMEM_SIZE. The total sum of \ref Sn_TXMEM_SIZE can not be exceed 16Kbytes.
  538. * When exceeded, the data transmission error is occurred.
  539. */
  540. #define Sn_TXMEM_SIZE(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001F)) // Transmit memory size reigster
  541. /**
  542. * @ingroup Socket_register_group_W5200
  543. * @brief Transmit free memory size register(R)
  544. * @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_TXMEM_SIZE.
  545. * 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.
  546. * Therefore, check before saving the data to the Socket n TX Buffer, and if data is equal or smaller than its checked size,
  547. * 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,
  548. * transmit the data after dividing into the checked size and saving in the Socket n TX buffer.
  549. */
  550. #define Sn_TX_FSR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0020)) // Transmit free memory size register
  551. /**
  552. * @ingroup Socket_register_group_W5200
  553. * @brief Transmit memory read pointer register address(R)
  554. * @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.
  555. * After its initialization, it is auto-increased by SEND command.
  556. * 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.
  557. * After transmitting the saved data, the SEND command increases the \ref Sn_TX_RD as same as the \ref Sn_TX_WR.
  558. * If its increment value exceeds the maximum value 0xFFFF, (greater than 0x10000 and the carry bit occurs),
  559. * then the carry bit is ignored and will automatically update with the lower 16bits value.
  560. */
  561. #define Sn_TX_RD(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0022)) // Transmit memory read pointer register address
  562. /**
  563. * @ingroup Socket_register_group_W5200
  564. * @brief Transmit memory write pointer register address(R/W)
  565. * @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
  566. * It should be read or be updated like as follows.\n
  567. * 1. Read the starting address for saving the transmitting data.\n
  568. * 2. Save the transmitting data from the starting address of Socket n TX buffer.\n
  569. * 3. After saving the transmitting data, update \ref Sn_TX_WR to the increased value as many as transmitting data size.
  570. * If the increment 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.\n
  572. * 4. Transmit the saved data in Socket n TX Buffer by using SEND/SEND command
  573. */
  574. #define Sn_TX_WR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0024)) // Transmit memory write pointer register address
  575. /**
  576. * @ingroup Socket_register_group_W5200
  577. * @brief Received data size register(R)
  578. * @details \ref Sn_RX_RSR indicates the data size received and saved in Socket n RX Buffer.
  579. * \ref Sn_RX_RSR does not exceed the \ref Sn_RXMEM_SIZE and is calculated as the difference between
  580. * Socket n RX Write Pointer (\ref Sn_RX_WR)and Socket n RX Read Pointer (\ref Sn_RX_RD)
  581. */
  582. #define Sn_RX_RSR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0026)) // Received data size register
  583. /**
  584. * @ingroup Socket_register_group_W5200
  585. * @brief Read point of Receive memory(R/W)
  586. * @details \ref Sn_RX_RD is initialized by OPEN command. Make sure to be read or updated as follows.\n
  587. * 1. Read the starting save address of the received data.\n
  588. * 2. Read data from the starting address of Socket n RX Buffer.\n
  589. * 3. After reading the received data, Update \ref Sn_RX_RD to the increased value as many as the reading size.
  590. * If the increment value exceeds the maximum value 0xFFFF, that is, is greater than 0x10000 and the carry bit occurs,
  591. * update with the lower 16bits value ignored the carry bit.\n
  592. * 4. Order RECV command is for notifying the updated \ref Sn_RX_RD to W5200.
  593. */
  594. #define Sn_RX_RD(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0028)) // Read point of Receive memory
  595. /**
  596. * @ingroup Socket_register_group_W5200
  597. * @brief Write point of Receive memory(R)
  598. * @details \ref Sn_RX_WR is initialized by OPEN command and it is auto-increased by the data reception.
  599. * If the increased value exceeds the maximum value 0xFFFF, (greater than 0x10000 and the carry bit occurs),
  600. * then the carry bit is ignored and will automatically update with the lower 16bits value.
  601. */
  602. #define Sn_RX_WR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002A)) // Write point of Receive memory
  603. /**
  604. * @ingroup Socket_register_group_W5200
  605. * @brief socket interrupt mask register(R)
  606. * @details \ref Sn_IMR masks the interrupt of Socket n.
  607. * 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
  608. * 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
  609. * Host is interrupted by asserted INTn PIN to low.
  610. */
  611. #define Sn_IMR(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002C)) // socket interrupt mask register
  612. /**
  613. * @ingroup Socket_register_group_W5200
  614. * @brief Fragment field value in IP header register(R/W)
  615. * @details \ref Sn_FRAG configures the FRAG(Fragment field in IP header).
  616. */
  617. #define Sn_FRAG(sn) (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002D)) // frag field value in IP header register
  618. //----------------------------- W5200 Register values -----------------------------
  619. /* MODE register values */
  620. /**
  621. * @brief Reset
  622. * @details If this bit is All internal registers will be initialized. It will be automatically cleared as after S/W reset.
  623. */
  624. #define MR_RST 0x80 ///< reset
  625. /**
  626. * @brief Wake on LAN
  627. * @details 0 : Disable WOL mode\n
  628. * 1 : Enable WOL mode\n
  629. * If WOL mode is enabled and the received magic packet over UDP has been normally processed, the Interrupt PIN (INTn) asserts to low.
  630. * 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.)
  631. * @note The magic packet over UDP supported by W5200 consists of 6 bytes synchronization stream (xFFFFFFFFFFFF and
  632. * 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.
  633. */
  634. #define MR_WOL 0x20 ///< Wake on Lan
  635. /**
  636. * @brief Ping block
  637. * @details 0 : Disable Ping block\n
  638. * 1 : Enable Ping block\n
  639. * If the bit is it blocks the response to a ping request.
  640. */
  641. #define MR_PB 0x10 ///< ping block
  642. /**
  643. * @brief Enable PPPoE
  644. * @details 0 : DisablePPPoE mode\n
  645. * 1 : EnablePPPoE mode\n
  646. * If you use ADSL, this bit should be '1'.
  647. */
  648. #define MR_PPPOE 0x08 ///< enable pppoe
  649. /**
  650. * @brief Address Auto-Increment in Indirect Bus Interface
  651. * @details 0 : Disable auto-increment \n
  652. * 1 : Enable auto-incremente \n
  653. * At the Indirect Bus Interface mode, if this bit is set as ��1��, the address will
  654. * be automatically increased by 1 whenever read and write are performed.
  655. */
  656. #define MR_AI 0x02 ///< auto-increment in indirect mode
  657. /**
  658. * @brief Indirect Bus Interface mode
  659. * @details 0 : Disable Indirect bus Interface mode \n
  660. * 1 : Enable Indirect bus Interface mode \n
  661. * If this bit is set as ��1��, Indirect Bus Interface mode is set.
  662. */
  663. #define MR_IND 0x01 ///< enable indirect mode
  664. /* IR register values */
  665. /**
  666. * @brief Check IP conflict.
  667. * @details Bit is set as when own source IP address is same with the sender IP address in the received ARP request.
  668. */
  669. #define IR_CONFLICT 0x80 ///< check ip confict
  670. /**
  671. * @brief Get the PPPoE close message.
  672. * @details When PPPoE is disconnected during PPPoE mode, this bit is set.
  673. */
  674. #define IR_PPPoE 0x20 ///< get the PPPoE close message
  675. /**
  676. * @brief Link Status [Read Only]
  677. * @details 0: Link down \n 1: Link up \n
  678. */
  679. #define PHYSTATUS_LINK 0x20
  680. /**
  681. * @brief Power save mode of PHY
  682. * @details 0: Disable Power save mode \n 1: Enable Power save mode \n
  683. */
  684. #define PHYSTATUS_POWERSAVE 0x10
  685. /**
  686. * @brief Power down mode of PHY
  687. * @details 0: Disable Power down mode \n 1: Enable Power down mode\n
  688. */
  689. #define PHYSTATUS_POWERDOWN 0x08
  690. // Sn_MR values
  691. /* Sn_MR Default values */
  692. /**
  693. * @brief Unused socket
  694. * @details This configures the protocol mode of Socket n.
  695. */
  696. #define Sn_MR_CLOSE 0x00 ///< unused socket
  697. /**
  698. * @brief TCP
  699. * @details This configures the protocol mode of Socket n.
  700. */
  701. #define Sn_MR_TCP 0x01 ///< TCP
  702. /**
  703. * @brief UDP
  704. * @details This configures the protocol mode of Socket n.
  705. */
  706. #define Sn_MR_UDP 0x02 ///< UDP
  707. #define Sn_MR_IPRAW 0x03 ///< IP LAYER RAW SOCK
  708. /**
  709. * @brief MAC LAYER RAW SOCK
  710. * @details This configures the protocol mode of Socket n.
  711. * @note MACRAW mode should be only used in Socket 0.
  712. */
  713. #define Sn_MR_MACRAW 0x04 ///< MAC LAYER RAW SOCK
  714. /**
  715. * @brief PPPoE
  716. * @details This configures the protocol mode of Socket n.
  717. * @note PPPoE mode should be only used in Socket 0.
  718. */
  719. #define Sn_MR_PPPOE 0x05 ///< PPPoE
  720. /**
  721. * @brief No Delayed Ack(TCP), Multicast flag
  722. * @details 0 : Disable No Delayed ACK option\n
  723. * 1 : Enable No Delayed ACK option\n
  724. * This bit is applied only during TCP mode (P[3:0] = 001).\n
  725. * When this bit is It sends the ACK packet without delay as soon as a Data packet is received from a peer.\n
  726. * When this bit is It sends the ACK packet after waiting for the timeout time configured by \ref _RTR_.
  727. */
  728. #define Sn_MR_ND 0x20 ///< No Delayed Ack(TCP) flag
  729. /* Sn_MR Default values */
  730. /**
  731. * @brief Support UDP Multicasting
  732. * @details 0 : disable Multicasting\n
  733. * 1 : enable Multicasting\n
  734. * This bit is applied only during UDP mode(P[3:0] = 010).\n
  735. * To use multicasting, \ref Sn_DIPR & \ref Sn_DPORT should be respectively configured with the multicast group IP address & port number
  736. * before Socket n is opened by OPEN command of \ref Sn_CR.
  737. */
  738. #define Sn_MR_MC Sn_MR_ND ///< Select IGMP version 1(0) or 2(1)
  739. /**
  740. * @brief Multicast Blocking in \ref Sn_MR_MACRAW mode
  741. * @details 0 : using IGMP version 2\n
  742. * 1 : using IGMP version 1\n
  743. * This bit is applied only during UDP mode(P[3:0] = 010 and MULTI = '1')
  744. * It configures the version for IGMP messages (Join/Leave/Report).
  745. */
  746. #define Sn_MR_MF 0x40 ///< Use MAC filter
  747. #define Sn_MR_MFEN Sn_MR_MF
  748. /* Sn_MR Default values */
  749. /**
  750. * @brief Support UDP Multicasting
  751. * @details 0 : disable Multicasting\n
  752. * 1 : enable Multicasting\n
  753. * This bit is applied only during UDP mode(P[3:0] = 010).\n
  754. * To use multicasting, \ref Sn_DIPR & \ref Sn_DPORT should be respectively configured with the multicast group IP address & port number
  755. * before Socket n is opened by OPEN command of \ref Sn_CR.
  756. */
  757. #define Sn_MR_MULTI 0x80 ///< support multicating
  758. /* Sn_CR values */
  759. /**
  760. * @brief Initialize or open socket
  761. * @details Socket n is initialized and opened according to the protocol selected in Sn_MR(P3:P0).
  762. * The table below shows the value of \ref Sn_SR corresponding to \ref Sn_MR.\n
  763. * <table>
  764. * <tr> <td>\b Sn_MR (P[3:0])</td> <td>\b Sn_SR</td> </tr>
  765. * <tr> <td>Sn_MR_CLOSE (000)</td> <td>--</td> </tr>
  766. * <tr> <td>Sn_MR_TCP (001)</td> <td>SOCK_INIT (0x13)</td> </tr>
  767. * <tr> <td>Sn_MR_UDP (010)</td> <td>SOCK_UDP (0x22)</td> </tr>
  768. * <tr> <td>S0_MR_IPRAW (011)</td> <td>SOCK_IPRAW (0x32)</td> </tr>
  769. * <tr> <td>S0_MR_MACRAW (100)</td> <td>SOCK_MACRAW (0x42)</td> </tr>
  770. * <tr> <td>S0_MR_PPPoE (101)</td> <td>SOCK_PPPoE (0x5F)</td> </tr>
  771. * </table>
  772. */
  773. #define Sn_CR_OPEN 0x01 ///< initialize or open socket
  774. /**
  775. * @brief Wait connection request in TCP mode(Server mode)
  776. * @details This is valid only in TCP mode (Sn_MR(P3:P0) = \ref Sn_MR_TCP).//
  777. * In this mode, Socket n operates as a 'TCP server' and waits for connection-request (SYN packet) from any 'TCP client'.//
  778. * The \ref Sn_SR changes the state from SOCK_INIT to SOCKET_LISTEN.//
  779. * When a 'TCP client' connection request is successfully established,
  780. * the \ref Sn_SR changes from SOCK_LISTEN to SOCK_ESTABLISHED and the Sn_IR(0) becomes
  781. * But when a 'TCP client' connection request is failed, Sn_IR(3) becomes and the status of \ref Sn_SR changes to SOCK_CLOSED.
  782. */
  783. #define Sn_CR_LISTEN 0x02 ///< wait connection request in tcp mode(Server mode)
  784. /**
  785. * @brief Send connection request in TCP mode(Client mode)
  786. * @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).
  787. * If the connect-request is successful, the \ref Sn_SR is changed to \ref SOCK_ESTABLISHED and the Sn_IR(0) becomes \n\n
  788. * The connect-request fails in the following three cases.\n
  789. * 1. When a @b ARPTO occurs (\ref Sn_IR[3] = '1') because destination hardware address is not acquired through the ARP-process.\n
  790. * 2. When a @b SYN/ACK packet is not received and @b TCPTO (Sn_IR(3) ='1')\n
  791. * 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.
  792. * @note This is valid only in TCP mode and operates when Socket n acts as <b>TCP client</b>
  793. */
  794. #define Sn_CR_CONNECT 0x04 ///< send connection request in tcp mode(Client mode)
  795. /**
  796. * @brief Send closing request in TCP mode
  797. * @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
  798. * @par Active close
  799. * it transmits disconnect-request(FIN packet) to the connected peer\n
  800. * @par Passive close
  801. * When FIN packet is received from peer, a FIN packet is replied back to the peer.\n
  802. * @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
  803. * Otherwise, TCPTO occurs (Sn_IR(3)='1') and then \ref Sn_SR is changed to \ref SOCK_CLOSED.
  804. * @note Valid only in TCP mode.
  805. */
  806. #define Sn_CR_DISCON 0x08 ///< send closing reqeuset in tcp mode
  807. /**
  808. * @brief Close socket
  809. * @details Sn_SR is changed to \ref SOCK_CLOSED.
  810. */
  811. #define Sn_CR_CLOSE 0x10
  812. /**
  813. * @brief Update TX buffer pointer and send data
  814. * @details SEND transmits all the data in the Socket n TX buffer.\n
  815. * For more details, please refer to Socket n TX Free Size Register (\ref Sn_TX_FSR), Socket n,
  816. * TX Write Pointer Register(\ref Sn_TX_WR), and Socket n TX Read Pointer Register(\ref Sn_TX_RD).
  817. */
  818. #define Sn_CR_SEND 0x20
  819. /**
  820. * @brief Send data with MAC address, so without ARP process
  821. * @details The basic operation is same as SEND.\n
  822. * Normally SEND transmits data after destination hardware address is acquired by the automatic ARP-process(Address Resolution Protocol).\n
  823. * But SEND_MAC transmits data without the automatic ARP-process.\n
  824. * In this case, the destination hardware address is acquired from \ref Sn_DHAR configured by host, instead of APR-process.
  825. * @note Valid only in UDP mode.
  826. */
  827. #define Sn_CR_SEND_MAC 0x21
  828. /**
  829. * @brief Send keep alive message
  830. * @details It checks the connection status by sending 1byte keep-alive packet.\n
  831. * If the peer can not respond to the keep-alive packet during timeout time, the connection is terminated and the timeout interrupt will occur.
  832. * @note Valid only in TCP mode.
  833. */
  834. #define Sn_CR_SEND_KEEP 0x22
  835. /**
  836. * @brief Update RX buffer pointer and receive data
  837. * @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
  838. * 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),
  839. * and Socket n RX Read Pointer Register (\ref Sn_RX_RD).
  840. */
  841. #define Sn_CR_RECV 0x40
  842. /**
  843. * @brief PPPoE connection
  844. * @details PPPoE connection begins by transmitting PPPoE discovery packet
  845. */
  846. #define Sn_CR_PCON 0x23
  847. /**
  848. * @brief Closes PPPoE connection
  849. * @details Closes PPPoE connection
  850. */
  851. #define Sn_CR_PDISCON 0x24
  852. /**
  853. * @brief REQ message transmission
  854. * @details In each phase, it transmits REQ message.
  855. */
  856. #define Sn_CR_PCR 0x25
  857. /**
  858. * @brief NAK massage transmission
  859. * @details In each phase, it transmits NAK message.
  860. */
  861. #define Sn_CR_PCN 0x26
  862. /**
  863. * @brief REJECT message transmission
  864. * @details In each phase, it transmits REJECT message.
  865. */
  866. #define Sn_CR_PCJ 0x27
  867. /* Sn_IR values */
  868. /**
  869. * @brief PPP Receive Interrupt
  870. * @details PPP Receive Interrupts when the option which is not supported is received.
  871. */
  872. #define Sn_IR_PRECV 0x80
  873. /**
  874. * @brief PPP Fail Interrupt
  875. * @details PPP Fail Interrupts when PAP Authentication is failed.
  876. */
  877. #define Sn_IR_PFAIL 0x40
  878. /**
  879. * @brief PPP Next Phase Interrupt
  880. * @details PPP Next Phase Interrupts when the phase is changed during ADSL connection process.
  881. */
  882. #define Sn_IR_PNEXT 0x20
  883. /**
  884. * @brief SEND_OK Interrupt
  885. * @details This is issued when SEND command is completed.
  886. */
  887. #define Sn_IR_SENDOK 0x10 ///< complete sending
  888. /**
  889. * @brief TIMEOUT Interrupt
  890. * @details This is issued when ARPTO or TCPTO occurs.
  891. */
  892. #define Sn_IR_TIMEOUT 0x08 ///< assert timeout
  893. /**
  894. * @brief RECV Interrupt
  895. * @details This is issued whenever data is received from a peer.
  896. */
  897. #define Sn_IR_RECV 0x04
  898. /**
  899. * @brief DISCON Interrupt
  900. * @details This is issued when FIN or FIN/ACK packet is received from a peer.
  901. */
  902. #define Sn_IR_DISCON 0x02
  903. /**
  904. * @brief CON Interrupt
  905. * @details This is issued one time when the connection with peer is successful and then \ref Sn_SR is changed to \ref SOCK_ESTABLISHED.
  906. */
  907. #define Sn_IR_CON 0x01
  908. /* Sn_SR values */
  909. /**
  910. * @brief Closed
  911. * @details This indicates that Socket n is released.\n
  912. * When DICON, CLOSE command is ordered, or when a timeout occurs, it is changed to \ref SOCK_CLOSED regardless of previous status.
  913. */
  914. #define SOCK_CLOSED 0x00 ///< closed
  915. /**
  916. * @brief Initiate state
  917. * @details This indicates Socket n is opened with TCP mode.\n
  918. * It is changed to \ref SOCK_INIT when Sn_MR(P[3:0]) = 001)and OPEN command is ordered.\n
  919. * After \ref SOCK_INIT, user can use LISTEN /CONNECT command.
  920. */
  921. #define SOCK_INIT 0x13 ///< init state
  922. /**
  923. * @brief Listen state
  924. * @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
  925. * It will change to \ref SOCK_ESTABLISHED when the connection-request is successfully accepted.\n
  926. * Otherwise it will change to \ref SOCK_CLOSED after TCPTO occurred (Sn_IR(TIMEOUT) = '1').
  927. */
  928. #define SOCK_LISTEN 0x14
  929. /**
  930. * @brief Connection state
  931. * @details This indicates Socket n sent the connect-request packet (SYN packet) to a peer.\n
  932. * It is temporarily shown when \ref Sn_SR is changed from \ref SOCK_INIT to \ref SOCK_ESTABLISHED by CONNECT command.\n
  933. * If connect-accept(SYN/ACK packet) is received from the peer at SOCK_SYNSENT, it changes to \ref SOCK_ESTABLISHED.\n
  934. * Otherwise, it changes to \ref SOCK_CLOSED after TCPTO (\ref Sn_IR[TIMEOUT] = '1') is occurred.
  935. */
  936. #define SOCK_SYNSENT 0x15
  937. /**
  938. * @brief Connection state
  939. * @details It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer.\n
  940. * If socket n sends the response (SYN/ACK packet) to the peer successfully, it changes to \ref SOCK_ESTABLISHED. \n
  941. * If not, it changes to \ref SOCK_CLOSED after timeout occurs (\ref Sn_IR[TIMEOUT] = '1').
  942. */
  943. #define SOCK_SYNRECV 0x16
  944. /**
  945. * @brief Success to connect
  946. * @details This indicates the status of the connection of Socket n.\n
  947. * 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
  948. * when the CONNECT command is successful.\n
  949. * During \ref SOCK_ESTABLISHED, DATA packet can be transferred using SEND or RECV command.
  950. */
  951. #define SOCK_ESTABLISHED 0x17
  952. /**
  953. * @brief Closing state
  954. * @details These indicate Socket n is closing.\n
  955. * These are shown in disconnect-process such as active-close and passive-close.\n
  956. * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED.
  957. */
  958. #define SOCK_FIN_WAIT 0x18
  959. /**
  960. * @brief Closing state
  961. * @details These indicate Socket n is closing.\n
  962. * These are shown in disconnect-process such as active-close and passive-close.\n
  963. * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED.
  964. */
  965. #define SOCK_CLOSING 0x1A
  966. /**
  967. * @brief Closing state
  968. * @details These indicate Socket n is closing.\n
  969. * These are shown in disconnect-process such as active-close and passive-close.\n
  970. * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED.
  971. */
  972. #define SOCK_TIME_WAIT 0x1B
  973. /**
  974. * @brief Closing state
  975. * @details This indicates Socket n received the disconnect-request (FIN packet) from the connected peer.\n
  976. * This is half-closing status, and data can be transferred.\n
  977. * For full-closing, DISCON command is used. But For just-closing, CLOSE command is used.
  978. */
  979. #define SOCK_CLOSE_WAIT 0x1C
  980. /**
  981. * @brief Closing state
  982. * @details This indicates Socket n is waiting for the response (FIN/ACK packet) to the disconnect-request (FIN packet) by passive-close.\n
  983. * It changes to \ref SOCK_CLOSED when Socket n received the response successfully, or when timeout occurs (\ref Sn_IR[TIMEOUT] = '1').
  984. */
  985. #define SOCK_LAST_ACK 0x1D
  986. /**
  987. * @brief UDP socket
  988. * @details This indicates Socket n is opened in UDP mode(Sn_MR(P[3:0]) = 010).\n
  989. * It changes to SOCK_UDP when Sn_MR(P[3:0]) = 010 and OPEN command is ordered.\n
  990. * Unlike TCP mode, data can be transfered without the connection-process.
  991. */
  992. #define SOCK_UDP 0x22 ///< udp socket
  993. /**
  994. * @brief IP raw mode socket
  995. * @details TThe socket is opened in IPRAW mode. The SOCKET status is change to SOCK_IPRAW when Sn_MR (P3:P0) is
  996. * Sn_MR_IPRAW and OPEN command is used.\n
  997. * IP Packet can be transferred without a connection similar to the UDP mode.
  998. */
  999. #define SOCK_IPRAW 0x32 ///< ip raw mode socket
  1000. /**
  1001. * @brief MAC raw mode socket
  1002. * @details This indicates Socket 0 is opened in MACRAW mode (S0_MR(P[3:0]) = 100and is valid only in Socket 0.\n
  1003. * It changes to SOCK_MACRAW when S0_MR(P[3:0] = 100)and OPEN command is ordered.\n
  1004. * Like UDP mode socket, MACRAW mode Socket 0 can transfer a MAC packet (Ethernet frame) without the connection-process.
  1005. */
  1006. #define SOCK_MACRAW 0x42 ///< mac raw mode socket
  1007. /**
  1008. * @brief PPPoE mode socket
  1009. * @details It is the status that SOCKET0 is open as PPPoE mode. It is changed to SOCK_PPPoE in case of S0_CR=OPEN and S0_MR
  1010. * (P3:P0)=S0_MR_PPPoE.\n
  1011. * It is temporarily used at the PPPoE
  1012. connection.
  1013. */
  1014. #define SOCK_PPPOE 0x5F ///< pppoe socket
  1015. // IP PROTOCOL
  1016. #define IPPROTO_IP 0 ///< Dummy for IP
  1017. #define IPPROTO_ICMP 1 ///< Control message protocol
  1018. #define IPPROTO_IGMP 2 ///< Internet group management protocol
  1019. #define IPPROTO_GGP 3 ///< GW^2 (deprecated)
  1020. #define IPPROTO_TCP 6 ///< TCP
  1021. #define IPPROTO_PUP 12 ///< PUP
  1022. #define IPPROTO_UDP 17 ///< UDP
  1023. #define IPPROTO_IDP 22 ///< XNS idp
  1024. #define IPPROTO_ND 77 ///< UNOFFICIAL net disk protocol
  1025. #define IPPROTO_RAW 255 ///< Raw IP packet
  1026. /**
  1027. * @brief Enter a critical section
  1028. *
  1029. * @details It is provided to protect your shared code which are executed without distribution. \n \n
  1030. *
  1031. * In non-OS environment, It can be just implemented by disabling whole interrupt.\n
  1032. * In OS environment, You can replace it to critical section api supported by OS.
  1033. *
  1034. * \sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF()
  1035. * \sa WIZCHIP_CRITICAL_EXIT()
  1036. */
  1037. #define WIZCHIP_CRITICAL_ENTER() WIZCHIP.CRIS._enter()
  1038. #ifdef _exit
  1039. #undef _exit
  1040. #endif
  1041. /**
  1042. * @brief Exit a critical section
  1043. *
  1044. * @details It is provided to protect your shared code which are executed without distribution. \n\n
  1045. *
  1046. * In non-OS environment, It can be just implemented by disabling whole interrupt. \n
  1047. * In OS environment, You can replace it to critical section api supported by OS.
  1048. *
  1049. * @sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF()
  1050. * @sa WIZCHIP_CRITICAL_ENTER()
  1051. */
  1052. #define WIZCHIP_CRITICAL_EXIT() WIZCHIP.CRIS._exit()
  1053. ////////////////////////
  1054. // Basic I/O Function //
  1055. ////////////////////////
  1056. /**
  1057. * @ingroup Basic_IO_function_W5200
  1058. * @brief It reads 1 byte value from a register.
  1059. * @param AddrSel Register address
  1060. * @return The value of register
  1061. */
  1062. uint8_t WIZCHIP_READ (uint32_t AddrSel);
  1063. /**
  1064. * @ingroup Basic_IO_function_W5200
  1065. * @brief It writes 1 byte value to a register.
  1066. * @param AddrSel Register address
  1067. * @param wb Write data
  1068. * @return void
  1069. */
  1070. void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb );
  1071. /**
  1072. * @ingroup Basic_IO_function_W5200
  1073. * @brief It reads sequence data from registers.
  1074. * @param AddrSel Register address
  1075. * @param pBuf Pointer buffer to read data
  1076. * @param len Data length
  1077. */
  1078. void WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
  1079. /**
  1080. * @ingroup Basic_IO_function_W5200
  1081. * @brief It writes sequence data to registers.
  1082. * @param AddrSel Register address
  1083. * @param pBuf Pointer buffer to write data
  1084. * @param len Data length
  1085. */
  1086. void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
  1087. /////////////////////////////////
  1088. // Common Register IO function //
  1089. /////////////////////////////////
  1090. /**
  1091. * @ingroup Common_register_access_function_W5200
  1092. * @brief Set Mode Register
  1093. * @param (uint8_t)mr The value to be set.
  1094. * @sa getMR()
  1095. */
  1096. #if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)
  1097. #define setMR(mr) WIZCHIP_WRITE(MR,mr)
  1098. #else
  1099. #define setMR(mr) (*((uint8_t*)MR) = mr)
  1100. #endif
  1101. /**
  1102. * @ingroup Common_register_access_function_W5200
  1103. * @brief Get @ref MR.
  1104. * @return uint8_t. The value of Mode register.
  1105. * @sa setMR()
  1106. */
  1107. #if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)
  1108. #define getMR() WIZCHIP_READ(MR)
  1109. #else
  1110. #define getMR() (*(uint8_t*)MR)
  1111. #endif
  1112. /**
  1113. * @ingroup Common_register_access_function_W5200
  1114. * @brief Set @ref GAR.
  1115. * @param (uint8_t*)gar Pointer variable to set gateway IP address. It should be allocated 4 bytes.
  1116. * @sa getGAR()
  1117. */
  1118. #define setGAR(gar) \
  1119. WIZCHIP_WRITE_BUF(GAR,gar,4)
  1120. /**
  1121. * @ingroup Common_register_access_function_W5200
  1122. * @brief Get @ref GAR.
  1123. * @param (uint8_t*)gar Pointer variable to get gateway IP address. It should be allocated 4 bytes.
  1124. * @sa setGAR()
  1125. */
  1126. #define getGAR(gar) \
  1127. WIZCHIP_READ_BUF(GAR,gar,4)
  1128. /**
  1129. * @ingroup Common_register_access_function_W5200
  1130. * @brief Set @ref SUBR.
  1131. * @param (uint8_t*)subr Pointer variable to set subnet mask address. It should be allocated 4 bytes.
  1132. * @note If subr is null pointer, set the backup subnet to SUBR. \n
  1133. * If subr is 0.0.0.0, back up SUBR and clear it. \n
  1134. * Otherwize, set subr to SUBR
  1135. * @sa getSUBR()
  1136. */
  1137. #define setSUBR(subr) \
  1138. WIZCHIP_WRITE_BUF(SUBR, subr,4)
  1139. /**
  1140. * @ingroup Common_register_access_function_W5200
  1141. * @brief Get @ref SUBR.
  1142. * @param (uint8_t*)subr Pointer variable to get subnet mask address. It should be allocated 4 bytes.
  1143. * @sa setSUBR()
  1144. */
  1145. #define getSUBR(subr) \
  1146. WIZCHIP_READ_BUF(SUBR, subr, 4)
  1147. /**
  1148. * @ingroup Common_register_access_function_W5200
  1149. * @brief Set @ref SHAR.
  1150. * @param (uint8_t*)shar Pointer variable to set local MAC address. It should be allocated 6 bytes.
  1151. * @sa getSHAR()
  1152. */
  1153. #define setSHAR(shar) \
  1154. WIZCHIP_WRITE_BUF(SHAR, shar, 6)
  1155. /**
  1156. * @ingroup Common_register_access_function_W5200
  1157. * @brief Get @ref SHAR.
  1158. * @param (uint8_t*)shar Pointer variable to get local MAC address. It should be allocated 6 bytes.
  1159. * @sa setSHAR()
  1160. */
  1161. #define getSHAR(shar) \
  1162. WIZCHIP_READ_BUF(SHAR, shar, 6)
  1163. /**
  1164. * @ingroup Common_register_access_function_W5200
  1165. * @brief Set @ref SIPR.
  1166. * @param (uint8_t*)sipr Pointer variable to set local IP address. It should be allocated 4 bytes.
  1167. * @sa getSIPR()
  1168. */
  1169. #define setSIPR(sipr) \
  1170. WIZCHIP_WRITE_BUF(SIPR, sipr, 4)
  1171. /**
  1172. * @ingroup Common_register_access_function_W5200
  1173. * @brief Get @ref SIPR.
  1174. * @param (uint8_t*)sipr Pointer variable to get local IP address. It should be allocated 4 bytes.
  1175. * @sa setSIPR()
  1176. */
  1177. #define getSIPR(sipr) \
  1178. WIZCHIP_READ_BUF(SIPR, sipr, 4)
  1179. /**
  1180. * @ingroup Common_register_access_function_W5200
  1181. * @brief Set \ref IR register
  1182. * @param (uint8_t)ir Value to set \ref IR register.
  1183. * @sa getIR()
  1184. */
  1185. #define setIR(ir) \
  1186. WIZCHIP_WRITE(IR, (ir & 0xA0))
  1187. /**
  1188. * @ingroup Common_register_access_function_W5200
  1189. * @brief Get \ref IR register
  1190. * @return uint8_t. Value of \ref IR register.
  1191. * @sa setIR()
  1192. */
  1193. #define getIR() \
  1194. (WIZCHIP_READ(IR) & 0xA0)
  1195. /**
  1196. * @ingroup Common_register_access_function_W5200
  1197. * @brief Set \ref IMR2 register
  1198. * @param (uint8_t)imr Value to set @ref IMR2 register.
  1199. * @sa getIMR()
  1200. */
  1201. //M20150410 : Replace _IMR_ with IMR2 for integrating with ioLibrary
  1202. /*
  1203. #define setIMR(imr) \
  1204. WIZCHIP_WRITE(_IMR_, imr)
  1205. */
  1206. #define setIMR(imr) \
  1207. WIZCHIP_WRITE(IMR2, imr & 0xA0)
  1208. /**
  1209. * @ingroup Common_register_access_function_W5200
  1210. * @brief Get \ref IMR2 register
  1211. * @return uint8_t. Value of @ref IMR2 register.
  1212. * @sa setIMR()
  1213. */
  1214. //M20150410 : Replace _IMR_ with IMR2 for integrating with ioLibrary
  1215. /*
  1216. #define getIMR() \
  1217. WIZCHIP_READ(_IMR_)
  1218. */
  1219. #define getIMR() \
  1220. (WIZCHIP_READ(IMR2) & 0xA0)
  1221. /**
  1222. * @ingroup Common_register_access_function_W5200
  1223. * @brief Set \ref _RTR_ register
  1224. * @param (uint16_t)rtr Value to set @ref _RTR_ register.
  1225. * @sa getRTR()
  1226. */
  1227. #define setRTR(rtr) {\
  1228. WIZCHIP_WRITE(_RTR_, (uint8_t)(rtr >> 8)); \
  1229. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_RTR_,1), (uint8_t) rtr); \
  1230. }
  1231. /**
  1232. * @ingroup Common_register_access_function_W5200
  1233. * @brief Get \ref _RTR_ register
  1234. * @return uint16_t. Value of @ref _RTR_ register.
  1235. * @sa setRTR()
  1236. */
  1237. #define getRTR() \
  1238. (((uint16_t)WIZCHIP_READ(_RTR_) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_RTR_,1)))
  1239. /**
  1240. * @ingroup Common_register_access_function_W5200
  1241. * @brief Set \ref _RCR_ register
  1242. * @param (uint8_t)rcr Value to set @ref _RCR_ register.
  1243. * @sa getRCR()
  1244. */
  1245. #define setRCR(rcr) \
  1246. WIZCHIP_WRITE(_RCR_, rcr)
  1247. /**
  1248. * @ingroup Common_register_access_function_W5200
  1249. * @brief Get \ref _RCR_ register
  1250. * @return uint8_t. Value of @ref _RCR_ register.
  1251. * @sa setRCR()
  1252. */
  1253. #define getRCR() \
  1254. WIZCHIP_READ(_RCR_)
  1255. /**
  1256. * @ingroup Common_register_access_function_W5200
  1257. * @brief Get \ref PATR register
  1258. * @return uint16_t. Value to set \ref PATR register
  1259. */
  1260. #define getPATR() \
  1261. (((uint16_t)WIZCHIP_READ(PATR) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(PATR,1)))
  1262. /**
  1263. * @ingroup Common_register_access_function_W5200
  1264. * @brief Get \ref PPPALGO register
  1265. * @return uint8_t. Value to set \ref PPPALGO register
  1266. */
  1267. #define getPPPALGO() \
  1268. WIZCHIP_READ(PPPALGO)
  1269. /**
  1270. * @ingroup Common_register_access_function_W5200
  1271. * @brief Get \ref VERSIONR register
  1272. * @return uint8_t. Value to set \ref VERSIONR register
  1273. */
  1274. #define getVERSIONR() \
  1275. WIZCHIP_READ(VERSIONR)
  1276. /**
  1277. * @ingroup Common_register_access_function_W5200
  1278. * @brief Set \ref PTIMER register
  1279. * @param (uint8_t)ptimer Value to set \ref PTIMER register.
  1280. * @sa getPTIMER()
  1281. */
  1282. #define setPTIMER(ptimer) \
  1283. WIZCHIP_WRITE(PTIMER, ptimer)
  1284. /**
  1285. * @ingroup Common_register_access_function_W5200
  1286. * @brief Get \ref PTIMER register
  1287. * @return uint8_t. Value of @ref PTIMER register.
  1288. * @sa setPTIMER()
  1289. */
  1290. #define getPTIMER() \
  1291. WIZCHIP_READ(PTIMER)
  1292. /**
  1293. * @ingroup Common_register_access_function_W5200
  1294. * @brief Set \ref PMAGIC register
  1295. * @param (uint8_t)pmagic Value to set @ref PMAGIC register.
  1296. * @sa getPMAGIC()
  1297. */
  1298. #define setPMAGIC(pmagic) \
  1299. WIZCHIP_WRITE(PMAGIC, pmagic)
  1300. /**
  1301. * @ingroup Common_register_access_function_W5200
  1302. * @brief Get \ref PMAGIC register
  1303. * @return uint8_t. Value of @ref PMAGIC register.
  1304. * @sa setPMAGIC()
  1305. */
  1306. #define getPMAGIC() \
  1307. WIZCHIP_READ(PMAGIC)
  1308. /**
  1309. * @ingroup Common_register_access_function_W5200
  1310. * @brief Set @ref INTLEVEL register
  1311. * @param (uint16_t)intlevel Value to set @ref INTLEVEL register.
  1312. * @sa getINTLEVEL()
  1313. */
  1314. #define setINTLEVEL(intlevel) {\
  1315. WIZCHIP_WRITE(INTLEVEL, (uint8_t)(intlevel >> 8)); \
  1316. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(INTLEVEL,1), (uint8_t) intlevel); \
  1317. }
  1318. /**
  1319. * @ingroup Common_register_access_function_W5200
  1320. * @brief Get @ref INTLEVEL register
  1321. * @return uint16_t. Value of @ref INTLEVEL register.
  1322. * @sa setINTLEVEL()
  1323. */
  1324. #define getINTLEVEL() \
  1325. (((uint16_t)WIZCHIP_READ(INTLEVEL) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(INTLEVEL,1)))
  1326. /**
  1327. * @ingroup Common_register_access_function_W5200
  1328. * @brief Set \ref IR2 register
  1329. * @param (uint8_t)ir2 Value to set \ref IR2 register.
  1330. * @sa getIR2()
  1331. */
  1332. #define setIR2(ir2) \
  1333. WIZCHIP_WRITE(IR2, ir2)
  1334. #define setSIR(ir2) setIR2(ir2)
  1335. /**
  1336. * @ingroup Common_register_access_function_W5200
  1337. * @brief Get \ref IR2 register
  1338. * @return uint8_t. Value of \ref IR2 register.
  1339. * @sa setIR2()
  1340. */
  1341. #define getIR2() \
  1342. WIZCHIP_READ(IR2)
  1343. #define getSIR() getIR2()
  1344. /**
  1345. * @ingroup Common_register_access_function_W5200
  1346. * @brief Get \ref PHYSTATUS register
  1347. * @return uint8_t. Value to set \ref PHYSTATUS register.
  1348. */
  1349. #define getPHYSTATUS() \
  1350. WIZCHIP_READ(PHYSTATUS)
  1351. /**
  1352. * @ingroup Common_register_access_function_W5200
  1353. * @brief Set \ref _IMR_ register
  1354. * @param (uint8_t)imr2 Value to set \ref IMR2 register.
  1355. * @sa getIMR2()
  1356. * @note If possible, Don't use this function. Instead, Use setSIMR() for compatible with ioLibrary.
  1357. */
  1358. //M20150410 : Replace IMR2 with _IMR_ for integrating with ioLibrary
  1359. /*
  1360. #define setIMR2(imr2) \
  1361. WIZCHIP_WRITE(IMR2, (imr2 & 0xA0))
  1362. */
  1363. #define setIMR2(imr2) \
  1364. WIZCHIP_WRITE(_IMR_, imr2)
  1365. #define setSIMR(imr2) setIMR2(imr2)
  1366. /**
  1367. * @ingroup Common_register_access_function_W5200
  1368. * @brief Get \ref _IMR_ register
  1369. * @return uint8_t. Value of \ref IMR2 register.
  1370. * @sa setIMR2()
  1371. */
  1372. //M20150410 : Replace IMR2 with _IMR_ for integrating with ioLibrary
  1373. /*
  1374. #define getIMR2() \
  1375. (WIZCHIP_READ(IMR2) & 0xA0)
  1376. */
  1377. #define getIMR2() \
  1378. WIZCHIP_READ(_IMR_)
  1379. #define getSIMR() getIMR2()
  1380. ///////////////////////////////////
  1381. // Socket N register I/O function //
  1382. ///////////////////////////////////
  1383. /**
  1384. * @ingroup Socket_register_access_function_W5200
  1385. * @brief Set @ref Sn_MR register
  1386. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b> expect <b>bit 4</b>.
  1387. * @param mr Value to set @ref Sn_MR
  1388. * @sa getSn_MR()
  1389. */
  1390. #define setSn_MR(sn, mr) \
  1391. WIZCHIP_WRITE(Sn_MR(sn),mr)
  1392. /**
  1393. * @ingroup Socket_register_access_function_W5200
  1394. * @brief Get @ref Sn_MR register
  1395. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b> expect <b>bit 4</b>.
  1396. * @return Value of @ref Sn_MR.
  1397. * @sa setSn_MR()
  1398. */
  1399. #define getSn_MR(sn) \
  1400. WIZCHIP_READ(Sn_MR(sn))
  1401. /**
  1402. * @ingroup Socket_register_access_function_W5200
  1403. * @brief Set @ref Sn_CR register
  1404. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1405. * @param (uint8_t)cr Value to set @ref Sn_CR
  1406. * @sa getSn_CR()
  1407. */
  1408. #define setSn_CR(sn, cr) \
  1409. WIZCHIP_WRITE(Sn_CR(sn), cr)
  1410. /**
  1411. * @ingroup Socket_register_access_function_W5200
  1412. * @brief Get @ref Sn_CR register
  1413. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1414. * @return uint8_t. Value of @ref Sn_CR.
  1415. * @sa setSn_CR()
  1416. */
  1417. #define getSn_CR(sn) \
  1418. WIZCHIP_READ(Sn_CR(sn))
  1419. /**
  1420. * @ingroup Socket_register_access_function_W5200
  1421. * @brief Set @ref Sn_IR register
  1422. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1423. * @param (uint8_t)ir Value to set @ref Sn_IR
  1424. * @sa getSn_IR()
  1425. */
  1426. #define setSn_IR(sn, ir) \
  1427. WIZCHIP_WRITE(Sn_IR(sn), ir)
  1428. /**
  1429. * @ingroup Socket_register_access_function_W5200
  1430. * @brief Get @ref Sn_IR register
  1431. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1432. * @return uint8_t. Value of @ref Sn_IR.
  1433. * @sa setSn_IR()
  1434. */
  1435. #define getSn_IR(sn) \
  1436. WIZCHIP_READ(Sn_IR(sn))
  1437. /**
  1438. * @ingroup Socket_register_access_function_W5200
  1439. * @brief Set @ref Sn_IMR register
  1440. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1441. * @param (uint8_t)imr Value to set @ref Sn_IMR
  1442. * @sa getSn_IMR()
  1443. */
  1444. #define setSn_IMR(sn, imr) \
  1445. WIZCHIP_WRITE(Sn_IMR(sn), imr)
  1446. /**
  1447. * @ingroup Socket_register_access_function_W5200
  1448. * @brief Get @ref Sn_IMR register
  1449. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1450. * @return uint8_t. Value of @ref Sn_IMR.
  1451. * @sa setSn_IMR()
  1452. */
  1453. #define getSn_IMR(sn) \
  1454. WIZCHIP_READ(Sn_IMR(sn))
  1455. /**
  1456. * @ingroup Socket_register_access_function_W5200
  1457. * @brief Get @ref Sn_SR register
  1458. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1459. * @return uint8_t. Value of @ref Sn_SR.
  1460. */
  1461. #define getSn_SR(sn) \
  1462. WIZCHIP_READ(Sn_SR(sn))
  1463. /**
  1464. * @ingroup Socket_register_access_function_W5200
  1465. * @brief Set @ref Sn_PORT register
  1466. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1467. * @param (uint16_t)port Value to set @ref Sn_PORT.
  1468. * @sa getSn_PORT()
  1469. */
  1470. #define setSn_PORT(sn, port) { \
  1471. WIZCHIP_WRITE(Sn_PORT(sn), (uint8_t)(port >> 8)); \
  1472. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1), (uint8_t) port); \
  1473. }
  1474. /**
  1475. * @ingroup Socket_register_access_function_W5200
  1476. * @brief Get @ref Sn_PORT register
  1477. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1478. * @return uint16_t. Value of @ref Sn_PORT.
  1479. * @sa setSn_PORT()
  1480. */
  1481. #define getSn_PORT(sn) \
  1482. (((uint16_t)WIZCHIP_READ(Sn_PORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1)))
  1483. /**
  1484. * @ingroup Socket_register_access_function_W5200
  1485. * @brief Set @ref Sn_DHAR register
  1486. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1487. * @param (uint8_t*)dhar Pointer variable to set socket n destination hardware address. It should be allocated 6 bytes.
  1488. * @sa getSn_DHAR()
  1489. */
  1490. #define setSn_DHAR(sn, dhar) \
  1491. WIZCHIP_WRITE_BUF(Sn_DHAR(sn), dhar, 6)
  1492. /**
  1493. * @ingroup Socket_register_access_function_W5200
  1494. * @brief Get @ref Sn_DHAR register
  1495. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1496. * @param (uint8_t*)dhar Pointer variable to get socket n destination hardware address. It should be allocated 6 bytes.
  1497. * @sa setSn_DHAR()
  1498. */
  1499. #define getSn_DHAR(sn, dhar) \
  1500. WIZCHIP_READ_BUF(Sn_DHAR(sn), dhar, 6)
  1501. /**
  1502. * @ingroup Socket_register_access_function_W5200
  1503. * @brief Set @ref Sn_DIPR register
  1504. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1505. * @param (uint8_t*)dipr Pointer variable to set socket n destination IP address. It should be allocated 4 bytes.
  1506. * @sa getSn_DIPR()
  1507. */
  1508. #define setSn_DIPR(sn, dipr) \
  1509. WIZCHIP_WRITE_BUF(Sn_DIPR(sn), dipr, 4)
  1510. /**
  1511. * @ingroup Socket_register_access_function_W5200
  1512. * @brief Get @ref Sn_DIPR register
  1513. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1514. * @param (uint8_t*)dipr Pointer variable to get socket n destination IP address. It should be allocated 4 bytes.
  1515. * @sa SetSn_DIPR()
  1516. */
  1517. #define getSn_DIPR(sn, dipr) \
  1518. WIZCHIP_READ_BUF(Sn_DIPR(sn), dipr, 4)
  1519. /**
  1520. * @ingroup Socket_register_access_function_W5200
  1521. * @brief Set @ref Sn_DPORT register
  1522. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1523. * @param (uint16_t)dport Value to set @ref Sn_DPORT
  1524. * @sa getSn_DPORT()
  1525. */
  1526. #define setSn_DPORT(sn, dport) { \
  1527. WIZCHIP_WRITE(Sn_DPORT(sn), (uint8_t) (dport>>8)); \
  1528. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1), (uint8_t) dport); \
  1529. }
  1530. /**
  1531. * @ingroup Socket_register_access_function_W5200
  1532. * @brief Get @ref Sn_DPORT register
  1533. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1534. * @return uint16_t. Value of @ref Sn_DPORT.
  1535. * @sa setSn_DPORT()
  1536. */
  1537. #define getSn_DPORT(sn) \
  1538. (((uint16_t)WIZCHIP_READ(Sn_DPORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1)))
  1539. /**
  1540. * @ingroup Socket_register_access_function_W5200
  1541. * @brief Set @ref Sn_MSSR register
  1542. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1543. * @param (uint16_t)mss Value to set @ref Sn_MSSR
  1544. * @sa setSn_MSSR()
  1545. */
  1546. #define setSn_MSSR(sn, mss) { \
  1547. WIZCHIP_WRITE(Sn_MSSR(sn), (uint8_t)(mss>>8)); \
  1548. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1), (uint8_t) mss); \
  1549. }
  1550. /**
  1551. * @ingroup Socket_register_access_function_W5200
  1552. * @brief Get @ref Sn_MSSR register
  1553. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1554. * @return uint16_t. Value of @ref Sn_MSSR.
  1555. * @sa setSn_MSSR()
  1556. */
  1557. #define getSn_MSSR(sn) \
  1558. (((uint16_t)WIZCHIP_READ(Sn_MSSR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1)))
  1559. /**
  1560. * @ingroup Socket_register_access_function_W5200
  1561. * @brief Set @ref Sn_PROTO register
  1562. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1563. * @param (uint8_t)proto Value to set \ref Sn_PROTO
  1564. * @sa getSn_PROTO()
  1565. */
  1566. //M20150601 : Fixed Wrong Register address
  1567. /*
  1568. #define setSn_PROTO(sn, proto) \
  1569. WIZCHIP_WRITE(Sn_TOS(sn), tos)
  1570. */
  1571. #define setSn_PROTO(sn, proto) \
  1572. WIZCHIP_WRITE(Sn_PROTO(sn), proto)
  1573. /**
  1574. * @ingroup Socket_register_access_function_W5200
  1575. * @brief Get @ref Sn_PROTO register
  1576. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1577. * @return uint8_t. Value of @ref Sn_PROTO.
  1578. * @sa setSn_PROTO()
  1579. */
  1580. //M20150601 : Fixed Wrong Register address
  1581. /*
  1582. #define getSn_PROTO(sn) \
  1583. WIZCHIP_READ(Sn_TOS(sn))
  1584. */
  1585. #define getSn_PROTO(sn) \
  1586. WIZCHIP_READ(Sn_PROTO(sn))
  1587. /**
  1588. * @ingroup Socket_register_access_function_W5200
  1589. * @brief Set @ref Sn_TOS register
  1590. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1591. * @param (uint8_t)tos Value to set @ref Sn_TOS
  1592. * @sa getSn_TOS()
  1593. */
  1594. #define setSn_TOS(sn, tos) \
  1595. WIZCHIP_WRITE(Sn_TOS(sn), tos)
  1596. /**
  1597. * @ingroup Socket_register_access_function_W5200
  1598. * @brief Get @ref Sn_TOS register
  1599. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_ </b>.
  1600. * @return uint8_t. Value of Sn_TOS.
  1601. * @sa setSn_TOS()
  1602. */
  1603. #define getSn_TOS(sn) \
  1604. WIZCHIP_READ(Sn_TOS(sn))
  1605. /**
  1606. * @ingroup Socket_register_access_function_W5200
  1607. * @brief Set @ref Sn_TTL register
  1608. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_ </b>.
  1609. * @param (uint8_t)ttl Value to set @ref Sn_TTL
  1610. * @sa getSn_TTL()
  1611. */
  1612. #define setSn_TTL(sn, ttl) \
  1613. WIZCHIP_WRITE(Sn_TTL(sn), ttl)
  1614. /**
  1615. * @ingroup Socket_register_access_function_W5200
  1616. * @brief Get @ref Sn_TTL register
  1617. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_ </b>.
  1618. * @return uint8_t. Value of @ref Sn_TTL.
  1619. * @sa setSn_TTL()
  1620. */
  1621. #define getSn_TTL(sn) \
  1622. WIZCHIP_READ(Sn_TTL(sn))
  1623. /**
  1624. * @ingroup Socket_register_access_function_W5200
  1625. * @brief Set @ref Sn_RXMEM_SIZE register
  1626. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_ </b>.
  1627. * @param (uint8_t)rxmemsize Value to set \ref Sn_RXMEM_SIZE
  1628. * @sa getSn_RXMEM_SIZE()
  1629. */
  1630. #define setSn_RXMEM_SIZE(sn, rxmemsize) \
  1631. WIZCHIP_WRITE(Sn_RXMEM_SIZE(sn),rxmemsize)
  1632. #define setSn_RXBUF_SIZE(sn,rxmemsize) setSn_RXMEM_SIZE(sn,rxmemsize)
  1633. /**
  1634. * @ingroup Socket_register_access_function_W5200
  1635. * @brief Get @ref Sn_RXMEM_SIZE register
  1636. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1637. * @return uint8_t. Value of @ref Sn_RXMEM.
  1638. * @sa setSn_RXMEM_SIZE()
  1639. */
  1640. #define getSn_RXMEM_SIZE(sn) \
  1641. WIZCHIP_READ(Sn_RXMEM_SIZE(sn))
  1642. #define getSn_RXBUF_SIZE(sn) getSn_RXMEM_SIZE(sn)
  1643. /**
  1644. * @ingroup Socket_register_access_function_W5200
  1645. * @brief Set @ref Sn_TXMEM_SIZE register
  1646. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1647. * @param (uint8_t)txmemsize Value to set \ref Sn_TXMEM_SIZE
  1648. * @sa getSn_TXMEM_SIZE()
  1649. */
  1650. #define setSn_TXMEM_SIZE(sn, txmemsize) \
  1651. WIZCHIP_WRITE(Sn_TXMEM_SIZE(sn), txmemsize)
  1652. #define setSn_TXBUF_SIZE(sn, txmemsize) setSn_TXMEM_SIZE(sn,txmemsize)
  1653. /**
  1654. * @ingroup Socket_register_access_function_W5200
  1655. * @brief Get @ref Sn_TXMEM_SIZE register
  1656. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1657. * @return uint8_t. Value of @ref Sn_TXMEM_SIZE.
  1658. * @sa setSn_TXMEM_SIZE()
  1659. */
  1660. #define getSn_TXMEM_SIZE(sn) \
  1661. WIZCHIP_READ(Sn_TXMEM_SIZE(sn))
  1662. #define getSn_TXBUF_SIZE(sn) getSn_TXMEM_SIZE(sn)
  1663. /**
  1664. * @ingroup Socket_register_access_function_W5200
  1665. * @brief Get @ref Sn_TX_FSR register
  1666. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1667. * @return uint16_t. Value of @ref Sn_TX_FSR.
  1668. */
  1669. uint16_t getSn_TX_FSR(uint8_t sn);
  1670. /**
  1671. * @ingroup Socket_register_access_function_W5200
  1672. * @brief Get @ref Sn_TX_RD register
  1673. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1674. * @return uint16_t. Value of @ref Sn_TX_RD.
  1675. */
  1676. #define getSn_TX_RD(sn) \
  1677. (((uint16_t)WIZCHIP_READ(Sn_TX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_RD(sn),1)))
  1678. /**
  1679. * @ingroup Socket_register_access_function_W5200
  1680. * @brief Set @ref Sn_TX_WR register
  1681. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1682. * @param (uint16_t)txwr Value to set @ref Sn_TX_WR
  1683. * @sa GetSn_TX_WR()
  1684. */
  1685. #define setSn_TX_WR(sn, txwr) { \
  1686. WIZCHIP_WRITE(Sn_TX_WR(sn), (uint8_t)(txwr>>8)); \
  1687. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1), (uint8_t) txwr); \
  1688. }
  1689. /**
  1690. * @ingroup Socket_register_access_function_W5200
  1691. * @brief Get @ref Sn_TX_WR register
  1692. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1693. * @return uint16_t. Value of @ref Sn_TX_WR.
  1694. * @sa setSn_TX_WR()
  1695. */
  1696. #define getSn_TX_WR(sn) \
  1697. (((uint16_t)WIZCHIP_READ(Sn_TX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1)))
  1698. /**
  1699. * @ingroup Socket_register_access_function_W5200
  1700. * @brief Get @ref Sn_RX_RSR register
  1701. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1702. * @return uint16_t. Value of @ref Sn_RX_RSR.
  1703. */
  1704. uint16_t getSn_RX_RSR(uint8_t sn);
  1705. /**
  1706. * @ingroup Socket_register_access_function_W5200
  1707. * @brief Set @ref Sn_RX_RD register
  1708. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1709. * @param (uint16_t)rxrd Value to set @ref Sn_RX_RD
  1710. * @sa getSn_RX_RD()
  1711. */
  1712. #define setSn_RX_RD(sn, rxrd) { \
  1713. WIZCHIP_WRITE(Sn_RX_RD(sn), (uint8_t)(rxrd>>8)); \
  1714. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1), (uint8_t) rxrd); \
  1715. }
  1716. /**
  1717. * @ingroup Socket_register_access_function_W5200
  1718. * @brief Get @ref Sn_RX_RD register
  1719. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1720. * @return uint16_t. Value of @ref Sn_RX_RD.
  1721. * @sa setSn_RX_RD()
  1722. */
  1723. #define getSn_RX_RD(sn) \
  1724. (((uint16_t)WIZCHIP_READ(Sn_RX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1)))
  1725. /**
  1726. * @ingroup Socket_register_access_function_W5200
  1727. * @brief Set @ref Sn_RX_WR register
  1728. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1729. * @param (uint16_t)rxwr Value to set \ref Sn_RX_WR
  1730. * @sa getSn_RX_WR()
  1731. */
  1732. #define setSn_RX_WR(sn, rxwr) { \
  1733. WIZCHIP_WRITE(Sn_RX_WR(sn), (uint8_t)(rxwr>>8)); \
  1734. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RX_WR(sn),1), (uint8_t) rxwr); \
  1735. }
  1736. /**
  1737. * @ingroup Socket_register_access_function_W5200
  1738. * @brief Get @ref Sn_RX_WR register
  1739. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1740. * @return uint16_t. Value of @ref Sn_RX_WR.
  1741. */
  1742. #define getSn_RX_WR(sn) \
  1743. (((uint16_t)WIZCHIP_READ(Sn_RX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_WR(sn),1)))
  1744. /**
  1745. * @ingroup Socket_register_access_function_W5200
  1746. * @brief Set @ref Sn_IMR register
  1747. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1748. * @param (uint8_t)imr Value to set \ref Sn_IMR
  1749. * @sa getSn_IMR()
  1750. */
  1751. #define setSn_IMR(sn ,imr) \
  1752. WIZCHIP_WRITE(Sn_IMR(sn), imr)
  1753. /**
  1754. * @ingroup Socket_register_access_function_W5200
  1755. * @brief Get @ref Sn_IMR register
  1756. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1757. * @return uint8_t. Value of @ref Sn_IMR.
  1758. * @sa setSn_IMR()
  1759. */
  1760. #define getSn_IMR(sn) \
  1761. WIZCHIP_READ(Sn_IMR(sn))
  1762. /**
  1763. * @ingroup Socket_register_access_function_W5200
  1764. * @brief Set @ref Sn_FRAG register
  1765. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1766. * @param (uint16_t)frag Value to set \ref Sn_FRAG
  1767. * @sa getSn_FRAG()
  1768. */
  1769. #define setSn_FRAG(sn, frag) { \
  1770. WIZCHIP_WRITE(Sn_FRAG(sn), (uint8_t)(frag >>8)); \
  1771. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_FRAG(sn),1), (uint8_t) frag); \
  1772. }
  1773. /**
  1774. * @ingroup Socket_register_access_function_W5200
  1775. * @brief Get @ref Sn_FRAG register
  1776. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1777. * @return uint16_t. Value of @ref Sn_FRAG.
  1778. * @sa setSn_FRAG()
  1779. */
  1780. #define getSn_FRAG(sn) \
  1781. (((uint16_t)WIZCHIP_READ(Sn_FRAG(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_FRAG(sn),1)))
  1782. /**
  1783. * @ingroup Socket_register_access_function_W5200
  1784. * @brief Get the max RX buffer size of socket sn
  1785. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1786. * @return uint16_t. Max buffer size
  1787. */
  1788. #define getSn_RxMAX(sn) \
  1789. ((uint16_t)getSn_RXMEM_SIZE(sn) << 10)
  1790. /**
  1791. * @ingroup Socket_register_access_function_W5200
  1792. * @brief Get the max TX buffer size of socket sn
  1793. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1794. * @return uint16_t. Max buffer size
  1795. */
  1796. #define getSn_TxMAX(sn) \
  1797. ((uint16_t)getSn_TXMEM_SIZE(sn) << 10)
  1798. /**
  1799. * @ingroup Socket_register_access_function_W5200
  1800. * @brief Get the mask of socket sn RX buffer.
  1801. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1802. * @return uint16_t. Mask value
  1803. */
  1804. #define getSn_RxMASK(sn) \
  1805. ((uint16_t)getSn_RxMAX(sn) - 1)
  1806. /**
  1807. * @ingroup Socket_register_access_function_W5200
  1808. * @brief Get the mask of socket sn TX buffer
  1809. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1810. * @return uint16_t. Mask value
  1811. */
  1812. #define getSn_TxMASK(sn) \
  1813. ((uint16_t)getSn_TxMAX(sn) - 1)
  1814. /**
  1815. * @ingroup Socket_register_access_function_W5200
  1816. * @brief Get the base address of socket sn RX buffer.
  1817. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1818. * @return uint16_t. Value of Socket n RX buffer base address.
  1819. */
  1820. uint16_t getSn_RxBASE(uint8_t sn);
  1821. /**
  1822. * @ingroup Socket_register_access_function_W5200
  1823. * @brief Get the base address of socket sn TX buffer.
  1824. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1825. * @return uint16_t. Value of Socket n TX buffer base address.
  1826. */
  1827. uint16_t getSn_TxBASE(uint8_t sn);
  1828. /////////////////////////////////////
  1829. // Sn_TXBUF & Sn_RXBUF IO function //
  1830. /////////////////////////////////////
  1831. /**
  1832. * @ingroup Basic_IO_function_W5200
  1833. * @brief It copies data to internal TX memory
  1834. *
  1835. * @details This function reads the Tx write pointer register and after that,
  1836. * it copies the <i>wizdata(pointer buffer)</i> of the length of <i>len(variable)</i> bytes to internal TX memory
  1837. * and updates the Tx write pointer register.
  1838. * This function is being called by send() and sendto() function also.
  1839. *
  1840. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1841. * @param wizdata Pointer buffer to write data
  1842. * @param len Data length
  1843. * @sa wiz_recv_data()
  1844. */
  1845. void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len);
  1846. /**
  1847. * @ingroup Basic_IO_function_W5200
  1848. * @brief It copies data to your buffer from internal RX memory
  1849. *
  1850. * @details This function read the Rx read pointer register and after that,
  1851. * it copies the received data from internal RX memory
  1852. * to <i>wizdata(pointer variable)</i> of the length of <i>len(variable)</i> bytes.
  1853. * This function is being called by recv() also.
  1854. *
  1855. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1856. * @param wizdata Pointer buffer to read data
  1857. * @param len Data length
  1858. * @sa wiz_send_data()
  1859. */
  1860. void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len);
  1861. /**
  1862. * @ingroup Basic_IO_function_W5200
  1863. * @brief It discard the received data in RX memory.
  1864. * @details It discards the data of the length of <i>len(variable)</i> bytes in internal RX memory.
  1865. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  1866. * @param len Data length
  1867. */
  1868. void wiz_recv_ignore(uint8_t sn, uint16_t len);
  1869. /// \cond DOXY_APPLY_CODE
  1870. #endif
  1871. /// \endcond
  1872. #ifdef __cplusplus
  1873. }
  1874. #endif
  1875. #endif //_W5200_H_