wizchip_conf.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. //****************************************************************************/
  2. //!
  3. //! \file wizchip_conf.c
  4. //! \brief WIZCHIP Config Header File.
  5. //! \version 1.0.1
  6. //! \date 2013/10/21
  7. //! \par Revision history
  8. //! <2014/05/01> V1.0.1 Refer to M20140501
  9. //! 1. Explicit type casting in wizchip_bus_readbyte() & wizchip_bus_writebyte()
  10. // Issued by Mathias ClauBen.
  11. //! uint32_t type converts into ptrdiff_t first. And then recoverting it into uint8_t*
  12. //! For remove the warning when pointer type size is not 32bit.
  13. //! If ptrdiff_t doesn't support in your complier, You should must replace ptrdiff_t into your suitable pointer type.
  14. //! <2013/10/21> 1st Release
  15. //! \author MidnightCow
  16. //! \copyright
  17. //!
  18. //! Copyright (c) 2013, WIZnet Co., LTD.
  19. //! All rights reserved.
  20. //!
  21. //! Redistribution and use in source and binary forms, with or without
  22. //! modification, are permitted provided that the following conditions
  23. //! are met:
  24. //!
  25. //! * Redistributions of source code must retain the above copyright
  26. //! notice, this list of conditions and the following disclaimer.
  27. //! * Redistributions in binary form must reproduce the above copyright
  28. //! notice, this list of conditions and the following disclaimer in the
  29. //! documentation and/or other materials provided with the distribution.
  30. //! * Neither the name of the <ORGANIZATION> nor the names of its
  31. //! contributors may be used to endorse or promote products derived
  32. //! from this software without specific prior written permission.
  33. //!
  34. //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  35. //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  36. //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  37. //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  38. //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  39. //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  40. //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  41. //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  42. //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43. //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  44. //! THE POSSIBILITY OF SUCH DAMAGE.
  45. //
  46. //*****************************************************************************/
  47. //A20140501 : for use the type - ptrdiff_t
  48. #include <stddef.h>
  49. //
  50. #include "wizchip_conf.h"
  51. #include "socket.h"
  52. /**
  53. * @brief Default function to enable interrupt.
  54. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  55. * null function is called.
  56. */
  57. void wizchip_cris_enter(void) {};
  58. /**
  59. * @brief Default function to disable interrupt.
  60. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  61. * null function is called.
  62. */
  63. void wizchip_cris_exit(void) {};
  64. /**
  65. * @brief Default function to select chip.
  66. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  67. * null function is called.
  68. */
  69. void wizchip_cs_select(void) {};
  70. /**
  71. * @brief Default function to deselect chip.
  72. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  73. * null function is called.
  74. */
  75. void wizchip_cs_deselect(void) {};
  76. /**
  77. * @brief Default function to read in direct or indirect interface.
  78. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  79. * null function is called.
  80. */
  81. //M20140501 : Explict pointer type casting
  82. //uint8_t wizchip_bus_readbyte(uint32_t AddrSel) { return * ((volatile uint8_t *) AddrSel); };
  83. uint8_t wizchip_bus_readbyte(uint32_t AddrSel) { return * ((volatile uint8_t *)((ptrdiff_t) AddrSel)); };
  84. /**
  85. * @brief Default function to write in direct or indirect interface.
  86. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  87. * null function is called.
  88. */
  89. //M20140501 : Explict pointer type casting
  90. //void wizchip_bus_writebyte(uint32_t AddrSel, uint8_t wb) { *((volatile uint8_t*) AddrSel) = wb; };
  91. void wizchip_bus_writebyte(uint32_t AddrSel, uint8_t wb) { *((volatile uint8_t*)((ptrdiff_t)AddrSel)) = wb; };
  92. /**
  93. * @brief Default function to read in SPI interface.
  94. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  95. * null function is called.
  96. */
  97. void wizchip_spi_readbytes(uint8_t *buf, uint32_t len) {}
  98. /**
  99. * @brief Default function to write in SPI interface.
  100. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  101. * null function is called.
  102. */
  103. void wizchip_spi_writebytes(const uint8_t *buf, uint32_t len) {}
  104. /**
  105. * @\ref _WIZCHIP instance
  106. */
  107. _WIZCHIP WIZCHIP =
  108. {
  109. .id = _WIZCHIP_ID_,
  110. .if_mode = _WIZCHIP_IO_MODE_,
  111. .CRIS._enter = wizchip_cris_enter,
  112. .CRIS._exit = wizchip_cris_exit,
  113. .CS._select = wizchip_cs_select,
  114. .CS._deselect = wizchip_cs_deselect,
  115. .IF.BUS._read_byte = wizchip_bus_readbyte,
  116. .IF.BUS._write_byte = wizchip_bus_writebyte
  117. // .IF.SPI._read_byte = wizchip_spi_readbyte,
  118. // .IF.SPI._write_byte = wizchip_spi_writebyte
  119. };
  120. #if _WIZCHIP_ == 5200 // for W5200 ARP errata
  121. static uint8_t _SUBN_[4]; // subnet
  122. #endif
  123. static uint8_t _DNS_[4]; // DNS server ip address
  124. static dhcp_mode _DHCP_; // DHCP mode
  125. void reg_wizchip_cris_cbfunc(void(*cris_en)(void), void(*cris_ex)(void))
  126. {
  127. if(!cris_en || !cris_ex)
  128. {
  129. WIZCHIP.CRIS._enter = wizchip_cris_enter;
  130. WIZCHIP.CRIS._exit = wizchip_cris_exit;
  131. }
  132. else
  133. {
  134. WIZCHIP.CRIS._enter = cris_en;
  135. WIZCHIP.CRIS._exit = cris_ex;
  136. }
  137. }
  138. void reg_wizchip_cs_cbfunc(void(*cs_sel)(void), void(*cs_desel)(void))
  139. {
  140. if(!cs_sel || !cs_desel)
  141. {
  142. WIZCHIP.CS._select = wizchip_cs_select;
  143. WIZCHIP.CS._deselect = wizchip_cs_deselect;
  144. }
  145. else
  146. {
  147. WIZCHIP.CS._select = cs_sel;
  148. WIZCHIP.CS._deselect = cs_desel;
  149. }
  150. }
  151. void reg_wizchip_bus_cbfunc(uint8_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, uint8_t wb))
  152. {
  153. while(!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_BUS_));
  154. if(!bus_rb || !bus_wb)
  155. {
  156. WIZCHIP.IF.BUS._read_byte = wizchip_bus_readbyte;
  157. WIZCHIP.IF.BUS._write_byte = wizchip_bus_writebyte;
  158. }
  159. else
  160. {
  161. WIZCHIP.IF.BUS._read_byte = bus_rb;
  162. WIZCHIP.IF.BUS._write_byte = bus_wb;
  163. }
  164. }
  165. void reg_wizchip_spi_cbfunc(void (*spi_rb)(uint8_t *, uint32_t), void (*spi_wb)(const uint8_t *, uint32_t))
  166. {
  167. while(!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_SPI_));
  168. if(!spi_rb || !spi_wb)
  169. {
  170. WIZCHIP.IF.SPI._read_bytes = wizchip_spi_readbytes;
  171. WIZCHIP.IF.SPI._write_bytes = wizchip_spi_writebytes;
  172. }
  173. else
  174. {
  175. WIZCHIP.IF.SPI._read_bytes = spi_rb;
  176. WIZCHIP.IF.SPI._write_bytes = spi_wb;
  177. }
  178. }
  179. int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg)
  180. {
  181. uint8_t tmp = 0;
  182. uint8_t* ptmp[2] = {0,0};
  183. switch(cwtype)
  184. {
  185. case CW_RESET_WIZCHIP:
  186. wizchip_sw_reset();
  187. break;
  188. case CW_INIT_WIZCHIP:
  189. if(arg != 0)
  190. {
  191. ptmp[0] = (uint8_t*)arg;
  192. ptmp[1] = ptmp[0] + _WIZCHIP_SOCK_NUM_;
  193. }
  194. return wizchip_init(ptmp[0], ptmp[1]);
  195. case CW_CLR_INTERRUPT:
  196. wizchip_clrinterrupt(*((intr_kind*)arg));
  197. break;
  198. case CW_GET_INTERRUPT:
  199. *((intr_kind*)arg) = wizchip_getinterrupt();
  200. break;
  201. case CW_SET_INTRMASK:
  202. wizchip_setinterruptmask(*((intr_kind*)arg));
  203. break;
  204. case CW_GET_INTRMASK:
  205. *((intr_kind*)arg) = wizchip_getinterruptmask();
  206. break;
  207. #if _WIZCHIP_ > 5100
  208. case CW_SET_INTRTIME:
  209. setINTLEVEL(*(uint16_t*)arg);
  210. break;
  211. case CW_GET_INTRTIME:
  212. *(uint16_t*)arg = getINTLEVEL();
  213. break;
  214. #endif
  215. case CW_GET_ID:
  216. ((uint8_t*)arg)[0] = WIZCHIP.id[0];
  217. ((uint8_t*)arg)[1] = WIZCHIP.id[1];
  218. ((uint8_t*)arg)[2] = WIZCHIP.id[2];
  219. ((uint8_t*)arg)[3] = WIZCHIP.id[3];
  220. ((uint8_t*)arg)[4] = WIZCHIP.id[4];
  221. ((uint8_t*)arg)[5] = 0;
  222. break;
  223. #if _WIZCHIP_ == 5500
  224. case CW_RESET_PHY:
  225. wizphy_reset();
  226. break;
  227. case CW_SET_PHYCONF:
  228. wizphy_setphyconf((wiz_PhyConf*)arg);
  229. break;
  230. case CW_GET_PHYCONF:
  231. wizphy_getphyconf((wiz_PhyConf*)arg);
  232. break;
  233. case CW_GET_PHYSTATUS:
  234. break;
  235. case CW_SET_PHYPOWMODE:
  236. return wizphy_setphypmode(*(uint8_t*)arg);
  237. #endif
  238. case CW_GET_PHYPOWMODE:
  239. tmp = wizphy_getphypmode();
  240. if((int8_t)tmp == -1) return -1;
  241. *(uint8_t*)arg = tmp;
  242. break;
  243. case CW_GET_PHYLINK:
  244. tmp = wizphy_getphylink();
  245. if((int8_t)tmp == -1) return -1;
  246. *(uint8_t*)arg = tmp;
  247. break;
  248. default:
  249. return -1;
  250. }
  251. return 0;
  252. }
  253. int8_t ctlnetwork(ctlnetwork_type cntype, void* arg)
  254. {
  255. switch(cntype)
  256. {
  257. case CN_SET_NETINFO:
  258. wizchip_setnetinfo((wiz_NetInfo*)arg);
  259. break;
  260. case CN_GET_NETINFO:
  261. wizchip_getnetinfo((wiz_NetInfo*)arg);
  262. break;
  263. case CN_SET_NETMODE:
  264. return wizchip_setnetmode(*(netmode_type*)arg);
  265. case CN_GET_NETMODE:
  266. *(netmode_type*)arg = wizchip_getnetmode();
  267. break;
  268. case CN_SET_TIMEOUT:
  269. wizchip_settimeout((wiz_NetTimeout*)arg);
  270. break;
  271. case CN_GET_TIMEOUT:
  272. wizchip_gettimeout((wiz_NetTimeout*)arg);
  273. break;
  274. default:
  275. return -1;
  276. }
  277. return 0;
  278. }
  279. void wizchip_sw_reset(void)
  280. {
  281. uint8_t gw[4], sn[4], sip[4];
  282. uint8_t mac[6];
  283. getSHAR(mac);
  284. getGAR(gw); getSUBR(sn); getSIPR(sip);
  285. setMR(MR_RST);
  286. getMR(); // for delay
  287. setSHAR(mac);
  288. setGAR(gw);
  289. setSUBR(sn);
  290. setSIPR(sip);
  291. }
  292. int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
  293. {
  294. int8_t i;
  295. int8_t tmp = 0;
  296. wizchip_sw_reset();
  297. if(txsize)
  298. {
  299. tmp = 0;
  300. for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  301. tmp += txsize[i];
  302. if(tmp > 16) return -1;
  303. for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  304. setSn_TXBUF_SIZE(i, txsize[i]);
  305. }
  306. if(rxsize)
  307. {
  308. tmp = 0;
  309. for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  310. tmp += rxsize[i];
  311. if(tmp > 16) return -1;
  312. for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  313. setSn_RXBUF_SIZE(i, rxsize[i]);
  314. }
  315. WIZCHIP_EXPORT(socket_reset)();
  316. return 0;
  317. }
  318. void wizchip_clrinterrupt(intr_kind intr)
  319. {
  320. uint8_t ir = (uint8_t)intr;
  321. uint8_t sir = (uint8_t)((uint16_t)intr >> 8);
  322. #if _WIZCHIP_ < 5500
  323. ir |= (1<<4); // IK_WOL
  324. #endif
  325. #if _WIZCHIP_ == 5200
  326. ir |= (1 << 6);
  327. #endif
  328. #if _WIZCHIP_ < 5200
  329. sir &= 0x0F;
  330. #endif
  331. #if _WIZCHIP_ == 5100
  332. ir |= sir;
  333. setIR(ir);
  334. #else
  335. setIR(ir);
  336. setSIR(sir);
  337. #endif
  338. }
  339. intr_kind wizchip_getinterrupt(void)
  340. {
  341. uint8_t ir = 0;
  342. uint8_t sir = 0;
  343. uint16_t ret = 0;
  344. #if _WIZCHIP_ == 5100
  345. ir = getIR();
  346. sir = ir 0x0F;
  347. #else
  348. ir = getIR();
  349. sir = getSIR();
  350. #endif
  351. #if _WIZCHIP_ < 5500
  352. ir &= ~(1<<4); // IK_WOL
  353. #endif
  354. #if _WIZCHIP_ == 5200
  355. ir &= ~(1 << 6);
  356. #endif
  357. ret = sir;
  358. ret = (ret << 8) + ir;
  359. return (intr_kind)ret;
  360. }
  361. void wizchip_setinterruptmask(intr_kind intr)
  362. {
  363. uint8_t imr = (uint8_t)intr;
  364. uint8_t simr = (uint8_t)((uint16_t)intr >> 8);
  365. #if _WIZCHIP_ < 5500
  366. imr &= ~(1<<4); // IK_WOL
  367. #endif
  368. #if _WIZCHIP_ == 5200
  369. imr &= ~(1 << 6);
  370. #endif
  371. #if _WIZCHIP_ < 5200
  372. simr &= 0x0F;
  373. #endif
  374. #if _WIZCHIP_ == 5100
  375. imr |= simr;
  376. setIMR(imr);
  377. #else
  378. setIMR(imr);
  379. setSIMR(simr);
  380. #endif
  381. }
  382. intr_kind wizchip_getinterruptmask(void)
  383. {
  384. uint8_t imr = 0;
  385. uint8_t simr = 0;
  386. uint16_t ret = 0;
  387. #if _WIZCHIP_ == 5100
  388. imr = getIMR();
  389. simr = imr 0x0F;
  390. #else
  391. imr = getIMR();
  392. simr = getSIMR();
  393. #endif
  394. #if _WIZCHIP_ < 5500
  395. imr &= ~(1<<4); // IK_WOL
  396. #endif
  397. #if _WIZCHIP_ == 5200
  398. imr &= ~(1 << 6); // IK_DEST_UNREACH
  399. #endif
  400. ret = simr;
  401. ret = (ret << 8) + imr;
  402. return (intr_kind)ret;
  403. }
  404. int8_t wizphy_getphylink(void)
  405. {
  406. int8_t tmp;
  407. #if _WIZCHIP_ == 5200
  408. if(getPHYSTATUS() & PHYSTATUS_LINK)
  409. tmp = PHY_LINK_ON;
  410. else
  411. tmp = PHY_LINK_OFF;
  412. #elif _WIZCHIP_ == 5500
  413. if(getPHYCFGR() & PHYCFGR_LNK_ON)
  414. tmp = PHY_LINK_ON;
  415. else
  416. tmp = PHY_LINK_OFF;
  417. #else
  418. tmp = -1;
  419. #endif
  420. return tmp;
  421. }
  422. #if _WIZCHIP_ > 5100
  423. int8_t wizphy_getphypmode(void)
  424. {
  425. int8_t tmp = 0;
  426. #if _WIZCHIP_ == 5200
  427. if(getPHYSTATUS() & PHYSTATUS_POWERDOWN)
  428. tmp = PHY_POWER_DOWN;
  429. else
  430. tmp = PHY_POWER_NORM;
  431. #elif _WIZCHIP_ == 5500
  432. if(getPHYCFGR() & PHYCFGR_OPMDC_PDOWN)
  433. tmp = PHY_POWER_DOWN;
  434. else
  435. tmp = PHY_POWER_NORM;
  436. #else
  437. tmp = -1;
  438. #endif
  439. return tmp;
  440. }
  441. #endif
  442. #if _WIZCHIP_ == 5500
  443. void wizphy_reset(void)
  444. {
  445. uint8_t tmp = getPHYCFGR();
  446. tmp &= PHYCFGR_RST;
  447. setPHYCFGR(tmp);
  448. tmp = getPHYCFGR();
  449. tmp |= ~PHYCFGR_RST;
  450. setPHYCFGR(tmp);
  451. }
  452. void wizphy_setphyconf(wiz_PhyConf* phyconf)
  453. {
  454. uint8_t tmp = 0;
  455. if(phyconf->by == PHY_CONFBY_SW)
  456. tmp |= PHYCFGR_OPMD;
  457. else
  458. tmp &= ~PHYCFGR_OPMD;
  459. if(phyconf->mode == PHY_MODE_AUTONEGO)
  460. tmp |= PHYCFGR_OPMDC_ALLA;
  461. else
  462. {
  463. if(phyconf->duplex == PHY_DUPLEX_FULL)
  464. {
  465. if(phyconf->speed == PHY_SPEED_100)
  466. tmp |= PHYCFGR_OPMDC_100F;
  467. else
  468. tmp |= PHYCFGR_OPMDC_10F;
  469. }
  470. else
  471. {
  472. if(phyconf->speed == PHY_SPEED_100)
  473. tmp |= PHYCFGR_OPMDC_100H;
  474. else
  475. tmp |= PHYCFGR_OPMDC_10H;
  476. }
  477. }
  478. setPHYCFGR(tmp);
  479. wizphy_reset();
  480. }
  481. void wizphy_getphyconf(wiz_PhyConf* phyconf)
  482. {
  483. uint8_t tmp = 0;
  484. tmp = getPHYCFGR();
  485. phyconf->by = (tmp & PHYCFGR_OPMD) ? PHY_CONFBY_SW : PHY_CONFBY_HW;
  486. switch(tmp & PHYCFGR_OPMDC_ALLA)
  487. {
  488. case PHYCFGR_OPMDC_ALLA:
  489. case PHYCFGR_OPMDC_100FA:
  490. phyconf->mode = PHY_MODE_AUTONEGO;
  491. break;
  492. default:
  493. phyconf->mode = PHY_MODE_MANUAL;
  494. break;
  495. }
  496. switch(tmp & PHYCFGR_OPMDC_ALLA)
  497. {
  498. case PHYCFGR_OPMDC_100FA:
  499. case PHYCFGR_OPMDC_100F:
  500. case PHYCFGR_OPMDC_100H:
  501. phyconf->speed = PHY_SPEED_100;
  502. break;
  503. default:
  504. phyconf->speed = PHY_SPEED_10;
  505. break;
  506. }
  507. switch(tmp & PHYCFGR_OPMDC_ALLA)
  508. {
  509. case PHYCFGR_OPMDC_100FA:
  510. case PHYCFGR_OPMDC_100F:
  511. case PHYCFGR_OPMDC_10F:
  512. phyconf->duplex = PHY_DUPLEX_FULL;
  513. break;
  514. default:
  515. phyconf->duplex = PHY_DUPLEX_HALF;
  516. break;
  517. }
  518. }
  519. void wizphy_getphystat(wiz_PhyConf* phyconf)
  520. {
  521. uint8_t tmp = getPHYCFGR();
  522. phyconf->duplex = (tmp & PHYCFGR_DPX_FULL) ? PHY_DUPLEX_FULL : PHY_DUPLEX_HALF;
  523. phyconf->speed = (tmp & PHYCFGR_SPD_100) ? PHY_SPEED_100 : PHY_SPEED_10;
  524. }
  525. int8_t wizphy_setphypmode(uint8_t pmode)
  526. {
  527. uint8_t tmp = 0;
  528. tmp = getPHYCFGR();
  529. if((tmp & PHYCFGR_OPMD)== 0) return -1;
  530. tmp &= ~PHYCFGR_OPMDC_ALLA;
  531. if( pmode == PHY_POWER_DOWN)
  532. tmp |= PHYCFGR_OPMDC_PDOWN;
  533. else
  534. tmp |= PHYCFGR_OPMDC_ALLA;
  535. setPHYCFGR(tmp);
  536. wizphy_reset();
  537. tmp = getPHYCFGR();
  538. if( pmode == PHY_POWER_DOWN)
  539. {
  540. if(tmp & PHYCFGR_OPMDC_PDOWN) return 0;
  541. }
  542. else
  543. {
  544. if(tmp & PHYCFGR_OPMDC_ALLA) return 0;
  545. }
  546. return -1;
  547. }
  548. #endif
  549. void wizchip_setnetinfo(wiz_NetInfo* pnetinfo)
  550. {
  551. setSHAR(pnetinfo->mac);
  552. setGAR(pnetinfo->gw);
  553. setSUBR(pnetinfo->sn);
  554. setSIPR(pnetinfo->ip);
  555. #if _WIZCHIP_ == 5200 // for W5200 ARP errata
  556. _SUBN_[0] = pnetinfo->sn[0];
  557. _SUBN_[1] = pnetinfo->sn[1];
  558. _SUBN_[2] = pnetinfo->sn[2];
  559. _SUBN_[3] = pnetinfo->sn[3];
  560. #endif
  561. _DNS_[0] = pnetinfo->dns[0];
  562. _DNS_[1] = pnetinfo->dns[1];
  563. _DNS_[2] = pnetinfo->dns[2];
  564. _DNS_[3] = pnetinfo->dns[3];
  565. _DHCP_ = pnetinfo->dhcp;
  566. }
  567. void wizchip_getnetinfo(wiz_NetInfo* pnetinfo)
  568. {
  569. getSHAR(pnetinfo->mac);
  570. getGAR(pnetinfo->gw);
  571. getSUBR(pnetinfo->sn);
  572. getSIPR(pnetinfo->ip);
  573. #if _WIZCHIP_ == 5200 // for W5200 ARP errata
  574. pnetinfo->sn[0] = _SUBN_[0];
  575. pnetinfo->sn[1] = _SUBN_[1];
  576. pnetinfo->sn[2] = _SUBN_[2];
  577. pnetinfo->sn[3] = _SUBN_[3];
  578. #endif
  579. pnetinfo->dns[0]= _DNS_[0];
  580. pnetinfo->dns[1]= _DNS_[1];
  581. pnetinfo->dns[2]= _DNS_[2];
  582. pnetinfo->dns[3]= _DNS_[3];
  583. pnetinfo->dhcp = _DHCP_;
  584. }
  585. #if _WIZCHIP_ == 5200 // for W5200 ARP errata
  586. uint8_t *wizchip_getsubn(void) {
  587. return _SUBN_;
  588. }
  589. #endif
  590. int8_t wizchip_setnetmode(netmode_type netmode)
  591. {
  592. uint8_t tmp = 0;
  593. #if _WIZCHIP_ != 5500
  594. if(netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK)) return -1;
  595. #else
  596. if(netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK | NM_FORCEARP)) return -1;
  597. #endif
  598. tmp = getMR();
  599. tmp |= (uint8_t)netmode;
  600. setMR(tmp);
  601. return 0;
  602. }
  603. netmode_type wizchip_getnetmode(void)
  604. {
  605. return (netmode_type) getMR();
  606. }
  607. void wizchip_settimeout(wiz_NetTimeout* nettime)
  608. {
  609. setRCR(nettime->retry_cnt);
  610. setRTR(nettime->time_100us);
  611. }
  612. void wizchip_gettimeout(wiz_NetTimeout* nettime)
  613. {
  614. nettime->retry_cnt = getRCR();
  615. nettime->time_100us = getRTR();
  616. }