wizchip_conf.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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. /**
  52. * @brief Default function to enable interrupt.
  53. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  54. * null function is called.
  55. */
  56. void wizchip_cris_enter(void) {};
  57. /**
  58. * @brief Default function to disable interrupt.
  59. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  60. * null function is called.
  61. */
  62. void wizchip_cris_exit(void) {};
  63. /**
  64. * @brief Default function to select chip.
  65. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  66. * null function is called.
  67. */
  68. void wizchip_cs_select(void) {};
  69. /**
  70. * @brief Default function to deselect chip.
  71. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  72. * null function is called.
  73. */
  74. void wizchip_cs_deselect(void) {};
  75. /**
  76. * @brief Default function to read in direct or indirect interface.
  77. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  78. * null function is called.
  79. */
  80. //M20140501 : Explict pointer type casting
  81. //uint8_t wizchip_bus_readbyte(uint32_t AddrSel) { return * ((volatile uint8_t *) AddrSel); };
  82. uint8_t wizchip_bus_readbyte(uint32_t AddrSel) { return * ((volatile uint8_t *)((ptrdiff_t) AddrSel)); };
  83. /**
  84. * @brief Default function to write in direct or indirect interface.
  85. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  86. * null function is called.
  87. */
  88. //M20140501 : Explict pointer type casting
  89. //void wizchip_bus_writebyte(uint32_t AddrSel, uint8_t wb) { *((volatile uint8_t*) AddrSel) = wb; };
  90. void wizchip_bus_writebyte(uint32_t AddrSel, uint8_t wb) { *((volatile uint8_t*)((ptrdiff_t)AddrSel)) = wb; };
  91. /**
  92. * @brief Default function to read in SPI interface.
  93. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  94. * null function is called.
  95. */
  96. uint8_t wizchip_spi_readbyte(void) {return 0;};
  97. /**
  98. * @brief Default function to write in SPI interface.
  99. * @note This function help not to access wrong address. If you do not describe this function or register any functions,
  100. * null function is called.
  101. */
  102. void wizchip_spi_writebyte(uint8_t wb) {};
  103. /**
  104. * @\ref _WIZCHIP instance
  105. */
  106. _WIZCHIP WIZCHIP =
  107. {
  108. .id = _WIZCHIP_ID_,
  109. .if_mode = _WIZCHIP_IO_MODE_,
  110. .CRIS._enter = wizchip_cris_enter,
  111. .CRIS._exit = wizchip_cris_exit,
  112. .CS._select = wizchip_cs_select,
  113. .CS._deselect = wizchip_cs_deselect,
  114. .IF.BUS._read_byte = wizchip_bus_readbyte,
  115. .IF.BUS._write_byte = wizchip_bus_writebyte
  116. // .IF.SPI._read_byte = wizchip_spi_readbyte,
  117. // .IF.SPI._write_byte = wizchip_spi_writebyte
  118. };
  119. static uint8_t _DNS_[4]; // DNS server ip address
  120. static dhcp_mode _DHCP_; // DHCP mode
  121. void reg_wizchip_cris_cbfunc(void(*cris_en)(void), void(*cris_ex)(void))
  122. {
  123. if(!cris_en || !cris_ex)
  124. {
  125. WIZCHIP.CRIS._enter = wizchip_cris_enter;
  126. WIZCHIP.CRIS._exit = wizchip_cris_exit;
  127. }
  128. else
  129. {
  130. WIZCHIP.CRIS._enter = cris_en;
  131. WIZCHIP.CRIS._exit = cris_ex;
  132. }
  133. }
  134. void reg_wizchip_cs_cbfunc(void(*cs_sel)(void), void(*cs_desel)(void))
  135. {
  136. if(!cs_sel || !cs_desel)
  137. {
  138. WIZCHIP.CS._select = wizchip_cs_select;
  139. WIZCHIP.CS._deselect = wizchip_cs_deselect;
  140. }
  141. else
  142. {
  143. WIZCHIP.CS._select = cs_sel;
  144. WIZCHIP.CS._deselect = cs_desel;
  145. }
  146. }
  147. void reg_wizchip_bus_cbfunc(uint8_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, uint8_t wb))
  148. {
  149. while(!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_BUS_));
  150. if(!bus_rb || !bus_wb)
  151. {
  152. WIZCHIP.IF.BUS._read_byte = wizchip_bus_readbyte;
  153. WIZCHIP.IF.BUS._write_byte = wizchip_bus_writebyte;
  154. }
  155. else
  156. {
  157. WIZCHIP.IF.BUS._read_byte = bus_rb;
  158. WIZCHIP.IF.BUS._write_byte = bus_wb;
  159. }
  160. }
  161. void reg_wizchip_spi_cbfunc(uint8_t (*spi_rb)(void), void (*spi_wb)(uint8_t wb))
  162. {
  163. while(!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_SPI_));
  164. if(!spi_rb || !spi_wb)
  165. {
  166. WIZCHIP.IF.SPI._read_byte = wizchip_spi_readbyte;
  167. WIZCHIP.IF.SPI._write_byte = wizchip_spi_writebyte;
  168. }
  169. else
  170. {
  171. WIZCHIP.IF.SPI._read_byte = spi_rb;
  172. WIZCHIP.IF.SPI._write_byte = spi_wb;
  173. }
  174. }
  175. int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg)
  176. {
  177. uint8_t tmp = 0;
  178. uint8_t* ptmp[2] = {0,0};
  179. switch(cwtype)
  180. {
  181. case CW_RESET_WIZCHIP:
  182. wizchip_sw_reset();
  183. break;
  184. case CW_INIT_WIZCHIP:
  185. if(arg != 0)
  186. {
  187. ptmp[0] = (uint8_t*)arg;
  188. ptmp[1] = ptmp[0] + _WIZCHIP_SOCK_NUM_;
  189. }
  190. return wizchip_init(ptmp[0], ptmp[1]);
  191. case CW_CLR_INTERRUPT:
  192. wizchip_clrinterrupt(*((intr_kind*)arg));
  193. break;
  194. case CW_GET_INTERRUPT:
  195. *((intr_kind*)arg) = wizchip_getinterrupt();
  196. break;
  197. case CW_SET_INTRMASK:
  198. wizchip_setinterruptmask(*((intr_kind*)arg));
  199. break;
  200. case CW_GET_INTRMASK:
  201. *((intr_kind*)arg) = wizchip_getinterruptmask();
  202. break;
  203. #if _WIZCHIP_ > 5100
  204. case CW_SET_INTRTIME:
  205. setINTLEVEL(*(uint16_t*)arg);
  206. break;
  207. case CW_GET_INTRTIME:
  208. *(uint16_t*)arg = getINTLEVEL();
  209. break;
  210. #endif
  211. case CW_GET_ID:
  212. ((uint8_t*)arg)[0] = WIZCHIP.id[0];
  213. ((uint8_t*)arg)[1] = WIZCHIP.id[1];
  214. ((uint8_t*)arg)[2] = WIZCHIP.id[2];
  215. ((uint8_t*)arg)[3] = WIZCHIP.id[3];
  216. ((uint8_t*)arg)[4] = WIZCHIP.id[4];
  217. ((uint8_t*)arg)[5] = 0;
  218. break;
  219. #if _WIZCHIP_ == 5500
  220. case CW_RESET_PHY:
  221. wizphy_reset();
  222. break;
  223. case CW_SET_PHYCONF:
  224. wizphy_setphyconf((wiz_PhyConf*)arg);
  225. break;
  226. case CW_GET_PHYCONF:
  227. wizphy_getphyconf((wiz_PhyConf*)arg);
  228. break;
  229. case CW_GET_PHYSTATUS:
  230. break;
  231. case CW_SET_PHYPOWMODE:
  232. return wizphy_setphypmode(*(uint8_t*)arg);
  233. #endif
  234. case CW_GET_PHYPOWMODE:
  235. tmp = wizphy_getphypmode();
  236. if((int8_t)tmp == -1) return -1;
  237. *(uint8_t*)arg = tmp;
  238. break;
  239. case CW_GET_PHYLINK:
  240. tmp = wizphy_getphylink();
  241. if((int8_t)tmp == -1) return -1;
  242. *(uint8_t*)arg = tmp;
  243. break;
  244. default:
  245. return -1;
  246. }
  247. return 0;
  248. }
  249. int8_t ctlnetwork(ctlnetwork_type cntype, void* arg)
  250. {
  251. switch(cntype)
  252. {
  253. case CN_SET_NETINFO:
  254. wizchip_setnetinfo((wiz_NetInfo*)arg);
  255. break;
  256. case CN_GET_NETINFO:
  257. wizchip_getnetinfo((wiz_NetInfo*)arg);
  258. break;
  259. case CN_SET_NETMODE:
  260. return wizchip_setnetmode(*(netmode_type*)arg);
  261. case CN_GET_NETMODE:
  262. *(netmode_type*)arg = wizchip_getnetmode();
  263. break;
  264. case CN_SET_TIMEOUT:
  265. wizchip_settimeout((wiz_NetTimeout*)arg);
  266. break;
  267. case CN_GET_TIMEOUT:
  268. wizchip_gettimeout((wiz_NetTimeout*)arg);
  269. break;
  270. default:
  271. return -1;
  272. }
  273. return 0;
  274. }
  275. void wizchip_sw_reset(void)
  276. {
  277. uint8_t gw[4], sn[4], sip[4];
  278. uint8_t mac[6];
  279. getSHAR(mac);
  280. getGAR(gw); getSUBR(sn); getSIPR(sip);
  281. setMR(MR_RST);
  282. getMR(); // for delay
  283. setSHAR(mac);
  284. setGAR(gw);
  285. setSUBR(sn);
  286. setSIPR(sip);
  287. }
  288. int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
  289. {
  290. int8_t i;
  291. int8_t tmp = 0;
  292. wizchip_sw_reset();
  293. if(txsize)
  294. {
  295. tmp = 0;
  296. for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  297. tmp += txsize[i];
  298. if(tmp > 16) return -1;
  299. for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  300. setSn_TXBUF_SIZE(i, txsize[i]);
  301. }
  302. if(rxsize)
  303. {
  304. tmp = 0;
  305. for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  306. tmp += rxsize[i];
  307. if(tmp > 16) return -1;
  308. for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
  309. setSn_RXBUF_SIZE(i, rxsize[i]);
  310. }
  311. return 0;
  312. }
  313. void wizchip_clrinterrupt(intr_kind intr)
  314. {
  315. uint8_t ir = (uint8_t)intr;
  316. uint8_t sir = (uint8_t)((uint16_t)intr >> 8);
  317. #if _WIZCHIP_ < 5500
  318. ir |= (1<<4); // IK_WOL
  319. #endif
  320. #if _WIZCHIP_ == 5200
  321. ir |= (1 << 6);
  322. #endif
  323. #if _WIZCHIP_ < 5200
  324. sir &= 0x0F;
  325. #endif
  326. #if _WIZCHIP_ == 5100
  327. ir |= sir;
  328. setIR(ir);
  329. #else
  330. setIR(ir);
  331. setSIR(sir);
  332. #endif
  333. }
  334. intr_kind wizchip_getinterrupt(void)
  335. {
  336. uint8_t ir = 0;
  337. uint8_t sir = 0;
  338. uint16_t ret = 0;
  339. #if _WIZCHIP_ == 5100
  340. ir = getIR();
  341. sir = ir 0x0F;
  342. #else
  343. ir = getIR();
  344. sir = getSIR();
  345. #endif
  346. #if _WIZCHIP_ < 5500
  347. ir &= ~(1<<4); // IK_WOL
  348. #endif
  349. #if _WIZCHIP_ == 5200
  350. ir &= ~(1 << 6);
  351. #endif
  352. ret = sir;
  353. ret = (ret << 8) + ir;
  354. return (intr_kind)ret;
  355. }
  356. void wizchip_setinterruptmask(intr_kind intr)
  357. {
  358. uint8_t imr = (uint8_t)intr;
  359. uint8_t simr = (uint8_t)((uint16_t)intr >> 8);
  360. #if _WIZCHIP_ < 5500
  361. imr &= ~(1<<4); // IK_WOL
  362. #endif
  363. #if _WIZCHIP_ == 5200
  364. imr &= ~(1 << 6);
  365. #endif
  366. #if _WIZCHIP_ < 5200
  367. simr &= 0x0F;
  368. #endif
  369. #if _WIZCHIP_ == 5100
  370. imr |= simr;
  371. setIMR(imr);
  372. #else
  373. setIMR(imr);
  374. setSIMR(simr);
  375. #endif
  376. }
  377. intr_kind wizchip_getinterruptmask(void)
  378. {
  379. uint8_t imr = 0;
  380. uint8_t simr = 0;
  381. uint16_t ret = 0;
  382. #if _WIZCHIP_ == 5100
  383. imr = getIMR();
  384. simr = imr 0x0F;
  385. #else
  386. imr = getIMR();
  387. simr = getSIMR();
  388. #endif
  389. #if _WIZCHIP_ < 5500
  390. imr &= ~(1<<4); // IK_WOL
  391. #endif
  392. #if _WIZCHIP_ == 5200
  393. imr &= ~(1 << 6); // IK_DEST_UNREACH
  394. #endif
  395. ret = simr;
  396. ret = (ret << 8) + imr;
  397. return (intr_kind)ret;
  398. }
  399. int8_t wizphy_getphylink(void)
  400. {
  401. int8_t tmp;
  402. #if _WIZCHIP_ == 5200
  403. if(getPHYSTATUS() & PHYSTATUS_LINK)
  404. tmp = PHY_LINK_ON;
  405. else
  406. tmp = PHY_LINK_OFF;
  407. #elif _WIZCHIP_ == 5500
  408. if(getPHYCFGR() & PHYCFGR_LNK_ON)
  409. tmp = PHY_LINK_ON;
  410. else
  411. tmp = PHY_LINK_OFF;
  412. #else
  413. tmp = -1;
  414. #endif
  415. return tmp;
  416. }
  417. #if _WIZCHIP_ > 5100
  418. int8_t wizphy_getphypmode(void)
  419. {
  420. int8_t tmp = 0;
  421. #if _WIZCHIP_ == 5200
  422. if(getPHYSTATUS() & PHYSTATUS_POWERDOWN)
  423. tmp = PHY_POWER_DOWN;
  424. else
  425. tmp = PHY_POWER_NORM;
  426. #elif _WIZCHIP_ == 5500
  427. if(getPHYCFGR() & PHYCFGR_OPMDC_PDOWN)
  428. tmp = PHY_POWER_DOWN;
  429. else
  430. tmp = PHY_POWER_NORM;
  431. #else
  432. tmp = -1;
  433. #endif
  434. return tmp;
  435. }
  436. #endif
  437. #if _WIZCHIP_ == 5500
  438. void wizphy_reset(void)
  439. {
  440. uint8_t tmp = getPHYCFGR();
  441. tmp &= PHYCFGR_RST;
  442. setPHYCFGR(tmp);
  443. tmp = getPHYCFGR();
  444. tmp |= ~PHYCFGR_RST;
  445. setPHYCFGR(tmp);
  446. }
  447. void wizphy_setphyconf(wiz_PhyConf* phyconf)
  448. {
  449. uint8_t tmp = 0;
  450. if(phyconf->by == PHY_CONFBY_SW)
  451. tmp |= PHYCFGR_OPMD;
  452. else
  453. tmp &= ~PHYCFGR_OPMD;
  454. if(phyconf->mode == PHY_MODE_AUTONEGO)
  455. tmp |= PHYCFGR_OPMDC_ALLA;
  456. else
  457. {
  458. if(phyconf->duplex == PHY_DUPLEX_FULL)
  459. {
  460. if(phyconf->speed == PHY_SPEED_100)
  461. tmp |= PHYCFGR_OPMDC_100F;
  462. else
  463. tmp |= PHYCFGR_OPMDC_10F;
  464. }
  465. else
  466. {
  467. if(phyconf->speed == PHY_SPEED_100)
  468. tmp |= PHYCFGR_OPMDC_100H;
  469. else
  470. tmp |= PHYCFGR_OPMDC_10H;
  471. }
  472. }
  473. setPHYCFGR(tmp);
  474. wizphy_reset();
  475. }
  476. void wizphy_getphyconf(wiz_PhyConf* phyconf)
  477. {
  478. uint8_t tmp = 0;
  479. tmp = getPHYCFGR();
  480. phyconf->by = (tmp & PHYCFGR_OPMD) ? PHY_CONFBY_SW : PHY_CONFBY_HW;
  481. switch(tmp & PHYCFGR_OPMDC_ALLA)
  482. {
  483. case PHYCFGR_OPMDC_ALLA:
  484. case PHYCFGR_OPMDC_100FA:
  485. phyconf->mode = PHY_MODE_AUTONEGO;
  486. break;
  487. default:
  488. phyconf->mode = PHY_MODE_MANUAL;
  489. break;
  490. }
  491. switch(tmp & PHYCFGR_OPMDC_ALLA)
  492. {
  493. case PHYCFGR_OPMDC_100FA:
  494. case PHYCFGR_OPMDC_100F:
  495. case PHYCFGR_OPMDC_100H:
  496. phyconf->speed = PHY_SPEED_100;
  497. break;
  498. default:
  499. phyconf->speed = PHY_SPEED_10;
  500. break;
  501. }
  502. switch(tmp & PHYCFGR_OPMDC_ALLA)
  503. {
  504. case PHYCFGR_OPMDC_100FA:
  505. case PHYCFGR_OPMDC_100F:
  506. case PHYCFGR_OPMDC_10F:
  507. phyconf->duplex = PHY_DUPLEX_FULL;
  508. break;
  509. default:
  510. phyconf->duplex = PHY_DUPLEX_HALF;
  511. break;
  512. }
  513. }
  514. void wizphy_getphystat(wiz_PhyConf* phyconf)
  515. {
  516. uint8_t tmp = getPHYCFGR();
  517. phyconf->duplex = (tmp & PHYCFGR_DPX_FULL) ? PHY_DUPLEX_FULL : PHY_DUPLEX_HALF;
  518. phyconf->speed = (tmp & PHYCFGR_SPD_100) ? PHY_SPEED_100 : PHY_SPEED_10;
  519. }
  520. int8_t wizphy_setphypmode(uint8_t pmode)
  521. {
  522. uint8_t tmp = 0;
  523. tmp = getPHYCFGR();
  524. if((tmp & PHYCFGR_OPMD)== 0) return -1;
  525. tmp &= ~PHYCFGR_OPMDC_ALLA;
  526. if( pmode == PHY_POWER_DOWN)
  527. tmp |= PHYCFGR_OPMDC_PDOWN;
  528. else
  529. tmp |= PHYCFGR_OPMDC_ALLA;
  530. setPHYCFGR(tmp);
  531. wizphy_reset();
  532. tmp = getPHYCFGR();
  533. if( pmode == PHY_POWER_DOWN)
  534. {
  535. if(tmp & PHYCFGR_OPMDC_PDOWN) return 0;
  536. }
  537. else
  538. {
  539. if(tmp & PHYCFGR_OPMDC_ALLA) return 0;
  540. }
  541. return -1;
  542. }
  543. #endif
  544. void wizchip_setnetinfo(wiz_NetInfo* pnetinfo)
  545. {
  546. setSHAR(pnetinfo->mac);
  547. setGAR(pnetinfo->gw);
  548. setSUBR(pnetinfo->sn);
  549. setSIPR(pnetinfo->ip);
  550. _DNS_[0] = pnetinfo->dns[0];
  551. _DNS_[1] = pnetinfo->dns[1];
  552. _DNS_[2] = pnetinfo->dns[2];
  553. _DNS_[3] = pnetinfo->dns[3];
  554. _DHCP_ = pnetinfo->dhcp;
  555. }
  556. void wizchip_getnetinfo(wiz_NetInfo* pnetinfo)
  557. {
  558. getSHAR(pnetinfo->mac);
  559. getGAR(pnetinfo->gw);
  560. getSUBR(pnetinfo->sn);
  561. getSIPR(pnetinfo->ip);
  562. pnetinfo->dns[0]= _DNS_[0];
  563. pnetinfo->dns[1]= _DNS_[1];
  564. pnetinfo->dns[2]= _DNS_[2];
  565. pnetinfo->dns[3]= _DNS_[3];
  566. pnetinfo->dhcp = _DHCP_;
  567. }
  568. int8_t wizchip_setnetmode(netmode_type netmode)
  569. {
  570. uint8_t tmp = 0;
  571. #if _WIZCHIP_ != 5500
  572. if(netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK)) return -1;
  573. #else
  574. if(netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK | NM_FORCEARP)) return -1;
  575. #endif
  576. tmp = getMR();
  577. tmp |= (uint8_t)netmode;
  578. setMR(tmp);
  579. return 0;
  580. }
  581. netmode_type wizchip_getnetmode(void)
  582. {
  583. return (netmode_type) getMR();
  584. }
  585. void wizchip_settimeout(wiz_NetTimeout* nettime)
  586. {
  587. setRCR(nettime->retry_cnt);
  588. setRTR(nettime->time_100us);
  589. }
  590. void wizchip_gettimeout(wiz_NetTimeout* nettime)
  591. {
  592. nettime->retry_cnt = getRCR();
  593. nettime->time_100us = getRTR();
  594. }