w5100.h 70 KB

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