w5100s.h 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323
  1. //* ****************************************************************************
  2. //! \file w5100S.h
  3. //! \brief W5100S HAL Header File.
  4. //! \version 1.0.0
  5. //! \date 2018/03/29
  6. //! \par Revision history
  7. //! <2018/03/29> 1st Release
  8. //! \author Peter
  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 _W5100S_H_
  41. #define _W5100S_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_ == W5100S)
  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 _W5100S_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 _W5100S_IO_BASE_ 0x0000
  65. #elif (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)
  66. #define _W5100S_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 W5100S W5100S
  78. * @brief WHIZCHIP register defines and I/O functions of @b W5100S.
  79. *
  80. * - @ref WIZCHIP_register_W5100S: @ref Common_register_group_W5100S and @ref Socket_register_group_W5100S
  81. * - @ref WIZCHIP_IO_Functions_W5100S: @ref Basic_IO_function_W5100S, @ref Common_register_access_function_W5100S and @ref Special_function_W5100S
  82. */
  83. /**
  84. * @defgroup WIZCHIP_register_W5100S WIZCHIP register
  85. * @ingroup W5100S
  86. * @brief WIZCHIP register defines register group of <b> W5100S </b>.
  87. *
  88. * - \ref Common_register_group_W5100S : Common register group W5100S
  89. * - \ref Socket_register_group_W5100S : \c SOCKET n register group W5100S
  90. */
  91. /**
  92. * @defgroup WIZCHIP_IO_Functions_W5100S WIZCHIP I/O functions
  93. * @ingroup W5100S
  94. * @brief This supports the basic I/O functions for \ref WIZCHIP_register_W5100S.
  95. *
  96. * - <b> Basic I/O function </b> \n
  97. * WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF(), wiz_recv_data(), wiz_recv_ignore(), wiz_send_data() \n\n
  98. *
  99. * - \ref Common_register_group_W5100S <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_W5100S <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_W5100S Common register
  128. * @ingroup WIZCHIP_register_W5100S
  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_W5100S Socket register
  141. * @ingroup WIZCHIP_register_W5100S
  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_FRAGR : 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_W5100S Basic I/O function
  152. * @ingroup WIZCHIP_IO_Functions_W5100S
  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_W5100S Common register access functions
  157. * @ingroup WIZCHIP_IO_Functions_W5100S
  158. * @brief These are functions to access <b>common registers</b>.
  159. */
  160. /**
  161. * @defgroup Socket_register_access_function_W5100S Socket register access functions
  162. * @ingroup WIZCHIP_IO_Functions_W5100S
  163. * @brief These are functions to access <b>socket registers</b>.
  164. */
  165. /**
  166. * @defgroup Special_function_W5100S Special functions
  167. * @ingroup WIZCHIP_IO_Functions_W5100S
  168. * @brief These are special functions to access to the PHY
  169. */
  170. //-----------------------------------------------------------------------------------
  171. //----------------------------- W5100S Common Registers IOMAP -----------------------------
  172. /**
  173. * @ingroup Common_register_group_W5100S
  174. * @brief Mode Register address(R/W)\n
  175. * \ref MR is used for S/W reset, ping block mode, PPPoE mode and etc.
  176. * @details Each bit of \ref MR defined as follows.
  177. * <table>
  178. * <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>
  179. * <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>
  180. * </table>
  181. * - \ref MR_RST : Reset
  182. * - \ref MR_PB : Ping block
  183. * - \ref MR_PPPOE : PPPoE mode
  184. * - \ref MR_AI : Address Auto-Increment in Indirect Bus Interface
  185. * - \ref MR_IND : Indirect Bus Interface mode
  186. */
  187. #if _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_
  188. #define MR (_WIZCHIP_IO_BASE_ + (0x0000)) // Mode
  189. #else
  190. #define MR (_W5100S_IO_BASE_ + (0x0000)) // Mode
  191. #endif
  192. /**
  193. * @ingroup Common_register_group_W5100S
  194. * @brief Gateway IP Register address(R/W)
  195. * @details \ref GAR configures the default gateway address.
  196. */
  197. #define GAR (_W5100S_IO_BASE_ + (0x0001)) // GW Address
  198. /**
  199. * @ingroup Common_register_group_W5100S
  200. * @brief Subnet mask Register address(R/W)
  201. * @details \ref SUBR configures the subnet mask address.
  202. */
  203. #define SUBR (_W5100S_IO_BASE_ + (0x0005)) // SN Mask Address
  204. /**
  205. * @ingroup Common_register_group_W5100S
  206. * @brief Source MAC Register address(R/W)
  207. * @details \ref SHAR configures the source hardware address.
  208. */
  209. #define SHAR (_W5100S_IO_BASE_ + (0x0009)) // Source Hardware Address
  210. /**
  211. * @ingroup Common_register_group_W5100S
  212. * @brief Source IP Register address(R/W)
  213. * @details \ref SIPR configures the source IP address.
  214. */
  215. #define SIPR (_W5100S_IO_BASE_ + (0x000F)) // Source IP Address
  216. // Reserved (_W5100S_IO_BASE_ + (0x0013))
  217. // Reserved (_W5100S_IO_BASE_ + (0x0014))
  218. /**
  219. * @ingroup Common_register_group_W5100S
  220. * @brief Interrupt Register(R/W)
  221. * @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.
  222. * If \ref IR is not equal to x00 INTn PIN is asserted to low until it is x00\n\n
  223. * Each bit of \ref IR defined as follows.
  224. * <table>
  225. * <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>
  226. * <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>
  227. * </table>
  228. * - \ref IR_CONFLICT : IP conflict
  229. * - \ref IR_UNREACH : Destination unreachable
  230. * - \ref IR_PPPoE : PPPoE connection close
  231. * - \ref IR_SOCK(3) : SOCKET 3 Interrupt
  232. * - \ref IR_SOCK(2) : SOCKET 2 Interrupt
  233. * - \ref IR_SOCK(1) : SOCKET 1 Interrupt
  234. * - \ref IR_SOCK(0) : SOCKET 0 Interrupt
  235. */
  236. #define IR (_W5100S_IO_BASE_ + (0x0015)) // Interrupt
  237. /**
  238. * @ingroup Common_register_group_W5100S
  239. * @brief Socket Interrupt Mask Register(R/W)
  240. * @details Each bit of \ref _IMR_ corresponds to each bit of \ref IR.
  241. * When a bit of \ref _IMR_ is and the corresponding bit of \ref IR is set, Interrupt will be issued.
  242. */
  243. #define _IMR_ (_W5100S_IO_BASE_ + (0x0016)) // Socket Interrupt Mask
  244. /**
  245. * @ingroup Common_register_group_W5100S
  246. * @brief Timeout register address( 1 is 100us )(R/W)
  247. * @details \ref _RTR_ configures the retransmission timeout period. The unit of timeout period is 100us and the default of \ref _RTR_ is x07D0or 000
  248. * And so the default timeout period is 200ms(100us X 2000). During the time configured by \ref _RTR_, W5100S waits for the peer response
  249. * to the packet that is transmitted by \ref Sn_CR (CONNECT, DISCON, CLOSE, SEND, SEND_MAC, SEND_KEEP command).
  250. * If the peer does not respond within the \ref _RTR_ time, W5100S retransmits the packet or issues timeout.
  251. */
  252. #define _RTR_ (_W5100S_IO_BASE_ + (0x0017)) // Retry Time
  253. /**
  254. * @ingroup Common_register_group_W5100S
  255. * @brief Retry count register(R/W)
  256. * @details \ref _RCR_ configures the number of time of retransmission.
  257. * When retransmission occurs as many as ref _RCR_+1 Timeout interrupt is issued (\ref Sn_IR_TIMEOUT = '1').
  258. */
  259. #define _RCR_ (_W5100S_IO_BASE_ + (0x0019)) // Retry Count
  260. /**
  261. * @ingroup Common_register_group_W5100S
  262. * @brief Receive Memory Size Register
  263. * @details \ref RMSR register configures RX bufffer Size of the SOCKET
  264. * The sum of the RX buffers can not exceed 8kB.
  265. * <table>
  266. * <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>
  267. * <tr> <td>S3-1</td> <td>S3-0</td> <td>S2-1</td> <td>S2-0</td> <td>S1-1</td> <td>S1-0</td> <td>S0-1</td> <td>S0-0</td> </tr>
  268. * </table>
  269. * <table>
  270. * <tr> <td>Memory Size</td><td>Sn-1</td><td>Sn-0</td> </tr>
  271. * <tr> <td>1KB</td><td>0</td><td>0</td> </tr>
  272. * <tr> <td>2KB</td><td>0</td><td>1</td> </tr>
  273. * <tr> <td>4KB</td><td>1</td><td>0</td> </tr>
  274. * <tr> <td>8KB</td><td>1</td><td>1</td> </tr>
  275. * </table>
  276. */
  277. #define RMSR (_W5100S_IO_BASE_ + (0x001A)) // Receive Memory Size
  278. /**
  279. * @ingroup Common_register_group_W5100S
  280. * @brief Transmit Memory Size Register
  281. * @details \ref TMSR register configures TX bufffer Size of the SOCKET
  282. * The sum of the TX buffers can not exceed 8kB.
  283. * <table>
  284. * <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>
  285. * <tr> <td>S3-1</td> <td>S3-0</td> <td>S2-1</td> <td>S2-0</td> <td>S1-1</td> <td>S1-0</td> <td>S0-1</td> <td>S0-0</td> </tr>
  286. * </table>
  287. * <table>
  288. * <tr> <td>Memory Size</td><td>Sn-1</td><td>Sn-0</td> </tr>
  289. * <tr> <td>1KB</td><td>0</td><td>0</td> </tr>
  290. * <tr> <td>2KB</td><td>0</td><td>1</td> </tr>
  291. * <tr> <td>4KB</td><td>1</td><td>0</td> </tr>
  292. * <tr> <td>8KB</td><td>1</td><td>1</td> </tr>
  293. * </table>
  294. */
  295. #define TMSR (_W5100S_IO_BASE_ + (0x001B)) // Transmit Memory Size
  296. /**
  297. * @ingroup Common_register_group_W5100S
  298. * @brief Interrupt register 2
  299. * @details \ref IR2 indicates the interrupt status.
  300. * Each bit of IR2 will be still until the bit will be written to by the host.
  301. * <table>
  302. * <tr> <td>7:1</td> <td>0</td> </tr>
  303. * <tr> <td>Reserved</td> <td>WOL</td> </tr>
  304. * </table>
  305. * - \ref IR2_WOL : WOL MAGIC PACKET Interrupt Mask
  306. */
  307. #define IR2 (_W5100S_IO_BASE_ + (0x0020))
  308. /**
  309. * @ingroup Common_register_group_W5100S
  310. * @brief Interrupt mask register 2
  311. * @details \ref IMR2 Each bit of IMR2 corresponds to each bit of IR2.
  312. * When a bit of IMR2 is and the corresponding bit of IR2 is set, Interrupt will be issued.
  313. */
  314. #define IMR2 (_W5100S_IO_BASE_ + (0x0021))
  315. /**
  316. * @ingroup Common_register_group_W5100S
  317. * @brief PPP LCP Request Timer register in PPPoE mode(R)
  318. * @details \ref PTIMER configures the time for sending LCP echo request. The unit of time is 25ms.
  319. */
  320. #define PTIMER (_W5100S_IO_BASE_ + (0x0028)) // PPP LCP RequestTimer
  321. /**
  322. * @ingroup Common_register_group_W5100S
  323. * @brief PPP LCP Magic number register in PPPoE mode(R)
  324. * @details \ref PMAGIC configures the 4bytes magic number to be used in LCP negotiation.
  325. */
  326. #define PMAGIC (_W5100S_IO_BASE_ + (0x0029)) // PPP LCP Magic number
  327. /**
  328. * @ingroup Common_register_group_W5100S
  329. * @brief Unreachable IP address register
  330. * @details \ref
  331. */
  332. #define UIPR (_W5100S_IO_BASE_ + (0x002A))
  333. /**
  334. * @ingroup Common_register_group_W5100S
  335. * @brief Unreachable Port register
  336. * @details \ref
  337. */
  338. #define UPORTR (_W5100S_IO_BASE_ + (0x002E))
  339. /* register for W5100S only */
  340. /*------------------------------------------ Common registers ------------------------------------------*/
  341. /**
  342. * @ingroup Common_register_group_W5100S
  343. * @brief MR2 Mode register 2
  344. * @details \reg
  345. */
  346. #define MR2 (_W5100S_IO_BASE_ + (0x0030))
  347. /**
  348. * @ingroup Common_register_group_W5100S
  349. * @brief Destination Hardware address in PPPoE
  350. * @details \reg
  351. */
  352. #define PHAR (_W5100S_IO_BASE_ + (0x0032))
  353. /**
  354. * @ingroup Common_register_group_W5100S
  355. * @brief Session ID in PPPoE
  356. * @details \reg
  357. */
  358. #define PSIDR (_W5100S_IO_BASE_ + (0x0038))
  359. /**
  360. * @ingroup Common_register_group_W5100S
  361. * @brief Maximum receive Unit in PPPoE
  362. * @details \reg
  363. */
  364. #define PMRUR (_W5100S_IO_BASE_ + (0x003A))
  365. /*------------------------------------------ PHY registers ------------------------------------------*/
  366. /**
  367. * @ingroup Common_register_group_W5100S
  368. * @brief PHY status register
  369. * @details \reg
  370. */
  371. #define PHYSR (_W5100S_IO_BASE_ + (0x003C))
  372. /**
  373. * @ingroup Common_register_group_W5100S
  374. * @brief PHY status register(hidden)
  375. * @details \reg
  376. */
  377. #define PHYSR1 (_W5100S_IO_BASE_ + (0x003D))
  378. /**
  379. * @ingroup Common_register_group_W5100S
  380. * @brief PHY Address value
  381. * @details \reg
  382. */
  383. #define PHYAR (_W5100S_IO_BASE_ + (0x003E))
  384. /**
  385. * @ingroup Common_register_group_W5100S
  386. * @brief PHY Register address
  387. * @details \reg
  388. */
  389. #define PHYRAR (_W5100S_IO_BASE_ + (0x003F))
  390. /**
  391. * @ingroup Common_register_group_W5100S
  392. * @brief PHY Data input register
  393. * @details \reg
  394. */
  395. #define PHYDIR (_W5100S_IO_BASE_ + (0x0040))
  396. /**
  397. * @ingroup Common_register_group_W5100S
  398. * @brief PHY data output register
  399. * @details \reg
  400. */
  401. #define PHYDOR (_W5100S_IO_BASE_ + (0x0042))
  402. /**
  403. * @ingroup Common_register_group_W5100S
  404. * @brief PHY Action register
  405. * @details \reg
  406. */
  407. #define PHYACR (_W5100S_IO_BASE_ + (0x0044))
  408. /**
  409. * @ingroup Common_register_group_W5100S
  410. * @brief PHY Division register
  411. * @details \reg
  412. */
  413. #define PHYDIVR (_W5100S_IO_BASE_ + (0x0045))
  414. /**
  415. * @ingroup Common_register_group_W5100S
  416. * @brief PHY Control register 0
  417. * @details \reg
  418. */
  419. #define PHYCR0 (_W5100S_IO_BASE_ + (0x0046))
  420. /**
  421. * @ingroup Common_register_group_W5100S
  422. * @brief PHY Control register 1
  423. * @details \reg
  424. */
  425. #define PHYCR1 (_W5100S_IO_BASE_ + (0x0047))
  426. /*------------------------------------------ Socket Less registers ------------------------------------------*/
  427. /**
  428. * @ingroup Common_register_group_W5100S
  429. * @brief Socket-less control register
  430. * @details \reg
  431. */
  432. #define SLCR (_W5100S_IO_BASE_ + (0x004C))
  433. /**
  434. * @ingroup Common_register_group_W5100S
  435. * @brief Socket-less retry time register
  436. * @details \reg
  437. */
  438. #define SLRTR (_W5100S_IO_BASE_ + (0x004D))
  439. /**
  440. * @ingroup Common_register_group_W5100S
  441. * @brief Socket-less retry count register
  442. * @details \reg
  443. */
  444. #define SLRCR (_W5100S_IO_BASE_ + (0x004F))
  445. /**
  446. * @ingroup Common_register_group_W5100S
  447. * @brief Socket-less peer IP address register
  448. * @details \reg
  449. */
  450. #define SLPIPR (_W5100S_IO_BASE_ + (0x0050))
  451. /**
  452. * @ingroup Common_register_group_W5100S
  453. * @brief Socket-less peer hardware address register
  454. * @details \reg
  455. */
  456. #define SLPHAR (_W5100S_IO_BASE_ + (0x0054))
  457. /**
  458. * @ingroup Common_register_group_W5100S
  459. * @brief Ping sequence number register
  460. * @details \reg
  461. */
  462. #define PINGSEQR (_W5100S_IO_BASE_ + (0x005A))
  463. /**
  464. * @ingroup Common_register_group_W5100S
  465. * @brief Ping ID register
  466. * @details \reg
  467. */
  468. #define PINGIDR (_W5100S_IO_BASE_ + (0x005C))
  469. /**
  470. * @ingroup Common_register_group_W5100S
  471. * @brief Socket-less interrupt mask register
  472. * @details \reg
  473. */
  474. #define SLIMR (_W5100S_IO_BASE_ + (0x005E))
  475. /**
  476. * @ingroup Common_register_group_W5100S
  477. * @brief Socket-less interrupt register
  478. * @details \reg
  479. */
  480. #define SLIR (_W5100S_IO_BASE_ + (0x005F))
  481. /**
  482. * @ingroup Common_register_group_W5100S
  483. * @brief DBGOUT(hidden)
  484. * @details \reg
  485. */
  486. #define DBGOUT (_W5100S_IO_BASE_ + (0x0060))
  487. /**
  488. * @ingroup Common_register_group_W5100S
  489. * @brief NICMAXCOLR(hidden)
  490. * @details \reg
  491. */
  492. #define NICMAXCOLR (_W5100S_IO_BASE_ + (0x0063))
  493. /*------------------------------------------ CFG registers ------------------------------------------*/
  494. /**
  495. * @ingroup Common_register_group_W5100S
  496. * @brief Chip Configuration locking register
  497. * @details \reg
  498. */
  499. #define CHIPLCKR (_W5100S_IO_BASE_ + (0x0070))
  500. /**
  501. * @ingroup Common_register_group_W5100S
  502. * @brief Network Configuration locking register
  503. * @details \reg
  504. */
  505. #define NETLCKR (_W5100S_IO_BASE_ + (0x0071))
  506. /**
  507. * @ingroup Common_register_group_W5100S
  508. * @brief PHY Configuration locking register
  509. * @details \reg
  510. */
  511. #define PHYLCKR (_W5100S_IO_BASE_ + (0x0072))
  512. /**
  513. * @ingroup Common_register_group_W5100S
  514. * @brief version register
  515. * @details \reg
  516. */
  517. #define VERR (_W5100S_IO_BASE_ + (0x0080))
  518. /**
  519. * @ingroup Common_register_group_W5100S
  520. * @brief Core 100us Counter register
  521. * @details \reg
  522. */
  523. #define TCNTR (_W5100S_IO_BASE_ + (0x0082))
  524. /**
  525. * @ingroup Common_register_group_W5100S
  526. * @brief Core 100us Counter clear register
  527. * @details \reg
  528. */
  529. #define TCNTCLKR (_W5100S_IO_BASE_ + (0x0088))
  530. //----------------------------- W5100S Socket Registers -----------------------------
  531. //--------------------------- For Backward Compatibility ---------------------------
  532. /**
  533. * @ingroup Socket_register_group_W5100S
  534. * @brief socket Mode register(R/W)
  535. * @details \ref Sn_MR configures the option or protocol type of Socket n.\n\n
  536. * Each bit of \ref Sn_MR defined as the following.
  537. * <table>
  538. * <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>
  539. * <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>
  540. * </table>
  541. * - \ref Sn_MR_MULTI : Support UDP Multicasting
  542. * - \ref Sn_MR_MF : Support MACRAW
  543. * - \ref Sn_MR_ND : No Delayed Ack(TCP) flag
  544. * - \ref Sn_MR_MC : IGMP version used <b>in UDP mulitcasting</b>
  545. * - <b>Protocol</b>
  546. * <table>
  547. * <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>
  548. * <tr> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>Closed</td> </tr>
  549. * <tr> <td>0</td> <td>0</td> <td>0</td> <td>1</td> <td>TCP</td> </tr>
  550. * <tr> <td>0</td> <td>0</td> <td>1</td> <td>0</td> <td>UDP</td> </tr>
  551. * <tr> <td>0</td> <td>1</td> <td>0</td> <td>0</td> <td>MACRAW</td> </tr>
  552. * </table>
  553. * - <b>In case of Socket 0</b>
  554. * <table>
  555. * <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>
  556. * <tr> <td>0</td> <td>1</td> <td>0</td> <td>0</td> <td>MACRAW</td> </tr>
  557. * <tr> <td>0</td> <td>1</td> <td>0</td> <td>1</td> <td>PPPoE</td> </tr>
  558. * </table>
  559. * - \ref Sn_MR_MACRAW : MAC LAYER RAW SOCK \n
  560. * - \ref Sn_MR_UDP : UDP
  561. * - \ref Sn_MR_TCP : TCP
  562. * - \ref Sn_MR_CLOSE : Unused socket
  563. * @note MACRAW mode should be only used in Socket 0.
  564. */
  565. #define Sn_MR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0000)) // socket Mode register
  566. /**
  567. * @ingroup Socket_register_group_W5100S
  568. * @brief Socket command register(R/W)
  569. * @details This is used to set the command for Socket n such as OPEN, CLOSE, CONNECT, LISTEN, SEND, and RECEIVE.\n
  570. * After W5100S accepts the command, the \ref Sn_CR register is automatically cleared to 0x00.
  571. * Even though \ref Sn_CR is cleared to 0x00, the command is still being processed.\n
  572. * To check whether the command is completed or not, please check the \ref Sn_IR or \ref Sn_SR.
  573. * - \ref Sn_CR_OPEN : Initialize or open socket.
  574. * - \ref Sn_CR_LISTEN : Wait connection request in TCP mode(<b>Server mode</b>)
  575. * - \ref Sn_CR_CONNECT : Send connection request in TCP mode(<b>Client mode</b>)
  576. * - \ref Sn_CR_DISCON : Send closing request in TCP mode.
  577. * - \ref Sn_CR_CLOSE : Close socket.
  578. * - \ref Sn_CR_SEND : Update TX buffer pointer and send data.
  579. * - \ref Sn_CR_SEND_MAC : Send data with MAC address, so without ARP process.
  580. * - \ref Sn_CR_SEND_KEEP : Send keep alive message.
  581. * - \ref Sn_CR_RECV : Update RX buffer pointer and receive data.
  582. * - <b>In case of S0_MR(P3:P0) = S0_MR_PPPoE</b>
  583. * <table>
  584. * <tr> <td><b>Value</b></td> <td><b>Symbol</b></td> <td><b>Description</b></td></tr>
  585. * <tr> <td>0x23</td> <td>PCON</td> <td>PPPoE connection begins by transmitting PPPoE discovery packet</td> </tr>
  586. * <tr> <td>0x24</td> <td>PDISCON</td> <td>Closes PPPoE connection</td> </tr>
  587. * <tr> <td>0x25</td> <td>PCR</td> <td>In each phase, it transmits REQ message.</td> </tr>
  588. * <tr> <td>0x26</td> <td>PCN</td> <td>In each phase, it transmits NAK message.</td> </tr>
  589. * <tr> <td>0x27</td> <td>PCJ</td> <td>In each phase, it transmits REJECT message.</td> </tr>
  590. * </table>
  591. */
  592. #define Sn_CR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0001)) // channel Sn_CR register
  593. /**
  594. * @ingroup Socket_register_group_W5100S
  595. * @brief Socket interrupt register(R)
  596. * @details \ref Sn_IR indicates the status of Socket Interrupt such as establishment, termination, receiving data, timeout).\n
  597. * 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
  598. * In order to clear the \ref Sn_IR bit, the host should write the bit to \n
  599. * <table>
  600. * <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>
  601. * <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>
  602. * </table>
  603. * - \ref Sn_IR_PRECV : <b>PPP Receive Interrupt</b>
  604. * - \ref Sn_IR_PFAIL : <b>PPP Fail Interrupt</b>
  605. * - \ref Sn_IR_PNEXT : <b>PPP Next Phase Interrupt</b>
  606. * - \ref Sn_IR_SENDOK : <b>SEND_OK Interrupt</b>
  607. * - \ref Sn_IR_TIMEOUT : <b>TIMEOUT Interrupt</b>
  608. * - \ref Sn_IR_RECV : <b>RECV Interrupt</b>
  609. * - \ref Sn_IR_DISCON : <b>DISCON Interrupt</b>
  610. * - \ref Sn_IR_CON : <b>CON Interrupt</b>
  611. */
  612. #define Sn_IR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0002)) // channel interrupt register
  613. /**
  614. * @ingroup Socket_register_group_W5100S
  615. * @brief Socket status register(R)
  616. * @details \ref Sn_SR indicates the status of Socket n.\n
  617. * The status of Socket n is changed by \ref Sn_CR or some special control packet as SYN, FIN packet in TCP.
  618. * @par Normal status
  619. * - \ref SOCK_CLOSED : Closed
  620. * - \ref SOCK_INIT : Initiate state
  621. * - \ref SOCK_LISTEN : Listen state
  622. * - \ref SOCK_ESTABLISHED : Success to connect
  623. * - \ref SOCK_CLOSE_WAIT : Closing state
  624. * - \ref SOCK_UDP : UDP socket
  625. * - \ref SOCK_MACRAW : MAC raw mode socket
  626. *@par Temporary status during changing the status of Socket n.
  627. * - \ref SOCK_SYNSENT : This indicates Socket n sent the connect-request packet (SYN packet) to a peer.
  628. * - \ref SOCK_SYNRECV : It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer.
  629. * - \ref SOCK_FIN_WAIT : Connection state
  630. * - \ref SOCK_CLOSING : Closing state
  631. * - \ref SOCK_TIME_WAIT : Closing state
  632. * - \ref SOCK_LAST_ACK : Closing state
  633. */
  634. #define Sn_SR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0003)) // channel status register
  635. /**
  636. * @ingroup Socket_register_group_W5100S
  637. * @brief source port register(R/W)
  638. * @details \ref Sn_PORT configures the source port number of Socket n.
  639. * It is valid when Socket n is used in TCP/UDP mode. It should be set before OPEN command is ordered.
  640. */
  641. #define Sn_PORT(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0004)) // source port register
  642. /**
  643. * @ingroup Socket_register_group_W5100S
  644. * @brief Peer MAC register address(R/W)
  645. * @details \ref Sn_DHAR configures the destination hardware address of Socket n when using SEND_MAC command in UDP mode or
  646. * it indicates that it is acquired in ARP-process by CONNECT/SEND command.
  647. */
  648. #define Sn_DHAR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0006)) // Peer MAC register address
  649. /**
  650. * @ingroup Socket_register_group_W5100S
  651. * @brief Peer IP register address(R/W)
  652. * @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.
  653. * In TCP client mode, it configures an IP address of TCP server before CONNECT command.
  654. * In TCP server mode, it indicates an IP address of TCP client after successfully establishing connection.
  655. * In UDP mode, it configures an IP address of peer to be received the UDP packet by SEND or SEND_MAC command.
  656. */
  657. #define Sn_DIPR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x000C)) // Peer IP register address
  658. /**
  659. * @ingroup Socket_register_group_W5100S
  660. * @brief Peer port register address(R/W)
  661. * @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.
  662. * In TCP clientmode, it configures the listen port number of TCP server before CONNECT command.
  663. * In TCP Servermode, it indicates the port number of TCP client after successfully establishing connection.
  664. * In UDP mode, it configures the port number of peer to be transmitted the UDP packet by SEND/SEND_MAC command.
  665. */
  666. #define Sn_DPORT(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0010)) // Peer port register address
  667. /**
  668. * @ingroup Socket_register_group_W5100S
  669. * @brief Maximum Segment Size(Sn_MSSR0) register address(R/W)
  670. * @details \ref Sn_MSSR configures or indicates the MTU(Maximum Transfer Unit) of Socket n.
  671. */
  672. #define Sn_MSSR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0012)) // Maximum Segment Size(Sn_MSSR0) register address
  673. /**
  674. * @ingroup Socket_register_group_W5100S
  675. * @brief IP Protocol(PROTO) Register(R/W)
  676. * @details \ref Sn_PROTO that sets the protocol number field of the IP header at the IP layer. It is
  677. * valid only in IPRAW mode, and ignored in other modes.
  678. */
  679. #define Sn_PROTO(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0014)) // Protocol of IP Header field register in IP raw mode
  680. /**
  681. * @ingroup Socket_register_group_W5100S
  682. * @brief IP Type of Service(TOS) Register(R/W)
  683. * @details \ref Sn_TOS configures the TOS(Type Of Service field in IP Header) of Socket n.
  684. * It is set before OPEN command.
  685. */
  686. #define Sn_TOS(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + 0x0015) // IP Type of Service(TOS) Register
  687. /**
  688. * @ingroup Socket_register_group_W5100S
  689. * @brief IP Time to live(TTL) Register(R/W)
  690. * @details \ref Sn_TTL configures the TTL(Time To Live field in IP header) of Socket n.
  691. * It is set before OPEN command.
  692. */
  693. #define Sn_TTL(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0016)) // IP Time to live(TTL) Register
  694. // Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0017))
  695. // Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0018))
  696. // Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0019))
  697. // Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001A))
  698. // Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001B))
  699. // Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001C))
  700. // Reserved (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001D))
  701. /**
  702. * @ingroup Socket_register_group_W5100S
  703. * @brief Receive memory size register(R/W)
  704. * @details @ref Sn_RXBUF_SIZE configures the RX buffer block size of Socket n.
  705. * Socket n RX Buffer Block size can be configured with 1,2,4 and 8Kbytes.
  706. * If a different size is configured, the data cannot be normally received from a peer.
  707. * Although Socket n RX Buffer Block size is initially configured to 2Kbytes,
  708. * user can re-configure its size using @ref Sn_RXBUF_SIZE. The total sum of @ref Sn_RXBUF_SIZE can not be exceed 8Kbytes.
  709. * When exceeded, the data reception error is occurred.
  710. */
  711. #define Sn_RXBUF_SIZE(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001E))
  712. /**
  713. * @ingroup Socket_register_group_W5100S
  714. * @brief Transmit memory size register(R/W)
  715. * @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 and 8Kbytes.
  716. * If a different size is configured, the data cannot be normally transmitted to a peer.
  717. * Although Socket n TX Buffer Block size is initially configured to 2Kbytes,
  718. * user can be re-configure its size using @ref Sn_TXBUF_SIZE. The total sum of @ref Sn_TXBUF_SIZE can not be exceed 8Kbytes.
  719. * When exceeded, the data transmission error is occurred.
  720. */
  721. #define Sn_TXBUF_SIZE(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x001F))
  722. /**
  723. * @ingroup Socket_register_group_W5100S
  724. * @brief Transmit free memory size register(R)
  725. * @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.
  726. * 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.
  727. * Therefore, check before saving the data to the Socket n TX Buffer, and if data is equal or smaller than its checked size,
  728. * 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,
  729. * transmit the data after dividing into the checked size and saving in the Socket n TX buffer.
  730. */
  731. #define Sn_TX_FSR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0020)) // Transmit free memory size register
  732. /**
  733. * @ingroup Socket_register_group_W5100S
  734. * @brief Transmit memory read pointer register address(R)
  735. * @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.
  736. * After its initialization, it is auto-increased by SEND command.
  737. * 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.
  738. * After transmitting the saved data, the SEND command increases the \ref Sn_TX_RD as same as the \ref Sn_TX_WR.
  739. * If its increment value exceeds the maximum value 0xFFFF, (greater than 0x10000 and the carry bit occurs),
  740. * then the carry bit is ignored and will automatically update with the lower 16bits value.
  741. */
  742. #define Sn_TX_RD(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0022)) // Transmit memory read pointer register address
  743. /**
  744. * @ingroup Socket_register_group_W5100S
  745. * @brief Transmit memory write pointer register address(R/W)
  746. * @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
  747. * It should be read or be updated like as follows.\n
  748. * 1. Read the starting address for saving the transmitting data.\n
  749. * 2. Save the transmitting data from the starting address of Socket n TX buffer.\n
  750. * 3. After saving the transmitting data, update \ref Sn_TX_WR to the increased value as many as transmitting data size.
  751. * If the increment value exceeds the maximum value 0xFFFF(greater than 0x10000 and the carry bit occurs),
  752. * then the carry bit is ignored and will automatically update with the lower 16bits value.\n
  753. * 4. Transmit the saved data in Socket n TX Buffer by using SEND/SEND command
  754. */
  755. #define Sn_TX_WR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0024)) // Transmit memory write pointer register address
  756. /**
  757. * @ingroup Socket_register_group_W5100S
  758. * @brief Received data size register(R)
  759. * @details \ref Sn_RX_RSR indicates the data size received and saved in Socket n RX Buffer.
  760. * \ref Sn_RX_RSR does not exceed the \ref Sn_RXMEM_SIZE and is calculated as the difference between
  761. * Socket n RX Write Pointer (\ref Sn_RX_WR)and Socket n RX Read Pointer (\ref Sn_RX_RD)
  762. */
  763. #define Sn_RX_RSR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0026)) // Received data size register
  764. /**
  765. * @ingroup Socket_register_group_W5100S
  766. * @brief Read point of Receive memory(R/W)
  767. * @details \ref Sn_RX_RD is initialized by OPEN command. Make sure to be read or updated as follows.\n
  768. * 1. Read the starting save address of the received data.\n
  769. * 2. Read data from the starting address of Socket n RX Buffer.\n
  770. * 3. After reading the received data, Update \ref Sn_RX_RD to the increased value as many as the reading size.
  771. * If the increment value exceeds the maximum value 0xFFFF, that is, is greater than 0x10000 and the carry bit occurs,
  772. * update with the lower 16bits value ignored the carry bit.\n
  773. * 4. Order RECV command is for notifying the updated \ref Sn_RX_RD to W5100S.
  774. */
  775. #define Sn_RX_RD(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0028)) // Read point of Receive memory
  776. /**
  777. * @ingroup Socket_register_group_W5100S
  778. * @brief Write point of Receive memory(R)
  779. * @details \ref Sn_RX_WR is initialized by OPEN command and it is auto-increased by the data reception.
  780. * If the increased value exceeds the maximum value 0xFFFF, (greater than 0x10000 and the carry bit occurs),
  781. * then the carry bit is ignored and will automatically update with the lower 16bits value.
  782. */
  783. #define Sn_RX_WR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002A)) // Write point of Receive memory
  784. //todo
  785. /**
  786. * @ingroup Socket_register_group_W5100S
  787. * @brief Socket interrupt mask register
  788. * @details Register address to configure the interrupt mask of the socket
  789. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b> expect <b>bit 4</b>.
  790. *
  791. */
  792. #define Sn_IMR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002C))
  793. /**
  794. * @ingroup Socket_register_group_W5100S
  795. * @brief Socket fragment field register
  796. * @details Register to configure the Fragment field of IP Header
  797. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b> expect <b>bit 4</b>.
  798. */
  799. #define Sn_FRAGR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002D)) // and +1
  800. /**
  801. * @ingroup Socket_register_group_W5100S
  802. * @brief Socket Mode register 2
  803. * @details Register to set mode 2
  804. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b> expect <b>bit 4</b>.
  805. */
  806. #define Sn_MR2(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x002F))
  807. /**
  808. * @ingroup Socket_register_group_W5100S
  809. * @brief Socket n Keep Alive Timer Register
  810. * @details Register to set the transmission period of keep alive packet.
  811. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b> expect <b>bit 4</b>.
  812. */
  813. #define Sn_KPALVTR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0030))
  814. /** todo delete
  815. * @ingroup Socket_register_group_W5100S
  816. * @brief Socket n Timer Status Register
  817. * @details
  818. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b> expect <b>bit 4</b>.
  819. */
  820. //#define Sn_TSR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0031))
  821. /**
  822. * @ingroup Socket_register_group_W5100S
  823. * @brief Socket n Retry Time-value Register
  824. * @details Register to set the retry time value
  825. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b> expect <b>bit 4</b>.
  826. */
  827. #define Sn_RTR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0032))
  828. /**
  829. * @ingroup Socket_register_group_W5100S
  830. * @brief Socket n Retry Count-value Register
  831. * @details Register to set the retry count value
  832. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b> expect <b>bit 4</b>.
  833. */
  834. #define Sn_RCR(sn) (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (0x0034))
  835. /*----------------------------- W5100S Register values -----------------------------*/
  836. /* MODE register values */
  837. /**
  838. * @brief Reset
  839. * @details If this bit is All internal registers will be initialized. It will be automatically cleared as after S/W reset.
  840. */
  841. #define MR_RST 0x80 ///< reset
  842. /**
  843. * @brief Ping block
  844. * @details 0 : Disable Ping block\n
  845. * 1 : Enable Ping block\n
  846. * If the bit is it blocks the response to a ping request.
  847. */
  848. #define MR_PB 0x10 ///< ping block
  849. /**
  850. * @brief Enable PPPoE
  851. * @details 0 : DisablePPPoE mode\n
  852. * 1 : EnablePPPoE mode\n
  853. * If you use ADSL, this bit should be '1'.
  854. */
  855. #define MR_PPPOE 0x08 ///< enable pppoe
  856. /**
  857. * @brief Address Auto-Increment in Indirect Bus Interface
  858. * @details 0 : Disable auto-increment \n
  859. * 1 : Enable auto-incremente \n
  860. * At the Indirect Bus Interface mode, if this bit is set as the address will
  861. * be automatically increased by 1 whenever read and write are performed.
  862. */
  863. #define MR_AI 0x02 ///< auto-increment in indirect mode
  864. /**
  865. * @brief Indirect Bus Interface mode
  866. * @details 0 : Disable Indirect bus Interface mode \n
  867. * 1 : Enable Indirect bus Interface mode \n
  868. * If this bit is set as Indirect Bus Interface mode is set.
  869. */
  870. #define MR_IND 0x01 ///< enable indirect mode
  871. /* IR register values */
  872. /**
  873. * @brief Check IP conflict.
  874. * @details Bit is set as when own source IP address is same with the sender IP address in the received ARP request.
  875. */
  876. #define IR_CONFLICT 0x80 ///< check ip confict
  877. /**
  878. * @brief Get the destination unreachable message in UDP sending.
  879. * @details When receiving the ICMP (Destination port unreachable) packet, this bit is set as
  880. * When this bit is Destination Information such as IP address and Port number may be checked with the corresponding @ref UIPR & @ref UPORTR.
  881. */
  882. #define IR_UNREACH 0x40 ///< check destination unreachable
  883. /**
  884. * @brief Get the PPPoE close message.
  885. * @details When PPPoE is disconnected during PPPoE mode, this bit is set.
  886. */
  887. #define IR_PPPoE 0x20 ///< get the PPPoE close message
  888. /**
  889. * @brief Socket interrupt bit
  890. * @details Indicates whether each socket interrupt has occured.
  891. */
  892. #define IR_SOCK(sn) (0x01 << sn) ///< check socket interrupt
  893. /**
  894. * @brief IP conflict interrupt mask bit
  895. * @details If this bit is set, IP conflict interrupt is enabled.
  896. */
  897. #define IMR_CONFLICT 0x80
  898. /**
  899. * @brief Destination port unreachable interrupt mask bit
  900. * @details If this bit is set, destination port unreachable interrupt is enabled.
  901. */
  902. #define IMR_UNREACH 0x40
  903. /**
  904. * @brief PADT/LCPT interrupt mask bit(PPPoE)
  905. * @details If this bit is set, PADT/LCPT interrupt is enabled.
  906. */
  907. #define IMR_PPPoE 0x20
  908. /**
  909. * @brief Socket interrupt mask bit
  910. * @details If this bit is set, each socket interrupt is enabled.
  911. */
  912. #define IMR_SOCK(sn) (0x01 << sn)
  913. /**
  914. * @brief Socket-less command register bit
  915. * @details ARP command
  916. */
  917. #define SLCMD_ARP (1<<1)
  918. /**
  919. * @brief Socket-less command register bit
  920. * @details ARP command
  921. */
  922. #define SLCMD_PING (1<<0)
  923. /**
  924. * @brief Socket-less command interrupt and interrupt mask register bit
  925. * @details Request command time out interrupt and interrupt mask
  926. */
  927. #define SLIR_TIMEOUT (1<<2)
  928. /**
  929. * @brief Socket less command interrupt and interrupt mask register bit
  930. * @details Socket less command ARP interrupt and interrupt mask
  931. */
  932. #define SLIR_ARP (1<<1)
  933. /**
  934. * @brief Socket less command interrupt and interrupt mask register bit
  935. * @details Socket less command PING interrupt and interruptmask
  936. */
  937. #define SLIR_PING (1<<0)
  938. // Sn_MR values
  939. /* Sn_MR Default values */
  940. /**
  941. * @brief Unused socket
  942. * @details This configures the protocol mode of Socket n.
  943. */
  944. #define Sn_MR_CLOSE 0x00 ///< unused socket
  945. /**
  946. * @brief TCP
  947. * @details This configures the protocol mode of Socket n.
  948. */
  949. #define Sn_MR_TCP 0x01 ///< TCP
  950. /**
  951. * @brief UDP
  952. * @details This configures the protocol mode of Socket n.
  953. */
  954. #define Sn_MR_UDP 0x02 ///< UDP
  955. #define Sn_MR_IPRAW 0x03 ///< IP LAYER RAW SOCK
  956. /**
  957. * @brief MAC LAYER RAW SOCK
  958. * @details This configures the protocol mode of Socket n.
  959. * @note MACRAW mode should be only used in Socket 0.
  960. */
  961. #define Sn_MR_MACRAW 0x04 ///< MAC LAYER RAW SOCK
  962. /**
  963. * @brief PPPoE
  964. * @details This configures the protocol mode of Socket n.
  965. * @note PPPoE mode should be only used in Socket 0.
  966. */
  967. #define Sn_MR_PPPoE 0x05 ///< PPPoE
  968. /**
  969. * @brief No Delayed Ack(TCP), Multicast flag
  970. * @details 0 : Disable No Delayed ACK option\n
  971. * 1 : Enable No Delayed ACK option\n
  972. * This bit is applied only during TCP mode (P[3:0] = 001).\n
  973. * When this bit is It sends the ACK packet without delay as soon as a Data packet is received from a peer.\n
  974. * When this bit is It sends the ACK packet after waiting for the timeout time configured by \ref _RTR_.
  975. */
  976. #define Sn_MR_ND 0x20 ///< No Delayed Ack(TCP) flag
  977. /**
  978. * @brief Support UDP Multicasting
  979. * @details 0 : using IGMP version 2\n
  980. * 1 : using IGMP version 1\n
  981. * This bit is applied only during UDP mode(P[3:0] = 010 and MULTI = '1')
  982. * It configures the version for IGMP messages (Join/Leave/Report).
  983. */
  984. #define Sn_MR_MC Sn_MR_ND ///< Select IGMP version 1(0) or 2(1)
  985. /**
  986. * @brief MAC filter enable in @ref Sn_MR_MACRAW mode
  987. * @details 0 : disable MAC Filtering\n
  988. * 1 : enable MAC Filtering\n
  989. * This bit is applied only during MACRAW mode(P[3:0] = 100.\n
  990. * When set as W5100S can only receive broadcasting packet or packet sent to itself.
  991. * When this bit is W5100S can receive all packets on Ethernet.
  992. * If user wants to implement Hybrid TCP/IP stack,
  993. * it is recommended that this bit is set as for reducing host overhead to process the all received packets.
  994. */
  995. #define Sn_MR_MF 0x40 ///< Use MAC filter
  996. #define Sn_MR_MFEN Sn_MR_MF
  997. /* Sn_MR Default values */
  998. /**
  999. * @brief Support UDP Multicasting
  1000. * @details 0 : disable Multicasting\n
  1001. * 1 : enable Multicasting\n
  1002. * This bit is applied only during UDP mode(P[3:0] = 010).\n
  1003. * To use multicasting, \ref Sn_DIPR & \ref Sn_DPORT should be respectively configured with the multicast group IP address & port number
  1004. * before Socket n is opened by OPEN command of \ref Sn_CR.
  1005. */
  1006. #define Sn_MR_MULTI 0x80 ///< support multicating
  1007. /* Sn_CR values */
  1008. /**
  1009. * @brief Initialize or open socket
  1010. * @details Socket n is initialized and opened according to the protocol selected in Sn_MR(P3:P0).
  1011. * The table below shows the value of \ref Sn_SR corresponding to \ref Sn_MR.\n
  1012. * <table>
  1013. * <tr> <td>\b Sn_MR (P[3:0])</td> <td>\b Sn_SR</td> </tr>
  1014. * <tr> <td>Sn_MR_CLOSE (000)</td> <td>--</td> </tr>
  1015. * <tr> <td>Sn_MR_TCP (001)</td> <td>SOCK_INIT (0x13)</td> </tr>
  1016. * <tr> <td>Sn_MR_UDP (010)</td> <td>SOCK_UDP (0x22)</td> </tr>
  1017. * <tr> <td>S0_MR_IPRAW (011)</td> <td>SOCK_IPRAW (0x32)</td> </tr>
  1018. * <tr> <td>S0_MR_MACRAW (100)</td> <td>SOCK_MACRAW (0x42)</td> </tr>
  1019. * <tr> <td>S0_MR_PPPoE (101)</td> <td>SOCK_PPPoE (0x5F)</td> </tr>
  1020. * </table>
  1021. */
  1022. #define Sn_CR_OPEN 0x01 ///< initialize or open socket
  1023. /**
  1024. * @brief Wait connection request in TCP mode(Server mode)
  1025. * @details This is valid only in TCP mode (Sn_MR(P3:P0) = \ref Sn_MR_TCP).//
  1026. * In this mode, Socket n operates as a 'TCP server' and waits for connection-request (SYN packet) from any 'TCP client'.//
  1027. * The \ref Sn_SR changes the state from SOCK_INIT to SOCKET_LISTEN.//
  1028. * When a 'TCP client' connection request is successfully established,
  1029. * the \ref Sn_SR changes from SOCK_LISTEN to SOCK_ESTABLISHED and the Sn_IR(0) becomes
  1030. * But when a 'TCP client' connection request is failed, Sn_IR(3) becomes and the status of \ref Sn_SR changes to SOCK_CLOSED.
  1031. */
  1032. #define Sn_CR_LISTEN 0x02 ///< wait connection request in tcp mode(Server mode)
  1033. /**
  1034. * @brief Send connection request in TCP mode(Client mode)
  1035. * @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).
  1036. * If the connect-request is successful, the \ref Sn_SR is changed to \ref SOCK_ESTABLISHED and the Sn_IR(0) becomes \n\n
  1037. * The connect-request fails in the following three cases.\n
  1038. * 1. When a @b ARPTO occurs (\ref Sn_IR[3] = '1') because destination hardware address is not acquired through the ARP-process.\n
  1039. * 2. When a @b SYN/ACK packet is not received and @b TCPTO (Sn_IR(3) ='1')\n
  1040. * 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.
  1041. * @note This is valid only in TCP mode and operates when Socket n acts as <b>TCP client</b>
  1042. */
  1043. #define Sn_CR_CONNECT 0x04 ///< send connection request in tcp mode(Client mode)
  1044. /**
  1045. * @brief Send closing request in TCP mode
  1046. * @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
  1047. * @par Active close
  1048. * it transmits disconnect-request(FIN packet) to the connected peer\n
  1049. * @par Passive close
  1050. * When FIN packet is received from peer, a FIN packet is replied back to the peer.\n
  1051. * @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
  1052. * Otherwise, TCPTO occurs (Sn_IR(3)='1') and then \ref Sn_SR is changed to \ref SOCK_CLOSED.
  1053. * @note Valid only in TCP mode.
  1054. */
  1055. #define Sn_CR_DISCON 0x08 ///< send closing reqeuset in tcp mode
  1056. /**
  1057. * @brief Close socket
  1058. * @details Sn_SR is changed to \ref SOCK_CLOSED.
  1059. */
  1060. #define Sn_CR_CLOSE 0x10
  1061. /**
  1062. * @brief Update TX buffer pointer and send data
  1063. * @details SEND transmits all the data in the Socket n TX buffer.\n
  1064. * For more details, please refer to Socket n TX Free Size Register (\ref Sn_TX_FSR), Socket n,
  1065. * TX Write Pointer Register(\ref Sn_TX_WR), and Socket n TX Read Pointer Register(\ref Sn_TX_RD).
  1066. */
  1067. #define Sn_CR_SEND 0x20
  1068. /**
  1069. * @brief Send data with MAC address, so without ARP process
  1070. * @details The basic operation is same as SEND.\n
  1071. * Normally SEND transmits data after destination hardware address is acquired by the automatic ARP-process(Address Resolution Protocol).\n
  1072. * But SEND_MAC transmits data without the automatic ARP-process.\n
  1073. * In this case, the destination hardware address is acquired from \ref Sn_DHAR configured by host, instead of APR-process.
  1074. * @note Valid only in UDP mode.
  1075. */
  1076. #define Sn_CR_SEND_MAC 0x21
  1077. /**
  1078. * @brief Send keep alive message
  1079. * @details It checks the connection status by sending 1byte keep-alive packet.\n
  1080. * If the peer can not respond to the keep-alive packet during timeout time, the connection is terminated and the timeout interrupt will occur.
  1081. * @note Valid only in TCP mode.
  1082. */
  1083. #define Sn_CR_SEND_KEEP 0x22
  1084. /**
  1085. * @brief Update RX buffer pointer and receive data
  1086. * @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
  1087. * 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),
  1088. * and Socket n RX Read Pointer Register (\ref Sn_RX_RD).
  1089. */
  1090. #define Sn_CR_RECV 0x40
  1091. /**
  1092. * @brief
  1093. * @details
  1094. */
  1095. #define Sn_CR_IGMP_JOIN 0x23
  1096. /**
  1097. * @brief
  1098. * @details
  1099. */
  1100. #define Sn_CR_IGMP_LEAVE 0x24
  1101. /* Sn_IR values */
  1102. /**
  1103. * @brief SEND_OK Interrupt
  1104. * @details This is issued when SEND command is completed.
  1105. */
  1106. #define Sn_IR_SENDOK 0x10 ///< complete sending
  1107. /**
  1108. * @brief TIMEOUT Interrupt
  1109. * @details This is issued when ARPTO or TCPTO occurs.
  1110. */
  1111. #define Sn_IR_TIMEOUT 0x08 ///< assert timeout
  1112. /**
  1113. * @brief RECV Interrupt
  1114. * @details This is issued whenever data is received from a peer.
  1115. */
  1116. #define Sn_IR_RECV 0x04
  1117. /**
  1118. * @brief DISCON Interrupt
  1119. * @details This is issued when FIN or FIN/ACK packet is received from a peer.
  1120. */
  1121. #define Sn_IR_DISCON 0x02
  1122. /**
  1123. * @brief CON Interrupt
  1124. * @details This is issued one time when the connection with peer is successful and then \ref Sn_SR is changed to \ref SOCK_ESTABLISHED.
  1125. */
  1126. #define Sn_IR_CON 0x01
  1127. /* Sn_SR values */
  1128. /**
  1129. * @brief Closed
  1130. * @details This indicates that Socket n is released.\n
  1131. * When DICON, CLOSE command is ordered, or when a timeout occurs, it is changed to \ref SOCK_CLOSED regardless of previous status.
  1132. */
  1133. #define SOCK_CLOSED 0x00 ///< closed
  1134. /**
  1135. * @brief Initiate state
  1136. * @details This indicates Socket n is opened with TCP mode.\n
  1137. * It is changed to \ref SOCK_INIT when Sn_MR(P[3:0]) = 001)and OPEN command is ordered.\n
  1138. * After \ref SOCK_INIT, user can use LISTEN /CONNECT command.
  1139. */
  1140. #define SOCK_INIT 0x13 ///< init state
  1141. /**
  1142. * @brief Listen state
  1143. * @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
  1144. * It will change to \ref SOCK_ESTABLISHED when the connection-request is successfully accepted.\n
  1145. * Otherwise it will change to \ref SOCK_CLOSED after TCPTO occurred (Sn_IR(TIMEOUT) = '1').
  1146. */
  1147. #define SOCK_LISTEN 0x14
  1148. /**
  1149. * @brief Connection state
  1150. * @details This indicates Socket n sent the connect-request packet (SYN packet) to a peer.\n
  1151. * It is temporarily shown when \ref Sn_SR is changed from \ref SOCK_INIT to \ref SOCK_ESTABLISHED by CONNECT command.\n
  1152. * If connect-accept(SYN/ACK packet) is received from the peer at SOCK_SYNSENT, it changes to \ref SOCK_ESTABLISHED.\n
  1153. * Otherwise, it changes to \ref SOCK_CLOSED after TCPTO (\ref Sn_IR[TIMEOUT] = '1') is occurred.
  1154. */
  1155. #define SOCK_SYNSENT 0x15
  1156. /**
  1157. * @brief Connection state
  1158. * @details It indicates Socket n successfully received the connect-request packet (SYN packet) from a peer.\n
  1159. * If socket n sends the response (SYN/ACK packet) to the peer successfully, it changes to \ref SOCK_ESTABLISHED. \n
  1160. * If not, it changes to \ref SOCK_CLOSED after timeout occurs (\ref Sn_IR[TIMEOUT] = '1').
  1161. */
  1162. #define SOCK_SYNRECV 0x16
  1163. /**
  1164. * @brief Success to connect
  1165. * @details This indicates the status of the connection of Socket n.\n
  1166. * 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
  1167. * when the CONNECT command is successful.\n
  1168. * During \ref SOCK_ESTABLISHED, DATA packet can be transferred using SEND or RECV command.
  1169. */
  1170. #define SOCK_ESTABLISHED 0x17
  1171. /**
  1172. * @brief Closing state
  1173. * @details These indicate Socket n is closing.\n
  1174. * These are shown in disconnect-process such as active-close and passive-close.\n
  1175. * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED.
  1176. */
  1177. #define SOCK_FIN_WAIT 0x18
  1178. /**
  1179. * @brief Closing state
  1180. * @details These indicate Socket n is closing.\n
  1181. * These are shown in disconnect-process such as active-close and passive-close.\n
  1182. * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED.
  1183. */
  1184. #define SOCK_CLOSING 0x1A
  1185. /**
  1186. * @brief Closing state
  1187. * @details These indicate Socket n is closing.\n
  1188. * These are shown in disconnect-process such as active-close and passive-close.\n
  1189. * When Disconnect-process is successfully completed, or when timeout occurs, these change to \ref SOCK_CLOSED.
  1190. */
  1191. #define SOCK_TIME_WAIT 0x1B
  1192. /**
  1193. * @brief Closing state
  1194. * @details This indicates Socket n received the disconnect-request (FIN packet) from the connected peer.\n
  1195. * This is half-closing status, and data can be transferred.\n
  1196. * For full-closing, DISCON command is used. But For just-closing, @ref Sn_CR_CLOSE command is used.
  1197. */
  1198. #define SOCK_CLOSE_WAIT 0x1C
  1199. /**
  1200. * @brief Closing state
  1201. * @details This indicates Socket n is waiting for the response (FIN/ACK packet) to the disconnect-request (FIN packet) by passive-close.\n
  1202. * It changes to \ref SOCK_CLOSED when Socket n received the response successfully, or when timeout occurs (\ref Sn_IR[TIMEOUT] = '1').
  1203. */
  1204. #define SOCK_LAST_ACK 0x1D
  1205. /**
  1206. * @brief UDP socket
  1207. * @details This indicates Socket n is opened in UDP mode(Sn_MR(P[3:0]) = 010).\n
  1208. * It changes to SOCK_UDP when Sn_MR(P[3:0]) = 010 and @ref Sn_CR_OPEN command is ordered.\n
  1209. * Unlike TCP mode, data can be transfered without the connection-process.
  1210. */
  1211. #define SOCK_UDP 0x22 ///< udp socket
  1212. /**
  1213. * @brief IP raw mode socket
  1214. * @details TThe socket is opened in IPRAW mode. The SOCKET status is change to SOCK_IPRAW when @ref Sn_MR (P3:P0) is
  1215. * Sn_MR_IPRAW and @ref Sn_CR_OPEN command is used.\n
  1216. * IP Packet can be transferred without a connection similar to the UDP mode.
  1217. */
  1218. #define SOCK_IPRAW 0x32 ///< ip raw mode socket
  1219. /**
  1220. * @brief MAC raw mode socket
  1221. * @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
  1222. * It changes to SOCK_MACRAW when @ref Sn_MR(P[3:0]) = '100' and @ref Sn_CR_OPEN command is ordered.\n
  1223. * Like UDP mode socket, MACRAW mode Socket 0 can transfer a MAC packet (Ethernet frame) without the connection-process.
  1224. */
  1225. #define SOCK_MACRAW 0x42 ///< mac raw mode socket
  1226. /**
  1227. * @brief PPPoE mode socket
  1228. * @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
  1229. * (P3:P0)=S0_MR_PPPoE.\n
  1230. * It is temporarily used at the PPPoE
  1231. connection.
  1232. */
  1233. #define SOCK_PPPOE 0x5F ///< pppoe socket
  1234. // IP PROTOCOL
  1235. #define IPPROTO_IP 0 ///< Dummy for IP
  1236. #define IPPROTO_ICMP 1 ///< Control message protocol
  1237. #define IPPROTO_IGMP 2 ///< Internet group management protocol
  1238. #define IPPROTO_GGP 3 ///< GW^2 (deprecated)
  1239. #define IPPROTO_TCP 6 ///< TCP
  1240. #define IPPROTO_PUP 12 ///< PUP
  1241. #define IPPROTO_UDP 17 ///< UDP
  1242. #define IPPROTO_IDP 22 ///< XNS idp
  1243. #define IPPROTO_ND 77 ///< UNOFFICIAL net disk protocol
  1244. #define IPPROTO_RAW 255 ///< Raw IP packet
  1245. /*----------------------------- W5100S !!Only!! Register values -----------------------------*/
  1246. //todo
  1247. /* MODE2 register values */
  1248. /**
  1249. * @brief Clock select bit
  1250. * @details With this bit, system clock can be selected to be 25Mhz or 100Mhz
  1251. * 1: 25Mhz
  1252. * 0: 100Mhz (default)
  1253. */
  1254. #define MR2_CLKSEL (1<<7)
  1255. /**
  1256. * @brief Interrupt pin enable bit
  1257. * @details This bit enables interrupt.
  1258. * 1: Enable interrupt
  1259. * 0: Disable interrupt
  1260. */
  1261. #define MR2_G_IEN (1<<6)
  1262. /**
  1263. * @brief No TCP Reset Packet send
  1264. * @details This bit prevents sending reset packet.
  1265. * 1: Block TCP reset packet send
  1266. * 0: TCP Reset packet send
  1267. */
  1268. #define MR2_NOTCPRST (1<<5)
  1269. /**
  1270. * @brief Unreachable Packet Send Block bit
  1271. * @details This bit prevents sending Destination Port Unreachable Packet.
  1272. * 1: Block Destination Port Unreachable Packet Send
  1273. * 0: Destination Port Unreachable Packet Send
  1274. */
  1275. #define MR2_UDPURB (1<<4)
  1276. /**
  1277. * @brief Wake On LAN
  1278. * @details This bit enables WOL packet to be received.
  1279. * 1: WOL packet can be received.
  1280. * 0: WOL packet cannot be received.
  1281. */
  1282. #define MR2_WOL (1<<3)
  1283. /**todo
  1284. * @brief MACRAW No Size Check
  1285. * @details
  1286. */
  1287. #define MR2_MNOSCHK (1<<2)
  1288. /**
  1289. * @brief UDP force ARP
  1290. * @details This bit can enables to force ARP for each send command.
  1291. * 1: UDP Force ARP Enable
  1292. * 0: UDP Force ARP Disable.
  1293. *
  1294. */
  1295. #define MR2_UDPFARP (1<<1)
  1296. /**todo
  1297. * @brief Skip SRC Hardware Address
  1298. * @details This bit can enables to receive without checking the hardware address of the peer.
  1299. * 1:
  1300. */
  1301. #define MR2_SSRCHA (1<<0)
  1302. /* Common interrupt register 2 values */
  1303. /**todo
  1304. * @brief magic packet
  1305. * @details
  1306. */
  1307. #define IR2_MGC (1<<1)
  1308. /**todo
  1309. * @brief Magic packet interrupt mask bit
  1310. * @details If this bit is set, each socket interrupt is enabled.
  1311. */
  1312. #define IMR2_MGC (1<<1)
  1313. /**todo
  1314. * @brief
  1315. * @details
  1316. */
  1317. //#define IR2_MGD (1<<1) /* Reserved */
  1318. /* PHY status register 0 values */
  1319. /**todo
  1320. * @brief Ethernet CABLE OFF Signal
  1321. * @details
  1322. */
  1323. #define PHYSR_CABOFF (1<<7)
  1324. /**todo
  1325. * @brief
  1326. * @details
  1327. */
  1328. #define PHYSR_MD2 (1<<5)
  1329. /**todo
  1330. * @brief
  1331. * @details
  1332. */
  1333. #define PHYSR_MD1 (1<<4)
  1334. /**todo
  1335. * @brief
  1336. * @details
  1337. */
  1338. #define PHYSR_MD0 (1<<3)
  1339. /**todo
  1340. * @brief
  1341. * @details
  1342. */
  1343. #define PHYSR_DUP (1<<2)
  1344. /**todo
  1345. * @brief
  1346. * @details
  1347. */
  1348. #define PHYSR_SPD (1<<1)
  1349. /**todo
  1350. * @brief LINKDONE register
  1351. * @details If 1 Linked successfully, if 0 no link
  1352. */
  1353. #define PHYSR_LNK (1<<0)
  1354. /* PHY status register 10 values */
  1355. /**
  1356. * @brieftodo
  1357. * @details
  1358. */
  1359. #define PHYSR1_RXPG (1<<2)
  1360. /**
  1361. * @brieftodo
  1362. * @details
  1363. */
  1364. #define PHYSR1_LPI (1<<1)
  1365. /**
  1366. * @brieftodo
  1367. * @details
  1368. */
  1369. #define PHYSR1_CLDN (1<<0)
  1370. #define PHYCR_AUTONEGO_ENABLE (0<<2)
  1371. #define PHYCR_AUTONEGO_DISABLE (1<<2)
  1372. #define PHYCR_SPD_10 (1<<1)
  1373. #define PHYCR_SPD_100 (0<<1)
  1374. #define PHYCR_HALF_DUP (1<<0)
  1375. #define PHYCR_FULL_DUP (0<<0)
  1376. #define PHYCR1_RST (0<<0)
  1377. #define PHYCR1_PWDN_ENABLE (1<<5)
  1378. #define PHYCR1_PWDN_DISABLE (0<<5)
  1379. /* Socket n MODE register 2 values */
  1380. /**
  1381. * @brief Broadcast Blocking bit in MACRAW mode
  1382. * @details In MACRAW mode, this bit is set to ????to block the broadcast packet.
  1383. */
  1384. #define Sn_MR2_MBBLK (1<<6)
  1385. /**
  1386. * @brief Multicast Blocking bit in MACRAW mode
  1387. * @details In MACRAW mode, this bit is set to ????to block the multicast packet.
  1388. */
  1389. #define Sn_MR2_MMBLK (1<<5)
  1390. /**
  1391. * @brief IPv6 packet Blocking bit in MACRAW mode
  1392. * @details In MACRAW mode, this bit is set to ????to block the IPv6 packet.
  1393. */
  1394. #define Sn_MR2_IPV6BLK (1<<4)
  1395. /**
  1396. * @brief Broadcast Blocking bit in UDP mode
  1397. * @details In UDP mode, this bit is set to ????to block the broadcast packet.
  1398. */
  1399. #define Sn_MR2_UBBLK (1<<1)
  1400. /**
  1401. * @brief TCP Force PSH bit
  1402. * @details When the SOCKET transmits data in TCP mode, PSH Flag is set to all packets.
  1403. */
  1404. #define Sn_MR2_FPSH Sn_MR2_UBBLK
  1405. /**
  1406. * @brief Unicast Blocking bit in UDP mode
  1407. * @details In UDP mode, this bit is set to ????to block the Unicast packet.
  1408. */
  1409. #define Sn_MR2_UUBLK (1<<0)
  1410. /*----------------------------For PHY Control-------------------------------*/
  1411. /********************/
  1412. /* Register Address */
  1413. /********************/
  1414. //Basic mode control register, basic register
  1415. #define PHYMDIO_BMCR 0x00
  1416. //Basic mode status register, basic register
  1417. #define PHYMDIO_BMSR 0x01
  1418. //--------------------------------------Not used-------------------------------------------//
  1419. ////PHY identifier register 1, extended register
  1420. //#define PHY_IDR1 0x02 //not used
  1421. //
  1422. ////PHY identifier register 2, extended register
  1423. //#define PHY_IDR2 0x03 //not used
  1424. //
  1425. ////Auto-negotiation advertisement register, extended register
  1426. //#define PHY_ANAR 0x04 //not used
  1427. //
  1428. ////Auto-negotiation link partner ability register, extended register
  1429. //#define PHY_ANLPAR 0x05 //not used
  1430. //
  1431. ////Auto-negotiation expansion register, extended register
  1432. //#define PHY_ANER 0x06 //not used
  1433. //
  1434. ////Auto-negotiation next page transmit
  1435. //#define PHY_ANNP 0x07 //not used
  1436. //
  1437. ////Auto-negotiation link partner of the next page receive
  1438. //#define PHY_ANLPNP 0x08 //not used
  1439. //
  1440. ////MMD access control register
  1441. //#define PHY_REGCR 0x09 //not used
  1442. //
  1443. ////MMD access address data register
  1444. //#define PHY_ADDAR 0x0e //not used
  1445. //--------------------------------------Not used-------------------------------------------//
  1446. /********************/
  1447. /* Bit definitions */
  1448. /********************/
  1449. //For BMCR register
  1450. #define BMCR_RESET (1<<15)
  1451. #define BMCR_MLOOPBACK (1<<14)
  1452. #define BMCR_SPEED (1<<13)
  1453. #define BMCR_AUTONEGO (1<<12)
  1454. #define BMCR_PWDN (1<<11)
  1455. #define BMCR_ISOLATE (1<<10)
  1456. #define BMCR_RSTNEGO (1<<9)
  1457. #define BMCR_DUP (1<<8)
  1458. #define BMCR_COLTEST (1<<7)
  1459. //For BMSR register
  1460. #define BMSR_AUTONEGO_COMPL (1<<5)
  1461. #define BMSR_REMOTE_FAULT (1<<4)
  1462. #define BMSR_LINK_STATUS (1<<2)
  1463. #define BMSR_JAB_DETECT (1<<1)
  1464. #define EXTENDED_CAPA (1<<0)
  1465. //--------------------------------------Not used-------------------------------------------//
  1466. ////For ANAR register
  1467. //#define ANAR_NP (1<<15)
  1468. //#define ANAR_ACK (1<<14)
  1469. //#define ANAR_RF (1<<13)
  1470. //#define ANAR_ASM (3<<10)
  1471. //#define ANAR_T4 (1<<9)
  1472. //#define ANAR_TX_FD (1<<8)
  1473. //#define ANAR_TX_HD (1<<7)
  1474. //#define ANAR_10_FD (1<<6)
  1475. //#define ANAR_10_HD (1<<5)
  1476. //#define ANAR_SELECTOR (0x1F<<0)
  1477. //
  1478. ////For ANAR register
  1479. //#define ANLPAR_NP (1<<15)
  1480. //#define ANLPAR_ACK (1<<14)
  1481. //#define ANLPAR_RF (1<<13)
  1482. //#define ANLPAR_LP_DIR (1<<11)
  1483. //#define ANLPAR_PAUSE (1<<10)
  1484. //#define ANLPAR_T4 (1<<9)
  1485. //#define ANLPAR_TX_FD (1<<8)
  1486. //#define ANLPAR_TX_HD (1<<7)
  1487. //#define ANLPAR_10_FD (1<<6)
  1488. //#define ANLPAR_10_HD (1<<5)
  1489. //#define ANLPAR_SELECTOR (0x1F<<0)
  1490. /**/
  1491. /* MDIO register*/
  1492. //PCS_CTL_1 | PCS control 1 register
  1493. //PCS_STS_1 | PCS status 1 register
  1494. //EEE_ABILITY | EEE capability register
  1495. //WAKE_ER_CNTR | EEE wake error counter
  1496. //EEE_ADVR | EEE Advertisement register
  1497. //EEE_LPAR | EEE link partner ability register
  1498. //--------------------------------------Not used-------------------------------------------//
  1499. /********************/
  1500. /*Functions for PHY */
  1501. /********************/
  1502. //todo move this definition to bit area
  1503. #define PHYACR_READ 0x02
  1504. #define PHYACR_WRITE 0x01
  1505. /**
  1506. * @brief Enter a critical section
  1507. *
  1508. * @details It is provided to protect your shared code which are executed without distribution. \n \n
  1509. *
  1510. * In non-OS environment, It can be just implemented by disabling whole interrupt.\n
  1511. * In OS environment, You can replace it to critical section api supported by OS.
  1512. *
  1513. * \sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF()
  1514. * \sa WIZCHIP_CRITICAL_EXIT()
  1515. */
  1516. #define WIZCHIP_CRITICAL_ENTER() WIZCHIP.CRIS._enter()
  1517. #ifdef _exit
  1518. #undef _exit
  1519. #endif
  1520. /**
  1521. * @brief Exit a critical section
  1522. *
  1523. * @details It is provided to protect your shared code which are executed without distribution. \n\n
  1524. *
  1525. * In non-OS environment, It can be just implemented by disabling whole interrupt. \n
  1526. * In OS environment, You can replace it to critical section api supported by OS.
  1527. *
  1528. * @sa WIZCHIP_READ(), WIZCHIP_WRITE(), WIZCHIP_READ_BUF(), WIZCHIP_WRITE_BUF()
  1529. * @sa WIZCHIP_CRITICAL_ENTER()
  1530. */
  1531. #define WIZCHIP_CRITICAL_EXIT() WIZCHIP.CRIS._exit()
  1532. ////////////////////////
  1533. // Basic I/O Function //
  1534. ////////////////////////
  1535. //
  1536. //M20150601 : uint16_t AddrSel --> uint32_t AddrSel
  1537. //
  1538. /**
  1539. * @ingroup Basic_IO_function_W5100S
  1540. * @brief It reads 1 byte value from a register.
  1541. * @param AddrSel Register address
  1542. * @return The value of register
  1543. */
  1544. uint8_t WIZCHIP_READ (uint32_t AddrSel);
  1545. /**
  1546. * @ingroup Basic_IO_function_W5100S
  1547. * @brief It writes 1 byte value to a register.
  1548. * @param AddrSel Register address
  1549. * @param wb Write data
  1550. * @return void
  1551. */
  1552. void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb );
  1553. /**
  1554. * @ingroup Basic_IO_function_W5100S
  1555. * @brief It reads sequence data from registers.
  1556. * @param AddrSel Register address
  1557. * @param pBuf Pointer buffer to read data
  1558. * @param len Data length
  1559. */
  1560. void WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
  1561. /**
  1562. * @ingroup Basic_IO_function_W5100S
  1563. * @brief It writes sequence data to registers.
  1564. * @param AddrSel Register address
  1565. * @param pBuf Pointer buffer to write data
  1566. * @param len Data length
  1567. */
  1568. void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
  1569. /////////////////////////////////
  1570. // Common Register IO function //
  1571. /////////////////////////////////
  1572. /**
  1573. * @ingroup Common_register_access_function_W5100S
  1574. * @brief Set Mode Register
  1575. * @param (uint8_t)mr The value to be set.
  1576. * @sa getMR()
  1577. */
  1578. #if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)
  1579. #define setMR(mr) WIZCHIP_WRITE(MR,mr)
  1580. #else
  1581. #define setMR(mr) (*((uint8_t*)MR) = mr)
  1582. #endif
  1583. /**
  1584. * @ingroup Common_register_access_function_W5100S
  1585. * @brief Get @ref MR.
  1586. * @return uint8_t. The value of Mode register.
  1587. * @sa setMR()
  1588. */
  1589. #if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_)
  1590. #define getMR() WIZCHIP_READ(MR)
  1591. #else
  1592. #define getMR() (*(uint8_t*)MR)
  1593. #endif
  1594. /**
  1595. * @ingroup Common_register_access_function_W5100S
  1596. * @brief Set @ref GAR.
  1597. * @param (uint8_t*)gar Pointer variable to set gateway IP address. It should be allocated 4 bytes.
  1598. * @sa getGAR()
  1599. */
  1600. #define setGAR(gar) \
  1601. WIZCHIP_WRITE_BUF(GAR,gar,4)
  1602. /**
  1603. * @ingroup Common_register_access_function_W5100S
  1604. * @brief Get @ref GAR.
  1605. * @param (uint8_t*)gar Pointer variable to get gateway IP address. It should be allocated 4 bytes.
  1606. * @sa setGAR()
  1607. */
  1608. #define getGAR(gar) \
  1609. WIZCHIP_READ_BUF(GAR,gar,4)
  1610. /**
  1611. * @ingroup Common_register_access_function_W5100S
  1612. * @brief Set @ref SUBR.
  1613. * @param (uint8_t*)subr Pointer variable to set subnet mask address. It should be allocated 4 bytes.
  1614. * @note If subr is null pointer, set the backup subnet to SUBR. \n
  1615. * If subr is 0.0.0.0, back up SUBR and clear it. \n
  1616. * Otherwize, set subr to SUBR
  1617. * @sa getSUBR()
  1618. */
  1619. #define setSUBR(subr) \
  1620. WIZCHIP_WRITE_BUF(SUBR,subr,4)
  1621. /**
  1622. * @ingroup Common_register_access_function_W5100S
  1623. * @brief Get @ref SUBR.
  1624. * @param (uint8_t*)subr Pointer variable to get subnet mask address. It should be allocated 4 bytes.
  1625. * @sa setSUBR()
  1626. */
  1627. #define getSUBR(subr) \
  1628. WIZCHIP_READ_BUF(SUBR, subr, 4)
  1629. /**
  1630. * @ingroup Common_register_access_function_W5100S
  1631. * @brief Set @ref SHAR.
  1632. * @param (uint8_t*)shar Pointer variable to set local MAC address. It should be allocated 6 bytes.
  1633. * @sa getSHAR()
  1634. */
  1635. #define setSHAR(shar) \
  1636. WIZCHIP_WRITE_BUF(SHAR, shar, 6)
  1637. /**
  1638. * @ingroup Common_register_access_function_W5100S
  1639. * @brief Get @ref SHAR.
  1640. * @param (uint8_t*)shar Pointer variable to get local MAC address. It should be allocated 6 bytes.
  1641. * @sa setSHAR()
  1642. */
  1643. #define getSHAR(shar) \
  1644. WIZCHIP_READ_BUF(SHAR, shar, 6)
  1645. /**
  1646. * @ingroup Common_register_access_function_W5100S
  1647. * @brief Set @ref SIPR.
  1648. * @param (uint8_t*)sipr Pointer variable to set local IP address. It should be allocated 4 bytes.
  1649. * @sa getSIPR()
  1650. */
  1651. #define setSIPR(sipr) \
  1652. WIZCHIP_WRITE_BUF(SIPR, sipr, 4)
  1653. /**
  1654. * @ingroup Common_register_access_function_W5100S
  1655. * @brief Get @ref SIPR.
  1656. * @param (uint8_t*)sipr Pointer variable to get local IP address. It should be allocated 4 bytes.
  1657. * @sa setSIPR()
  1658. */
  1659. #define getSIPR(sipr) \
  1660. WIZCHIP_READ_BUF(SIPR, sipr, 4)
  1661. /**
  1662. * @ingroup Common_register_access_function_W5100S
  1663. * @brief Set \ref IR register
  1664. * @param (uint8_t)ir Value to set \ref IR register.
  1665. * @sa getIR()
  1666. */
  1667. #define setIR(ir) \
  1668. WIZCHIP_WRITE(IR, (ir & 0xE0)) //peter 2016.11.07 unreachable interrupt bit added
  1669. //WIZCHIP_WRITE(IR, (ir & 0xA0))
  1670. /**
  1671. * @ingroup Common_register_access_function_W5100S
  1672. * @brief Get \ref IR register
  1673. * @return uint8_t. Value of \ref IR register.
  1674. * @sa setIR()
  1675. */
  1676. #define getIR() \
  1677. (WIZCHIP_READ(IR) & 0xE0) //peter 2016.11.07 unreachable interrupt bit added
  1678. //(WIZCHIP_READ(IR) & 0xA0)
  1679. /**
  1680. * @ingroup Common_register_access_function_W5100S
  1681. * @brief Set \ref _IMR_ register
  1682. * @param (uint8_t)imr Value to set @ref _IMR_ register.
  1683. * @sa getIMR()
  1684. */
  1685. #define setIMR(imr) \
  1686. WIZCHIP_WRITE(_IMR_, imr)
  1687. /**
  1688. * @ingroup Common_register_access_function_W5100S
  1689. * @brief Get \ref _IMR_ register
  1690. * @return uint8_t. Value of @ref _IMR_ register.
  1691. * @sa setIMR()
  1692. */
  1693. #define getIMR() \
  1694. WIZCHIP_READ(_IMR_)
  1695. /**
  1696. * @ingroup Common_register_access_function_W5100S
  1697. * @brief Set \ref _RTR_ register
  1698. * @param (uint16_t)rtr Value to set @ref _RTR_ register.
  1699. * @sa getRTR()
  1700. */
  1701. #define setRTR(rtr) {\
  1702. WIZCHIP_WRITE(_RTR_, (uint8_t)(rtr >> 8)); \
  1703. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(_RTR_,1), (uint8_t) rtr); \
  1704. }
  1705. /**
  1706. * @ingroup Common_register_access_function_W5100S
  1707. * @brief Get \ref _RTR_ register
  1708. * @return uint16_t. Value of @ref _RTR_ register.
  1709. * @sa setRTR()
  1710. */
  1711. #define getRTR() \
  1712. (((uint16_t)WIZCHIP_READ(_RTR_) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(_RTR_,1)))
  1713. /**
  1714. * @ingroup Common_register_access_function_W5100S
  1715. * @brief Set \ref _RCR_ register
  1716. * @param (uint8_t)rcr Value to set @ref _RCR_ register.
  1717. * @sa getRCR()
  1718. */
  1719. #define setRCR(rcr) \
  1720. WIZCHIP_WRITE(_RCR_, rcr)
  1721. /**
  1722. * @ingroup Common_register_access_function_W5100S
  1723. * @brief Get \ref _RCR_ register
  1724. * @return uint8_t. Value of @ref _RCR_ register.
  1725. * @sa setRCR()
  1726. */
  1727. #define getRCR() \
  1728. WIZCHIP_READ(_RCR_)
  1729. /**
  1730. * @ingroup Common_register_access_function_W5100S
  1731. * @brief Get \ref RMSR register
  1732. * @sa getRMSR()
  1733. */
  1734. #define setRMSR(rmsr) \
  1735. WIZCHIP_WRITE(RMSR,rmsr) // Receicve Memory Size
  1736. /**
  1737. * @ingroup Common_register_access_function_W5100S
  1738. * @brief Get \ref RMSR register
  1739. * @return uint8_t. Value of @ref RMSR register.
  1740. * @sa setRMSR()
  1741. */
  1742. #define getRMSR() \
  1743. WIZCHIP_READ(RMSR) // Receicve Memory Size
  1744. /**
  1745. * @ingroup Common_register_access_function_W5100S
  1746. * @brief Get \ref TMSR register
  1747. * @sa getTMSR()
  1748. */
  1749. #define setTMSR(tmsr) \
  1750. WIZCHIP_WRITE(TMSR,tmsr) // Receicve Memory Size
  1751. /**
  1752. * @ingroup Common_register_access_function_W5100S
  1753. * @brief Get \ref TMSR register
  1754. * @return uint8_t. Value of @ref TMSR register.
  1755. * @sa setTMSR()
  1756. */
  1757. #define getTMSR() \
  1758. WIZCHIP_READ(TMSR)
  1759. /**
  1760. * @ingroup Common_register_access_function_W5100S
  1761. * @brief Get \ref PATR register
  1762. * @return uint16_t. Value to set \ref PATR register
  1763. */
  1764. #define getPATR() \
  1765. (((uint16_t)WIZCHIP_READ(PATR) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(PATR,1)))
  1766. /**
  1767. * @ingroup Common_register_access_function_W5100S
  1768. * @brief Get \ref PPPALGO register
  1769. * @return uint8_t. Value to set \ref PPPALGO register
  1770. */
  1771. #define getPPPALGO() \
  1772. WIZCHIP_READ(PPPALGO)
  1773. /**
  1774. * @ingroup Common_register_access_function_W5100S
  1775. * @brief Set \ref PTIMER register
  1776. * @param (uint8_t)ptimer Value to set \ref PTIMER register.
  1777. * @sa getPTIMER()
  1778. */
  1779. #define setPTIMER(ptimer) \
  1780. WIZCHIP_WRITE(PTIMER, ptimer)
  1781. /**
  1782. * @ingroup Common_register_access_function_W5100S
  1783. * @brief Get \ref PTIMER register
  1784. * @return uint8_t. Value of @ref PTIMER register.
  1785. * @sa setPTIMER()
  1786. */
  1787. #define getPTIMER() \
  1788. WIZCHIP_READ(PTIMER)
  1789. /**
  1790. * @ingroup Common_register_access_function_W5100S
  1791. * @brief Set \ref PMAGIC register
  1792. * @param (uint8_t)pmagic Value to set @ref PMAGIC register.
  1793. * @sa getPMAGIC()
  1794. */
  1795. #define setPMAGIC(pmagic) \
  1796. WIZCHIP_WRITE(PMAGIC, pmagic)
  1797. /**
  1798. * @ingroup Common_register_access_function_W5100S
  1799. * @brief Get \ref PMAGIC register
  1800. * @return uint8_t. Value of @ref PMAGIC register.
  1801. * @sa setPMAGIC()
  1802. */
  1803. #define getPMAGIC() \
  1804. WIZCHIP_READ(PMAGIC)
  1805. //todo Functions for W5100S
  1806. /*----------------------------------------------------------------------*/
  1807. /* W5100S only */
  1808. /*----------------------------------------------------------------------*/
  1809. /**
  1810. * @ingroup Common_register_access_function_W5100S
  1811. * @brief Set \ref IR2 register
  1812. * @param (uint8_t)ir2 Value to set @ref IR2 register.
  1813. * @sa getIR2()
  1814. */
  1815. #define setIR2(ir2) \
  1816. WIZCHIP_WRITE(IR2, ir2)
  1817. /**
  1818. * @ingroup Common_register_access_function_W5100S
  1819. * @brief Get \ref IR2 register
  1820. * @return uint8_t. Value of @ref IR2 register.
  1821. * @sa setIR2()
  1822. */
  1823. #define getIR2() \
  1824. WIZCHIP_READ(IR2)
  1825. /**
  1826. * @ingroup Common_register_access_function_W5100S
  1827. * @brief Set \ref IMR2 register
  1828. * @param (uint8_t)imr2 Value to set @ref IMR2 register.
  1829. * @sa setIMR2()
  1830. */
  1831. #define setIMR2(imr2) \
  1832. WIZCHIP_WRITE(IMR2,imr2)
  1833. /**
  1834. * @ingroup Common_register_access_function_W5100S
  1835. * @brief Get \ref IMR2 register
  1836. * @return uint8_t. Value of @ref IMR2 register.
  1837. * @sa getIMR2()
  1838. */
  1839. #define getIMR2() \
  1840. WIZCHIP_READ(IMR2)
  1841. /**
  1842. * @ingroup Common_register_access_function_W5100S
  1843. * @brief Set \ref UIPR(Unreachable IP Address Register) registers
  1844. * @param (uint8_t*)uipr Value to set @ref UIPR registers.
  1845. * @sa setUIPR()
  1846. */
  1847. #define setUIPR(uipr) \
  1848. WIZCHIP_WRITE_BUF(UIPR,uipr,4)
  1849. /**
  1850. * @ingroup Common_register_access_function_W5100S
  1851. * @brief Get \ref UIPR(Unreachable IP Address Register) registers
  1852. * @param (uint8_t*)uipr Value to get @ref UIPR registers
  1853. * @sa setUIPR()
  1854. */
  1855. #define getUIPR(uipr) \
  1856. WIZCHIP_READ_BUF(UIPR,uipr,4)
  1857. /**
  1858. * @ingroup Common_register_access_function_W5100S
  1859. * @brief Set \ref UPORTR(Unreachable Port Address Register) register
  1860. * @param (uint16_t)uportr Value to set @ref UPORTR register.
  1861. * @sa getUPORTR()
  1862. */
  1863. #define setUPORTR(uportr) {\
  1864. WIZCHIP_WRITE(UPORTR, (uint8_t)(uportr >> 8)); \
  1865. WIZCHIP_WRITE(UPORTR+1, (uint8_t) uportr); \
  1866. }
  1867. /**
  1868. * @ingroup Common_register_access_function_W5100S
  1869. * @brief Get \ref UPORTR(Unreachable Port Address Register) register
  1870. * @return uint16_t. Value of @ref UPORTR register.
  1871. * @sa setUPORTR()
  1872. */
  1873. #define getUPORTR() \
  1874. (((uint16_t)WIZCHIP_READ(UPORTR) << 8) + WIZCHIP_READ(UPORTR+1))
  1875. /**
  1876. * @ingroup Common_register_access_function_W5100S
  1877. * @brief Set \ref MR2 register
  1878. * @param (uint8_t)mr2 Value to set @ref MR2 registers.
  1879. * @sa getMR2()
  1880. */
  1881. #define setMR2(mr2) \
  1882. WIZCHIP_WRITE(MR2,mr2)
  1883. /**
  1884. * @ingroup Common_register_access_function_W5100S
  1885. * @brief Get \ref MR2 register
  1886. * @return uint8_t. Value of @ref MR2 register.
  1887. * @sa setMR2()
  1888. */
  1889. #define getMR2() \
  1890. WIZCHIP_READ(MR2)
  1891. /**
  1892. * @ingroup Common_register_access_function_W5100S
  1893. * @brief Set \ref PHAR registers
  1894. * @param (uint8_t*)phar Value to set @ref PHAR registers.
  1895. * @sa getPHAR()
  1896. */
  1897. #define setPHAR(phar) \
  1898. WIZCHIP_WRITE_BUF(PHAR,phar,6)
  1899. /**
  1900. * @ingroup Common_register_access_function_W5100S
  1901. * @brief Get \ref PHAR registers
  1902. * @param (uint8_t*)phar Pointer variable to get @ref PHAR registers.
  1903. * @sa setPHAR()
  1904. */
  1905. #define getPHAR(phar) \
  1906. WIZCHIP_READ_BUF(PHAR,phar,6)
  1907. /**
  1908. * @ingroup Common_register_access_function_W5100S
  1909. * @brief Set \ref PSIDR register
  1910. * @param (uint16_t)psidr Value to set @ref PSIDR register.
  1911. * @sa getPSIDR()
  1912. */
  1913. #define setPSIDR(psidr) {\
  1914. WIZCHIP_WRITE(PSIDR, (uint8_t)(psidr >> 8)); \
  1915. WIZCHIP_WRITE(PSIDR+1, (uint8_t) psidr); \
  1916. }
  1917. /**
  1918. * @ingroup Common_register_access_function_W5100S
  1919. * @brief Get \ref PSIDR register
  1920. * @return uint16_t. Value of @ref PSIDR register.
  1921. * @sa setPSIDR()
  1922. */
  1923. #define getPSIDR() \
  1924. (((uint16_t)WIZCHIP_READ(PSIDR) << 8) + WIZCHIP_READ(PSIDR+1))
  1925. /**
  1926. * @ingroup Common_register_access_function_W5100S
  1927. * @brief Set \ref PMRUR register
  1928. * @param (uint16_t)pmrur Value to set @ref PMRUR register.
  1929. * @sa getPMRUR()
  1930. */
  1931. #define setPMRUR(pmrur) {\
  1932. WIZCHIP_WRITE(PMRUR, (uint8_t)(pmrur >> 8)); \
  1933. WIZCHIP_WRITE(PMRUR+1, (uint8_t) pmrur); \
  1934. }
  1935. /**
  1936. * @ingroup Common_register_access_function_W5100S
  1937. * @brief Get \ref PMRUR register
  1938. * @return uint16_t. Value of @ref PMRUR register.
  1939. * @sa setPMRUR()
  1940. */
  1941. #define getPMRUR() \
  1942. (((uint16_t)WIZCHIP_READ(PMRUR) << 8) + WIZCHIP_READ(PMRUR+1))
  1943. /**
  1944. * @ingroup Common_register_access_function_W5100S
  1945. * @brief Get \ref PHYSR register
  1946. * @return uint8_t. Value of @ref PHYSR register.
  1947. * @sa setPHYSR()
  1948. */
  1949. #define getPHYSR() \
  1950. WIZCHIP_READ(PHYSR)
  1951. /**
  1952. * @ingroup Common_register_access_function_W5100S
  1953. * @brief Get \ref PHYSR1 register
  1954. * @return uint8_t. Value of @ref PHYSR1 register.
  1955. * @sa setPHYSR1()
  1956. */
  1957. #define getPHYSR1() \
  1958. WIZCHIP_READ(PHYSR1)
  1959. /**
  1960. * For internal uses
  1961. * The address of the PHY is fixed as "0x0A".
  1962. */
  1963. #define getPHYAR() \
  1964. WIZCHIP_READ(PHYAR)
  1965. /**
  1966. * @ingroup Common_register_access_function_W5100S
  1967. * @brief Get \ref PHYRAR register
  1968. * @return uint8_t. Value of @ref PHYRAR register.
  1969. * @sa setPHYRAR()
  1970. */
  1971. #define getPHYRAR() \
  1972. WIZCHIP_READ(PHYRAR)
  1973. /**
  1974. * @ingroup Common_register_access_function_W5100S
  1975. * @brief Set \ref PHYRR register
  1976. * @param (uint8_t)phyrar Value to set @ref PHYRR register.
  1977. * @sa getPHYRR()
  1978. */
  1979. #define setPHYRR(phyrar) \
  1980. WIZCHIP_WRITE(PHYRAR, phyrar)
  1981. /**
  1982. * @ingroup Common_register_access_function_W5100S
  1983. * @brief Get \ref PHYDIR register
  1984. * @return uint16_t. Value of @ref PHYDIR register.
  1985. * @sa setPHYRAR()
  1986. */
  1987. //read the value of the phy data input register
  1988. #define getPHYDIR() \
  1989. (((uint16_t)WIZCHIP_READ(PHYDIR+1) << 8) + WIZCHIP_READ(PHYDIR))
  1990. /**
  1991. * @ingroup Common_register_access_function_W5100S
  1992. * @brief Set \ref PHYDIR register
  1993. * @param (uint16_t)phydir Value to set @ref PHYDIR register.
  1994. * @sa getPHYDIR()
  1995. */
  1996. //write the value of the phy data input register
  1997. #define setPHYDIR(phydir) {\
  1998. WIZCHIP_WRITE(PHYDIR+1, (uint8_t)(phydir >> 8)); \
  1999. WIZCHIP_WRITE(PHYDIR, (uint8_t) phydir); \
  2000. }
  2001. /**
  2002. * @ingroup Common_register_access_function_W5100S
  2003. * @brief Get \ref PHYDOR register
  2004. * @return uint16_t. Value of @ref PHYDOR register.
  2005. * @sa setPHYDOR()
  2006. */
  2007. //read the value of the phy data output register
  2008. #define getPHYDOR() \
  2009. (((uint16_t)WIZCHIP_READ(PHYDOR+1) << 8) + WIZCHIP_READ(PHYDOR))
  2010. /**
  2011. * @ingroup Common_register_access_function_W5100S
  2012. * @brief Set \ref PHYDOR register
  2013. * @param (uint16_t)phydor Value to set @ref PHYDOR register.
  2014. * @sa getPHYDOR()
  2015. */
  2016. //write the value of the phy data output register
  2017. #define setPHYDOR(phydor) {\
  2018. WIZCHIP_WRITE(PHYDOR, (uint8_t)(phydor >> 8)); \
  2019. WIZCHIP_WRITE(PHYDOR+1, (uint8_t) phydor); \
  2020. }
  2021. /**
  2022. * @ingroup Common_register_access_function_W5100S
  2023. * @brief Get \ref PHYACR register
  2024. * @return uint8_t. Value of @ref PHYACR register.
  2025. * @sa setPHYACR()
  2026. */
  2027. //read the value of the phy action register ***This register will be cleared automatically***
  2028. #define getPHYACR() \
  2029. WIZCHIP_READ(PHYACR)
  2030. /**
  2031. * @ingroup Common_register_access_function_W5100S
  2032. * @brief Set \ref PHYACR register
  2033. * @param (uint8_t)phyacr Value to set @ref PHYACR register.
  2034. * @sa getPHYACR()
  2035. */
  2036. //write the value of the phy action register
  2037. #define setPHYACR(phyacr) \
  2038. WIZCHIP_WRITE(PHYACR,phyacr)
  2039. /**
  2040. * @ingroup Common_register_access_function_W5100S
  2041. * @brief Set \ref PHYDIVR register
  2042. * @param (uint8_t)phydivr Value to set @ref PHYDIVR register.
  2043. * @sa getPHYDIVR()
  2044. */
  2045. #define setPHYDIVR(phydivr) \
  2046. WIZCHIP_WRITE(PHYDIVR, phydivr)
  2047. /**
  2048. * @ingroup Common_register_access_function_W5100S
  2049. * @brief Get \ref PHYDIVR register
  2050. * @return uint8_t. Value of @ref PHYDIVR register.
  2051. * @sa setPHYDIVR()
  2052. */
  2053. #define getPHYDIVR() \
  2054. WIZCHIP_READ(PHYDIVR)
  2055. /**
  2056. * @ingroup Common_register_access_function_W5100S
  2057. * @brief Set \ref PHYCR0 register
  2058. * @param (uint8_t)phych0 Value to set @ref PHYCR0 register.
  2059. * @sa getPHYCR0()
  2060. */
  2061. #define setPHYCR0(phych0) \
  2062. WIZCHIP_WRITE(PHYCR0,phych0)
  2063. /**
  2064. * @ingroup Common_register_access_function_W5100S
  2065. * @brief Get \ref PHYCR0 register
  2066. * @return uint8_t. Value of @ref PHYCR0 register.
  2067. * @sa setPHYCR0()
  2068. */
  2069. #define getPHYCR0() \
  2070. WIZCHIP_READ(PHYCR0)
  2071. /**
  2072. * @ingroup Common_register_access_function_W5100S
  2073. * @brief Set \ref PHYCR1 register
  2074. * @param (uint8_t)phycr1 Value to set @ref PHYCR1 register.
  2075. * @sa getPHYCR1()
  2076. */
  2077. #define setPHYCR1(phycr1) \
  2078. WIZCHIP_WRITE(PHYCR1,phycr1)
  2079. /**
  2080. * @ingroup Common_register_access_function_W5100S
  2081. * @brief Get \ref PHYCR1 register
  2082. * @return uint8_t. Value of @ref PHYCR1 register.
  2083. * @sa setPHYCR1()
  2084. */
  2085. #define getPHYCR1() \
  2086. WIZCHIP_READ(PHYCR1)
  2087. /**
  2088. * @ingroup Common_register_access_function_W5100S
  2089. * @brief Set \ref SLCR register
  2090. * @param (uint8_t)rqcr Value to set @ref SLCR register.
  2091. * @sa getSLCR()
  2092. */
  2093. #define setSLCR(rqcr) \
  2094. WIZCHIP_WRITE(SLCR, rqcr)
  2095. /**
  2096. * @ingroup Common_register_access_function_W5100S
  2097. * @brief Get \ref RQCR register
  2098. * @return uint8_t. Value of @ref RQCR register.
  2099. * @sa setRQCR()
  2100. */
  2101. #define getSLCR() \
  2102. WIZCHIP_READ(RQCR)
  2103. /**
  2104. * @ingroup Common_register_access_function_W5100S
  2105. * @brief Set \ref SLRTR register
  2106. * @param (uint16_t)slrtr Value to set @ref SLRTR register.
  2107. * @sa getSLRTR()
  2108. */
  2109. #define setSLRTR(slrtr) \
  2110. WIZCHIP_WRITE(SLRTR, (uint8_t)(slrtr >> 8)); \
  2111. WIZCHIP_WRITE(SLRTR+1, (uint8_t) slrtr); \
  2112. /**
  2113. * @ingroup Common_register_access_function_W5100S
  2114. * @brief Get \ref SLRTR register
  2115. * @return uint16_t. Value of @ref SLRTR register.
  2116. * @sa setSLRTR()
  2117. */
  2118. #define getSLRTR() \
  2119. (((uint16_t)WIZCHIP_READ(SLRTR) << 8) + WIZCHIP_READ(SLRTR+1))
  2120. /**
  2121. * @ingroup Common_register_access_function_W5100S
  2122. * @brief Set \ref SLRCR register
  2123. * @param (uint8_t)slrcr Value to set @ref SLRCR register.
  2124. * @sa getSLRCR()
  2125. */
  2126. #define setSLRCR(slrcr) \
  2127. WIZCHIP_WRITE(SLRCR,slrcr)
  2128. /**
  2129. * @ingroup Common_register_access_function_W5100S
  2130. * @brief Get \ref SLRCR register
  2131. * @return uint8_t. Value of @ref SLRCR register.
  2132. * @sa setSLRCR()
  2133. */
  2134. #define getSLRCR() \
  2135. WIZCHIP_READ(SLRCR)
  2136. /**
  2137. * @ingroup Common_register_access_function_W5100S
  2138. * @brief Set \ref SLPIPR registers
  2139. * @param (uint8_t*)slpipr Values to set @ref SLPIPR registers.
  2140. * @sa getSLPIPR()
  2141. */
  2142. #define setSLPIPR(slpipr) \
  2143. WIZCHIP_WRITE_BUF(SLPIPR,slpipr,4)
  2144. /**
  2145. * @ingroup Common_register_access_function_W5100S
  2146. * @brief Get \ref SLPIPR registers
  2147. * @param (uint8_t*)slpipr Values to get @ref SLPIPR registers.
  2148. * @sa getSLPIPR()
  2149. */
  2150. #define getSLPIPR(slpipr) \
  2151. WIZCHIP_READ_BUF(SLPIPR,slpipr,4)
  2152. /**
  2153. * @ingroup Common_register_access_function_W5100S
  2154. * @brief Get \ref SLPHAR registers
  2155. * @param (uint8_t*)slphar Values to set @ref SLPHAR registers.
  2156. * @sa getSLPHAR()
  2157. */
  2158. #define setSLPHAR(slphar) \
  2159. WIZCHIP_WRITE_BUF(SLPHAR,slphar,6)
  2160. /**
  2161. * @ingroup Common_register_access_function_W5100S
  2162. * @brief Get \ref SLPHAR registers
  2163. * @param (uint8_t*)slphar Values to get @ref SLPHAR registers.
  2164. * @sa getSLPHAR()
  2165. */
  2166. #define getSLPHAR(slphar) \
  2167. WIZCHIP_READ_BUF(SLPHAR,slphar,6)
  2168. /**
  2169. * @ingroup Common_register_access_function_W5100S
  2170. * @brief Set \ref PINGSEQR register
  2171. * @param (uint16_t)pingseqr Value to set @ref PINGSEQR register.
  2172. * @sa getPINGSEQR()
  2173. */
  2174. #define setPINGSEQR(pingseqr) {\
  2175. WIZCHIP_WRITE(PINGSEQR, (uint8_t)(pingseqr >> 8)); \
  2176. WIZCHIP_WRITE(PINGSEQR+1, (uint8_t) pingseqr); \
  2177. }
  2178. /**
  2179. * @ingroup Common_register_access_function_W5100S
  2180. * @brief Get \ref PINGSEQR register
  2181. * @return uint16_t. Value of @ref PINGSEQR register.
  2182. * @sa setPINGSEQR()
  2183. */
  2184. #define getPINGSEQR() \
  2185. (((uint16_t)WIZCHIP_READ(PINGSEQR) << 8) + WIZCHIP_READ(PINGSEQR+1))
  2186. /**
  2187. * @ingroup Common_register_access_function_W5100S
  2188. * @brief Set \ref PINGIDR register
  2189. * @param (uint16_t)pingidr Value to set @ref PINGIDR register.
  2190. * @sa getPINGIDR()
  2191. */
  2192. #define setPINGIDR(pingidr) {\
  2193. WIZCHIP_WRITE(PINGIDR, (uint8_t)(pingidr >> 8)); \
  2194. WIZCHIP_WRITE(PINGIDR+1, (uint8_t) pingidr); \
  2195. }
  2196. /**
  2197. * @ingroup Common_register_access_function_W5100S
  2198. * @brief Get \ref PINGIDR register
  2199. * @return uint16_t. Value of @ref PINGIDR register.
  2200. * @sa setPINGIDR()
  2201. */
  2202. #define getPINGIDR() \
  2203. (((uint16_t)WIZCHIP_READ(PINGIDR) << 8) + WIZCHIP_READ(PINGIDR+1))
  2204. /**
  2205. * @ingroup Common_register_access_function_W5100S
  2206. * @brief Set \ref SLIMR register
  2207. * @param (uint8_t)slimr Value to set @ref SLIMR register.
  2208. * @sa getSLIMR()
  2209. */
  2210. #define setSLIMR(slimr) \
  2211. WIZCHIP_WRITE(SLIMR, slimr)
  2212. /**
  2213. * @ingroup Common_register_access_function_W5100S
  2214. * @brief Get \ref SLIMR register
  2215. * @return uint8_t. Value of @ref SLIMR register.
  2216. * @sa setSLIMR()
  2217. */
  2218. #define getSLIMR() \
  2219. WIZCHIP_READ(SLIMR)
  2220. /**
  2221. * @ingroup Common_register_access_function_W5100S
  2222. * @brief Set \ref SLIR register
  2223. * @param (uint8_t)slir Value to set @ref SLIR register.
  2224. * @sa getSLIMR()
  2225. */
  2226. #define setSLIR(slir) \
  2227. WIZCHIP_WRITE(SLIR, slir)
  2228. /**
  2229. * @ingroup Common_register_access_function_W5100S
  2230. * @brief Get \ref SLIMR register
  2231. * @return uint8_t. Value of @ref SLIMR register.
  2232. * @sa setSLIMR()
  2233. */
  2234. #define getSLIR() \
  2235. WIZCHIP_READ(SLIR)
  2236. /*Hidden functions for W5100S*/
  2237. #define setDBGOUT(dbgout) {\
  2238. WIZCHIP_WRITE(DBGOUT,(uint8_t)(dbgout >> 16)); \
  2239. WIZCHIP_WRITE(DBGOUT,(uint8_t)(dbgout >> 8)); \
  2240. WIZCHIP_WRITE(DBGOUT,(uint8_t)(dbgout)); \
  2241. }
  2242. /**
  2243. * @ingroup Common_register_access_function_W5100S
  2244. * @brief Set \ref NICMAXCOLR register
  2245. * @param (uint8_t)nicmaxcolr Value to set @ref NICMAXCOLR register.
  2246. * @sa getNICMAXCOLR()
  2247. */
  2248. #define setNICMAXCOLR(nicmaxcolr) \
  2249. WIZCHIP_WRITE(NICMAXCOLR,nicmaxcolr)
  2250. /**
  2251. * @ingroup Common_register_access_function_W5100S
  2252. * @brief Get \ref NICMAXCOLR register
  2253. * @return uint8_t. Value of @ref NICMAXCOLR register.
  2254. * @sa setNICMAXCOLR()
  2255. */
  2256. #define getNICMAXCOLR() \
  2257. WIZCHIP_READ(NICMAXCOLR)
  2258. /*Clock lock/unlock*/
  2259. /**
  2260. * @ingroup Common_register_access_function_W5100S
  2261. * @brief LOCK Chip Information
  2262. * @sa CHIPULLOCK()
  2263. */
  2264. #define CHIPLOCK() \
  2265. WIZCHIP_WRITE(CHIPLCKR,0xff)
  2266. /**
  2267. * @ingroup Common_register_access_function_W5100S
  2268. * @brief Unlock Chip Information
  2269. * @sa CHIPLOCK()
  2270. */
  2271. #define CHIPUNLOCK() \
  2272. WIZCHIP_WRITE(CHIPLCKR,0xCE)
  2273. /**
  2274. * @ingroup Common_register_access_function_W5100S
  2275. * @brief LOCK Chip Information
  2276. * @sa CHIPULLOCK()
  2277. */
  2278. /*Network information lock/unlock*/
  2279. #define NETLOCK() \
  2280. WIZCHIP_WRITE(NETLCKR,0x3A)
  2281. /**
  2282. * @ingroup Common_register_access_function_W5100S
  2283. * @brief Unlock Chip Information
  2284. * @sa CHIPLOCK()
  2285. */
  2286. #define NETUNLOCK() \
  2287. WIZCHIP_WRITE(NETLCKR,0xC5)
  2288. /**
  2289. * @ingroup Common_register_access_function_W5100S
  2290. * @brief Lock PHYCR0,CR1 Information
  2291. * @sa CHIPULLOCK()
  2292. */
  2293. /*PHY CR0,CR1 lock/unlock*/
  2294. #define PHYLOCK() \
  2295. WIZCHIP_WRITE(PHYLCKR,0xff)
  2296. /**
  2297. * @ingroup Common_register_access_function_W5100S
  2298. * @brief Lock PHYCR0,CR1 Information
  2299. * @sa CHIPULLOCK()
  2300. */
  2301. #define PHYUNLOCK() \
  2302. WIZCHIP_WRITE(PHYLCKR,0x53)
  2303. /**
  2304. * @ingroup Version register_access_function_W5100SS
  2305. * @brief Get version information.
  2306. * @return uint16_t. It must be "0x51"
  2307. */
  2308. #define getVER() \
  2309. (WIZCHIP_READ(VERR))
  2310. /**
  2311. * @ingroup Common_register_access_function_W5100S
  2312. * @brief Get \ref TCNTR register
  2313. * @return uint16_t. Value of @ref TCNTR register.
  2314. * @sa setNTCNTR()
  2315. */
  2316. /*Get 100us internal counter*/
  2317. #define getTCNTR() \
  2318. (((uint16_t)WIZCHIP_READ(TCNTR) << 8) + WIZCHIP_READ(TCNTR+1))
  2319. /**
  2320. * @ingroup Common_register_access_function_W5100S
  2321. * @brief Set \ref TCNTR register
  2322. * @param (uint8_t)
  2323. Value to set @ref TCNTR register.
  2324. * @sa getTCNTCLKR()
  2325. */
  2326. /*Reset 100us internal counter(TCNTR)*/
  2327. #define setTCNTCLKR(var) \
  2328. WIZCHIP_WRITE(TCNTCLKR, var)
  2329. /*w5100s only end*/
  2330. ///////////////////////////////////
  2331. // Socket N register I/O function //
  2332. ///////////////////////////////////
  2333. /**
  2334. * @ingroup Socket_register_access_function_W5100S
  2335. * @brief Set @ref Sn_MR register
  2336. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b> expect <b>bit 4</b>.
  2337. * @param mr Value to set @ref Sn_MR
  2338. * @sa getSn_MR()
  2339. */
  2340. #define setSn_MR(sn, mr) \
  2341. WIZCHIP_WRITE(Sn_MR(sn),mr)
  2342. /**
  2343. * @ingroup Socket_register_access_function_W5100S
  2344. * @brief Get @ref Sn_MR register
  2345. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b> expect <b>bit 4</b>.
  2346. * @return Value of @ref Sn_MR.
  2347. * @sa setSn_MR()
  2348. */
  2349. #define getSn_MR(sn) \
  2350. WIZCHIP_READ(Sn_MR(sn))
  2351. /**
  2352. * @ingroup Socket_register_access_function_W5100S
  2353. * @brief Set @ref Sn_CR register
  2354. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2355. * @param (uint8_t)cr Value to set @ref Sn_CR
  2356. * @sa getSn_CR()
  2357. */
  2358. #define setSn_CR(sn, cr) \
  2359. WIZCHIP_WRITE(Sn_CR(sn), cr)
  2360. /**
  2361. * @ingroup Socket_register_access_function_W5100S
  2362. * @brief Get @ref Sn_CR register
  2363. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2364. * @return uint8_t. Value of @ref Sn_CR.
  2365. * @sa setSn_CR()
  2366. */
  2367. #define getSn_CR(sn) \
  2368. WIZCHIP_READ(Sn_CR(sn))
  2369. /**
  2370. * @ingroup Socket_register_access_function_W5100S
  2371. * @brief Set @ref Sn_IR register
  2372. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2373. * @param (uint8_t)ir Value to set @ref Sn_IR
  2374. * @sa getSn_IR()
  2375. */
  2376. #define setSn_IR(sn, ir) \
  2377. WIZCHIP_WRITE(Sn_IR(sn), ir)
  2378. /**
  2379. * @ingroup Socket_register_access_function_W5100S
  2380. * @brief Get @ref Sn_IR register
  2381. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2382. * @return uint8_t. Value of @ref Sn_IR.
  2383. * @sa setSn_IR()
  2384. */
  2385. #define getSn_IR(sn) \
  2386. WIZCHIP_READ(Sn_IR(sn))
  2387. /**
  2388. * @ingroup Socket_register_access_function_W5100S
  2389. * @brief Get @ref Sn_SR register
  2390. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2391. * @return uint8_t. Value of @ref Sn_SR.
  2392. */
  2393. #define getSn_SR(sn) \
  2394. WIZCHIP_READ(Sn_SR(sn))
  2395. /**
  2396. * @ingroup Socket_register_access_function_W5100S
  2397. * @brief Set @ref Sn_PORT register
  2398. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2399. * @param (uint16_t)port Value to set @ref Sn_PORT.
  2400. * @sa getSn_PORT()
  2401. */
  2402. #define setSn_PORT(sn, port) { \
  2403. WIZCHIP_WRITE(Sn_PORT(sn), (uint8_t)(port >> 8)); \
  2404. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1), (uint8_t) port); \
  2405. }
  2406. /**
  2407. * @ingroup Socket_register_access_function_W5100S
  2408. * @brief Get @ref Sn_PORT register
  2409. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2410. * @return uint16_t. Value of @ref Sn_PORT.
  2411. * @sa setSn_PORT()
  2412. */
  2413. #define getSn_PORT(sn) \
  2414. (((uint16_t)WIZCHIP_READ(Sn_PORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_PORT(sn),1)))
  2415. /**
  2416. * @ingroup Socket_register_access_function_W5100S
  2417. * @brief Set @ref Sn_DHAR register
  2418. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2419. * @param (uint8_t*)dhar Pointer variable to set socket n destination hardware address. It should be allocated 6 bytes.
  2420. * @sa getSn_DHAR()
  2421. */
  2422. #define setSn_DHAR(sn, dhar) \
  2423. WIZCHIP_WRITE_BUF(Sn_DHAR(sn), dhar, 6)
  2424. /**
  2425. * @ingroup Socket_register_access_function_W5100S
  2426. * @brief Get @ref Sn_DHAR register
  2427. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2428. * @param (uint8_t*)dhar Pointer variable to get socket n destination hardware address. It should be allocated 6 bytes.
  2429. * @sa setSn_DHAR()
  2430. */
  2431. #define getSn_DHAR(sn, dhar) \
  2432. WIZCHIP_READ_BUF(Sn_DHAR(sn), dhar, 6)
  2433. /**
  2434. * @ingroup Socket_register_access_function_W5100S
  2435. * @brief Set @ref Sn_DIPR register
  2436. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2437. * @param (uint8_t*)dipr Pointer variable to set socket n destination IP address. It should be allocated 4 bytes.
  2438. * @sa getSn_DIPR()
  2439. */
  2440. #define setSn_DIPR(sn, dipr) \
  2441. WIZCHIP_WRITE_BUF(Sn_DIPR(sn), dipr, 4)
  2442. /**
  2443. * @ingroup Socket_register_access_function_W5100S
  2444. * @brief Get @ref Sn_DIPR register
  2445. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2446. * @param (uint8_t*)dipr Pointer variable to get socket n destination IP address. It should be allocated 4 bytes.
  2447. * @sa SetSn_DIPR()
  2448. */
  2449. #define getSn_DIPR(sn, dipr) \
  2450. WIZCHIP_READ_BUF(Sn_DIPR(sn), dipr, 4)
  2451. /**
  2452. * @ingroup Socket_register_access_function_W5100S
  2453. * @brief Set @ref Sn_DPORT register
  2454. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2455. * @param (uint16_t)dport Value to set @ref Sn_DPORT
  2456. * @sa getSn_DPORT()
  2457. */
  2458. #define setSn_DPORT(sn, dport) { \
  2459. WIZCHIP_WRITE(Sn_DPORT(sn), (uint8_t) (dport>>8)); \
  2460. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1), (uint8_t) dport); \
  2461. }
  2462. /**
  2463. * @ingroup Socket_register_access_function_W5100S
  2464. * @brief Get @ref Sn_DPORT register
  2465. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2466. * @return uint16_t. Value of @ref Sn_DPORT.
  2467. * @sa setSn_DPORT()
  2468. */
  2469. #define getSn_DPORT(sn) \
  2470. (((uint16_t)WIZCHIP_READ(Sn_DPORT(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_DPORT(sn),1)))
  2471. /**
  2472. * @ingroup Socket_register_access_function_W5100S
  2473. * @brief Set @ref Sn_MSSR register
  2474. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2475. * @param (uint16_t)mss Value to set @ref Sn_MSSR
  2476. * @sa setSn_MSSR()
  2477. */
  2478. #define setSn_MSSR(sn, mss) { \
  2479. WIZCHIP_WRITE(Sn_MSSR(sn), (uint8_t)(mss>>8)); \
  2480. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1), (uint8_t) mss); \
  2481. }
  2482. /**
  2483. * @ingroup Socket_register_access_function_W5100S
  2484. * @brief Get @ref Sn_MSSR register
  2485. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2486. * @return uint16_t. Value of @ref Sn_MSSR.
  2487. * @sa setSn_MSSR()
  2488. */
  2489. #define getSn_MSSR(sn) \
  2490. (((uint16_t)WIZCHIP_READ(Sn_MSSR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_MSSR(sn),1)))
  2491. /**
  2492. * @ingroup Socket_register_access_function_W5100S
  2493. * @brief Set @ref Sn_PROTO register
  2494. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2495. * @param (uint8_t)proto Value to set \ref Sn_PROTO
  2496. * @sa getSn_PROTO()
  2497. */
  2498. #define setSn_PROTO(sn, proto) \
  2499. WIZCHIP_WRITE(Sn_PROTO(sn), proto)
  2500. /**
  2501. * @ingroup Socket_register_access_function_W5100S
  2502. * @brief Get @ref Sn_PROTO register
  2503. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2504. * @return uint8_t. Value of @ref Sn_PROTO.
  2505. * @sa setSn_PROTO()
  2506. */
  2507. #define getSn_PROTO(sn) \
  2508. WIZCHIP_READ(Sn_PROTO(sn))
  2509. /**
  2510. * @ingroup Socket_register_access_function_W5100S
  2511. * @brief Set @ref Sn_TOS register
  2512. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2513. * @param (uint8_t)tos Value to set @ref Sn_TOS
  2514. * @sa getSn_TOS()
  2515. */
  2516. #define setSn_TOS(sn, tos) \
  2517. WIZCHIP_WRITE(Sn_TOS(sn), tos)
  2518. /**
  2519. * @ingroup Socket_register_access_function_W5100S
  2520. * @brief Get @ref Sn_TOS register
  2521. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_ </b>.
  2522. * @return uint8_t. Value of Sn_TOS.
  2523. * @sa setSn_TOS()
  2524. */
  2525. #define getSn_TOS(sn) \
  2526. WIZCHIP_READ(Sn_TOS(sn))
  2527. /**
  2528. * @ingroup Socket_register_access_function_W5100S
  2529. * @brief Set @ref Sn_TTL register
  2530. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_ </b>.
  2531. * @param (uint8_t)ttl Value to set @ref Sn_TTL
  2532. * @sa getSn_TTL()
  2533. */
  2534. #define setSn_TTL(sn, ttl) \
  2535. WIZCHIP_WRITE(Sn_TTL(sn), ttl)
  2536. /**
  2537. * @ingroup Socket_register_access_function_W5100S
  2538. * @brief Get @ref Sn_TTL register
  2539. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_ </b>.
  2540. * @return uint8_t. Value of @ref Sn_TTL.
  2541. * @sa setSn_TTL()
  2542. */
  2543. #define getSn_TTL(sn) \
  2544. WIZCHIP_READ(Sn_TTL(sn))
  2545. /**
  2546. * @ingroup Socket_register_access_function_W5100S
  2547. * @brief Set @ref Sn_RXMEM_SIZE register
  2548. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_ </b>.
  2549. * @param (uint8_t)rxmemsize Value to set \ref Sn_RXMEM_SIZE
  2550. * @sa getSn_RXMEM_SIZE()
  2551. */
  2552. #define setSn_RXMEM_SIZE(sn, rxmemsize) \
  2553. WIZCHIP_WRITE(RMSR, (WIZCHIP_READ(RMSR) & ~(0x03 << (2*sn))) | (rxmemsize << (2*sn)))
  2554. #define setSn_RXBUF_SIZE(sn,rxmemsize) setSn_RXMEM_SIZE(sn,rxmemsize)
  2555. /**
  2556. * @ingroup Socket_register_access_function_W5100S
  2557. * @brief Get @ref Sn_RXMEM_SIZE register
  2558. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2559. * @return uint8_t. Value of @ref Sn_RXMEM.
  2560. * @sa setSn_RXMEM_SIZE()
  2561. */
  2562. #define getSn_RXMEM_SIZE(sn) \
  2563. ((WIZCHIP_READ(RMSR) & (0x03 << (2*sn))) >> (2*sn))
  2564. #define getSn_RXBUF_SIZE(sn) getSn_RXMEM_SIZE(sn)
  2565. /**
  2566. * @ingroup Socket_register_access_function_W5100S
  2567. * @brief Set @ref Sn_TXMEM_SIZE register
  2568. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2569. * @param (uint8_t)txmemsize Value to set \ref Sn_TXMEM_SIZE
  2570. * @sa getSn_TXMEM_SIZE()
  2571. */
  2572. #define setSn_TXMEM_SIZE(sn, txmemsize) \
  2573. WIZCHIP_WRITE(TMSR, (WIZCHIP_READ(TMSR) & ~(0x03 << (2*sn))) | (txmemsize << (2*sn)))
  2574. #define setSn_TXBUF_SIZE(sn, txmemsize) setSn_TXMEM_SIZE(sn,txmemsize)
  2575. /**
  2576. * @ingroup Socket_register_access_function_W5100S
  2577. * @brief Get @ref Sn_TXMEM_SIZE register
  2578. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2579. * @return uint8_t. Value of @ref Sn_TXMEM_SIZE.
  2580. * @sa setSn_TXMEM_SIZE()
  2581. */
  2582. #define getSn_TXMEM_SIZE(sn) \
  2583. ((WIZCHIP_READ(TMSR) & (0x03 << (2*sn))) >> (2*sn))
  2584. #define getSn_TXBUF_SIZE(sn) getSn_TXMEM_SIZE(sn)
  2585. /**
  2586. * @ingroup Socket_register_access_function_W5100S
  2587. * @brief Get @ref Sn_TX_FSR register
  2588. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2589. * @return uint16_t. Value of @ref Sn_TX_FSR.
  2590. */
  2591. uint16_t getSn_TX_FSR(uint8_t sn);
  2592. /**
  2593. * @ingroup Socket_register_access_function_W5100S
  2594. * @brief Get @ref Sn_TX_RD register
  2595. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2596. * @return uint16_t. Value of @ref Sn_TX_RD.
  2597. */
  2598. #define getSn_TX_RD(sn) \
  2599. (((uint16_t)WIZCHIP_READ(Sn_TX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_RD(sn),1)))
  2600. /**
  2601. * @ingroup Socket_register_access_function_W5100S
  2602. * @brief Set @ref Sn_TX_WR register
  2603. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2604. * @param (uint16_t)txwr Value to set @ref Sn_TX_WR
  2605. * @sa GetSn_TX_WR()
  2606. */
  2607. #define setSn_TX_WR(sn, txwr) { \
  2608. WIZCHIP_WRITE(Sn_TX_WR(sn), (uint8_t)(txwr>>8)); \
  2609. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1), (uint8_t) txwr); \
  2610. }
  2611. /**
  2612. * @ingroup Socket_register_access_function_W5100S
  2613. * @brief Get @ref Sn_TX_WR register
  2614. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2615. * @return uint16_t. Value of @ref Sn_TX_WR.
  2616. * @sa setSn_TX_WR()
  2617. */
  2618. #define getSn_TX_WR(sn) \
  2619. (((uint16_t)WIZCHIP_READ(Sn_TX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_WR(sn),1)))
  2620. /**
  2621. * @ingroup Socket_register_access_function_W5100S
  2622. * @brief Get @ref Sn_RX_RSR register
  2623. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2624. * @return uint16_t. Value of @ref Sn_RX_RSR.
  2625. */
  2626. uint16_t getSn_RX_RSR(uint8_t sn);
  2627. /**
  2628. * @ingroup Socket_register_access_function_W5100S
  2629. * @brief Set @ref Sn_RX_RD register
  2630. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2631. * @param (uint16_t)rxrd Value to set @ref Sn_RX_RD
  2632. * @sa getSn_RX_RD()
  2633. */
  2634. #define setSn_RX_RD(sn, rxrd) { \
  2635. WIZCHIP_WRITE(Sn_RX_RD(sn), (uint8_t)(rxrd>>8)); \
  2636. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1), (uint8_t) rxrd); \
  2637. }
  2638. /**
  2639. * @ingroup Socket_register_access_function_W5100S
  2640. * @brief Get @ref Sn_RX_RD register
  2641. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2642. * @regurn uint16_t. Value of @ref Sn_RX_RD.
  2643. * @sa setSn_RX_RD()
  2644. */
  2645. #define getSn_RX_RD(sn) \
  2646. (((uint16_t)WIZCHIP_READ(Sn_RX_RD(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RD(sn),1)))
  2647. /**
  2648. * @ingroup Socket_register_access_function_W5100S
  2649. * @brief Set @ref Sn_RX_WR register
  2650. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2651. * @param (uint16_t)rxwr Value to set \ref Sn_RX_WR
  2652. * @sa getSn_RX_WR()
  2653. */
  2654. #define setSn_RX_WR(sn, rxwr) { \
  2655. WIZCHIP_WRITE(Sn_RX_WR(sn), (uint8_t)(rxwr>>8)); \
  2656. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RX_WR(sn),1), (uint8_t) rxwr); \
  2657. }
  2658. /**
  2659. * @ingroup Socket_register_access_function_W5100S
  2660. * @brief Get @ref Sn_RX_WR register
  2661. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2662. * @return uint16_t. Value of @ref Sn_RX_WR.
  2663. */
  2664. #define getSn_RX_WR(sn) \
  2665. (((uint16_t)WIZCHIP_READ(Sn_RX_WR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_WR(sn),1)))
  2666. /**
  2667. * @ingroup Socket_register_access_function_W5100S
  2668. * @brief Set @ref Sn_FRAGR register
  2669. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2670. * @param (uint16_t)frag Value to set \ref Sn_FRAGR
  2671. * @sa getSn_FRAG()
  2672. */
  2673. #define setSn_FRAGR(sn, fragr) { \
  2674. WIZCHIP_WRITE(Sn_FRAGR(sn), (uint8_t)(fragr >>8)); \
  2675. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_FRAGR(sn),1), (uint8_t) fragr); \
  2676. }
  2677. /**
  2678. * @ingroup Socket_register_access_function_W5100S
  2679. * @brief Get @ref Sn_FRAGR register
  2680. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2681. * @return uint16_t. Value of @ref Sn_FRAGR.
  2682. * @sa setSn_FRAG()
  2683. */
  2684. #define getSn_FRAGR(sn) \
  2685. (((uint16_t)WIZCHIP_READ(Sn_FRAGR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_FRAGR(sn),1)))
  2686. /**
  2687. * @ingroup Socket_register_access_function_W5100S
  2688. * @brief Get the max RX buffer size of socket sn
  2689. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2690. * @return uint16_t. Max buffer size
  2691. */
  2692. #define getSn_RxMAX(sn) \
  2693. ((uint16_t)(0x0001 << getSn_RXMEM_SIZE(sn)) << 10)
  2694. /**
  2695. * @ingroup Socket_register_access_function_W5100S
  2696. * @brief Get the max TX buffer size of socket sn
  2697. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2698. * @return uint16_t. Max buffer size
  2699. */
  2700. #define getSn_TxMAX(sn) \
  2701. ((uint16_t)(0x0001 << getSn_TXMEM_SIZE(sn)) << 10)
  2702. /**
  2703. * @ingroup Socket_register_access_function_W5100S
  2704. * @brief Get the mask of socket sn RX buffer.
  2705. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2706. * @return uint16_t. Mask value
  2707. */
  2708. #define getSn_RxMASK(sn) \
  2709. (getSn_RxMAX(sn) - 1)
  2710. /**
  2711. * @ingroup Socket_register_access_function_W5100S
  2712. * @brief Get the mask of socket sn TX buffer
  2713. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2714. * @return uint16_t. Mask value
  2715. */
  2716. #define getSn_TxMASK(sn) \
  2717. (getSn_TxMAX(sn) - 1)
  2718. /**
  2719. * @ingroup Socket_register_access_function_W5100S
  2720. * @brief Get the base address of socket sn RX buffer.
  2721. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2722. * @return uint16_t. Value of Socket n RX buffer base address.
  2723. */
  2724. uint32_t getSn_RxBASE(uint8_t sn);
  2725. /**
  2726. * @ingroup Socket_register_access_function_W5100S
  2727. * @brief Get the base address of socket sn TX buffer.
  2728. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2729. * @return uint16_t. Value of Socket n TX buffer base address.
  2730. */
  2731. uint32_t getSn_TxBASE(uint8_t sn);
  2732. /*socket register W5100S only*/
  2733. /**
  2734. * @ingroup Socket_register_access_function_W5100S
  2735. * @brief Set the interrupt mask register of socket sn.
  2736. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2737. * @param (uint16_t)imr Value to set \ref Sn_IMR
  2738. * @sa getSn_IMR(sn)
  2739. */
  2740. #define setSn_IMR(sn,imr) \
  2741. WIZCHIP_WRITE(Sn_IMR(sn),imr)
  2742. /**
  2743. * @ingroup Socket_register_access_function_W5100S
  2744. * @brief Get the interrupt mask register of socket sn.
  2745. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2746. * @return uint16_t. Value of Socket n interrupt mask register.
  2747. */
  2748. #define getSn_IMR(sn) \
  2749. WIZCHIP_READ(Sn_IMR(sn))
  2750. /**
  2751. * @ingroup Socket_register_access_function_W5100S
  2752. * @brief Set the Sn_MR2 value of socket sn.
  2753. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2754. * @param mr2 Value of Sn_MR2 register to set.
  2755. */
  2756. #define setSn_MR2(sn,mr2) \
  2757. WIZCHIP_WRITE(Sn_MR2(sn), mr2)
  2758. /**
  2759. * @ingroup Socket_register_access_function_W5100S
  2760. * @brief Get the Sn_MR2 value of socket sn.
  2761. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2762. * @return uint16_t. Value of Socket n Sn_MR2 register.
  2763. */
  2764. #define getSn_MR2(sn) \
  2765. WIZCHIP_READ(Sn_MR2(sn))
  2766. /**
  2767. * @ingroup Socket_register_access_function_W5100S
  2768. * @brief Set the Sn_KPALVTR value of socket sn.
  2769. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2770. * @param kpalvtr Value of the Sn_KPALVTR register to set.
  2771. */
  2772. #define setSn_KPALVTR(sn,kpalvtr) \
  2773. WIZCHIP_WRITE(Sn_KPALVTR(sn), kpalvtr)
  2774. /**
  2775. * @ingroup Socket_register_access_function_W5100S
  2776. * @brief Get the Sn_KPALVTR value of socket sn
  2777. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2778. * @return uint8_t. Value of the Sn_KPALVTR register.
  2779. */
  2780. #define getSn_KPALVTR(sn) \
  2781. WIZCHIP_READ(Sn_KPALVTR(sn))
  2782. /**
  2783. * @ingroup Socket_register_access_function_W5100S
  2784. * @brief Get the Sn_TSR register of socket sn.
  2785. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2786. * @return uint8_t. Value of the Socket n Sn_TSR register.
  2787. */
  2788. #define getSn_TSR(sn) \
  2789. WIZCHIP_READ(Sn_TSR(sn))
  2790. /**
  2791. * @ingroup Socket_register_access_function_W5100S
  2792. * @brief Set the Sn_RTR register of socket sn.
  2793. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2794. * @param (uint16_t)rtr Value of the Socket n Sn_RTR register to set.
  2795. */
  2796. #define setSn_RTR(sn,rtr) { \
  2797. WIZCHIP_WRITE(Sn_RTR(sn), (uint8_t)(rtr >> 8)); \
  2798. WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(Sn_RTR(sn),1), (uint8_t) rtr); \
  2799. }
  2800. /**
  2801. * @ingroup Socket_register_access_function_W5100S
  2802. * @brief Get the Sn_RTR register of socket sn.
  2803. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2804. * @return uint16_t. Value of the Socket n Sn_RTR register.
  2805. */
  2806. #define getSn_RTR(sn) \
  2807. (((uint16_t)WIZCHIP_READ(Sn_RTR(sn)) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RTR(sn),1)))
  2808. /**
  2809. * @ingroup Socket_register_access_function_W5100S
  2810. * @brief Set the Sn_RCR register of socket sn.
  2811. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2812. * @return uint8_t. Value of the Socket n Sn_RCR register to set.
  2813. */
  2814. #define setSn_RCR(sn,rcr) \
  2815. WIZCHIP_WRITE(Sn_RCR(sn),rcr)
  2816. /**
  2817. * @ingroup Socket_register_access_function_W5100S
  2818. * @brief Get the Sn_RCR of socket sn.
  2819. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2820. * @return uint8_t. Value of the Socket n Sn_RCR.
  2821. */
  2822. #define getSn_RCR(sn) \
  2823. WIZCHIP_READ(Sn_RCR(sn))
  2824. /////////////////////////////////////
  2825. // Sn_TXBUF & Sn_RXBUF IO function //
  2826. /////////////////////////////////////
  2827. /**
  2828. * @ingroup Basic_IO_function_W5100S
  2829. * @brief It copies data to internal TX memory
  2830. *
  2831. * @details This function reads the Tx write pointer register and after that,
  2832. * it copies the <i>wizdata(pointer buffer)</i> of the length of <i>len(variable)</i> bytes to internal TX memory
  2833. * and updates the Tx write pointer register.
  2834. * This function is being called by send() and sendto() function also.
  2835. *
  2836. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2837. * @param wizdata Pointer buffer to write data
  2838. * @param len Data length
  2839. * @sa wiz_recv_data()
  2840. */
  2841. void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len);
  2842. /**
  2843. * @ingroup Basic_IO_function_W5100S
  2844. * @brief It copies data to your buffer from internal RX memory
  2845. *
  2846. * @details This function read the Rx read pointer register and after that,
  2847. * it copies the received data from internal RX memory
  2848. * to <i>wizdata(pointer variable)</i> of the length of <i>len(variable)</i> bytes.
  2849. * This function is being called by recv() also.
  2850. *
  2851. * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2852. * @param wizdata Pointer buffer to read data
  2853. * @param len Data length
  2854. * @sa wiz_send_data()
  2855. */
  2856. void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len);
  2857. /**
  2858. * @ingroup Basic_IO_function_W5100S
  2859. * @brief It discard the received data in RX memory.
  2860. * @details It discards the data of the length of <i>len(variable)</i> bytes in internal RX memory.
  2861. * @param (uint8_t)sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
  2862. * @param len Data length
  2863. */
  2864. void wiz_recv_ignore(uint8_t sn, uint16_t len);
  2865. /**
  2866. * @ingroup Special_function_W5100S
  2867. * @brief Write data to the PHY via MDC/MDIO interface.
  2868. * @details Write command data to the PHY via MDC/MDIO interface.
  2869. * @param (uint8_t)PHYMDIO_regadr Address of the PHY register. It should be PHYMDIO_BMCR or PHYMDIO_BMSR.
  2870. * @param (uint16_t)var Data to write to the PHY register. Please refer to the bit definitions of the BMCR and BMSR register.
  2871. */
  2872. void wiz_mdio_write(uint8_t PHYMDIO_regadr, uint16_t var);
  2873. /**
  2874. * @ingroup Special_function_W5100S
  2875. * @brief Read data from the PHY via MDC/MDIO interface.
  2876. * @details Read command or status data from the PHY via MDC/MDIO interface.
  2877. * @param (uint8_t)PHYMDIO_regadr Address of the PHY register. It should be PHYMDIO_BMCR or PHYMDIO_BMSR.
  2878. * @return The value of the PHY register
  2879. */
  2880. uint16_t wiz_mdio_read(uint8_t PHYMDIO_regadr);
  2881. /**
  2882. * @ingroup Special_function_W5100S
  2883. * @brief Delay function
  2884. * @details Delay function using internal 100us timer of the W5100S
  2885. * @param (uint32_t)ms Time to delay in milliseconds.
  2886. */
  2887. void wiz_delay_ms(uint32_t ms);
  2888. /// @cond DOXY_APPLY_CODE
  2889. #endif
  2890. /// @endcond
  2891. #ifdef __cplusplus
  2892. }
  2893. #endif
  2894. #endif //_W5100S_H_