w5200.h 75 KB

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