Skip to content

Commit 7da9145

Browse files
committed
drivers, wiznet5k: Properly fix ARP bug with W5200 chipset.
1 parent 0c0550b commit 7da9145

File tree

4 files changed

+63
-10
lines changed

4 files changed

+63
-10
lines changed

drivers/wiznet5k/ethernet/socket.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,19 @@ int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port)
204204
setSn_DIPR(sn,addr);
205205
setSn_DPORT(sn,port);
206206
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
207-
setSUBR(0);
207+
setSUBR(wizchip_getsubn());
208208
#endif
209209
setSn_CR(sn,Sn_CR_CONNECT);
210210
while(getSn_CR(sn));
211211
if(sock_io_mode & (1<<sn)) return SOCK_BUSY;
212212
while(getSn_SR(sn) != SOCK_ESTABLISHED)
213213
{
214+
if (getSn_SR(sn) == SOCK_CLOSED) {
215+
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
216+
setSUBR((uint8_t*)"\x00\x00\x00\x00");
217+
#endif
218+
return SOCKERR_SOCKCLOSED;
219+
}
214220
if (getSn_IR(sn) & Sn_IR_TIMEOUT)
215221
{
216222
setSn_IR(sn, Sn_IR_TIMEOUT);
@@ -390,15 +396,12 @@ int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t
390396
wiz_send_data(sn, buf, len);
391397

392398
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
393-
setSUBR(0);
399+
setSUBR(wizchip_getsubn());
394400
#endif
395401

396402
setSn_CR(sn,Sn_CR_SEND);
397403
/* wait to process the command... */
398404
while(getSn_CR(sn));
399-
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
400-
setSUBR((uint8_t*)"\x00\x00\x00\x00");
401-
#endif
402405
while(1)
403406
{
404407
tmp = getSn_IR(sn);
@@ -412,10 +415,16 @@ int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t
412415
else if(tmp & Sn_IR_TIMEOUT)
413416
{
414417
setSn_IR(sn, Sn_IR_TIMEOUT);
418+
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
419+
setSUBR((uint8_t*)"\x00\x00\x00\x00");
420+
#endif
415421
return SOCKERR_TIMEOUT;
416422
}
417423
////////////
418424
}
425+
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
426+
setSUBR((uint8_t*)"\x00\x00\x00\x00");
427+
#endif
419428
return len;
420429
}
421430

drivers/wiznet5k/ethernet/w5200/w5200.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,9 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
13151315
* @param (uint16_t)intlevel Value to set @ref INTLEVEL register.
13161316
* @sa getINTLEVEL()
13171317
*/
1318-
#if 0 // dpgeorge
1318+
// dpgeorge: not yet implemented
1319+
#define setINTLEVEL(intlevel) (void)intlevel
1320+
#if 0
13191321
#define setINTLEVEL(intlevel) {\
13201322
WIZCHIP_WRITE(INTLEVEL, (uint8_t)(intlevel >> 8)); \
13211323
WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(INTLEVEL,1), (uint8_t) intlevel); \
@@ -1329,7 +1331,9 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
13291331
* @return uint16_t. Value of @ref INTLEVEL register.
13301332
* @sa setINTLEVEL()
13311333
*/
1332-
#if 0 // dpgeorge
1334+
// dpgeorge: not yet implemented
1335+
#define getINTLEVEL() (0)
1336+
#if 0
13331337
#define getINTLEVEL() \
13341338
((WIZCHIP_READ(INTLEVEL) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(INTLEVEL,1)))
13351339
#endif
@@ -1376,33 +1380,48 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
13761380
* @param (uint8_t)sir Value to set @ref SIR register.
13771381
* @sa getSIR()
13781382
*/
1383+
// dpgeorge: not yet implemented
1384+
#define setSIR(sir) ((void)sir)
13791385
#if 0
13801386
#define setSIR(sir) \
13811387
WIZCHIP_WRITE(SIR, sir)
1388+
#endif
13821389

13831390
/**
13841391
* @ingroup Common_register_access_function
13851392
* @brief Get @ref SIR register
13861393
* @return uint8_t. Value of @ref SIR register.
13871394
* @sa setSIR()
13881395
*/
1396+
// dpgeorge: not yet implemented
1397+
#define getSIR() (0)
1398+
#if 0
13891399
#define getSIR() \
13901400
WIZCHIP_READ(SIR)
1401+
#endif
1402+
13911403
/**
13921404
* @ingroup Common_register_access_function
13931405
* @brief Set @ref SIMR register
13941406
* @param (uint8_t)simr Value to set @ref SIMR register.
13951407
* @sa getSIMR()
13961408
*/
1409+
// dpgeorge: not yet implemented
1410+
#define setSIMR(simr) ((void)simr)
1411+
#if 0
13971412
#define setSIMR(simr) \
13981413
WIZCHIP_WRITE(SIMR, simr)
1414+
#endif
13991415

14001416
/**
14011417
* @ingroup Common_register_access_function
14021418
* @brief Get @ref SIMR register
14031419
* @return uint8_t. Value of @ref SIMR register.
14041420
* @sa setSIMR()
14051421
*/
1422+
// dpgeorge: not yet implemented
1423+
#define getSIMR() (0)
1424+
#if 0
14061425
#define getSIMR() \
14071426
WIZCHIP_READ(SIMR)
14081427
#endif
@@ -1652,16 +1671,19 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
16521671
#define getSn_IR(sn) \
16531672
(WIZCHIP_READ(Sn_IR(sn)) & 0x1F)
16541673

1655-
#if 0 // dpgeorge
16561674
/**
16571675
* @ingroup Socket_register_access_function
16581676
* @brief Set @ref Sn_IMR register
16591677
* @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
16601678
* @param (uint8_t)imr Value to set @ref Sn_IMR
16611679
* @sa getSn_IMR()
16621680
*/
1681+
// dpgeorge: not yet implemented
1682+
#define setSn_IMR(sn, imr) (void)sn; (void)imr
1683+
#if 0
16631684
#define setSn_IMR(sn, imr) \
16641685
WIZCHIP_WRITE(Sn_IMR(sn), (imr & 0x1F))
1686+
#endif
16651687

16661688
/**
16671689
* @ingroup Socket_register_access_function
@@ -1670,6 +1692,9 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
16701692
* @return uint8_t. Value of @ref Sn_IMR.
16711693
* @sa setSn_IMR()
16721694
*/
1695+
// dpgeorge: not yet implemented
1696+
#define getSn_IMR(sn) (0)
1697+
#if 0
16731698
#define getSn_IMR(sn) \
16741699
(WIZCHIP_READ(Sn_IMR(sn)) & 0x1F)
16751700
#endif

drivers/wiznet5k/ethernet/wizchip_conf.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ _WIZCHIP WIZCHIP =
121121
// .IF.SPI._write_byte = wizchip_spi_writebyte
122122
};
123123

124+
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
125+
static uint8_t _SUBN_[4]; // subnet
126+
#endif
124127
static uint8_t _DNS_[4]; // DNS server ip address
125128
static dhcp_mode _DHCP_; // DHCP mode
126129

@@ -168,7 +171,7 @@ void reg_wizchip_bus_cbfunc(uint8_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint
168171
}
169172
}
170173

171-
void reg_wizchip_spi_cbfunc((void (*spi_rb)(uint8_t *, uint32_t), void (*spi_wb)(const uint8_t *, uint32_t))
174+
void reg_wizchip_spi_cbfunc(void (*spi_rb)(uint8_t *, uint32_t), void (*spi_wb)(const uint8_t *, uint32_t))
172175
{
173176
while(!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_SPI_));
174177

@@ -584,6 +587,12 @@ void wizchip_setnetinfo(wiz_NetInfo* pnetinfo)
584587
setGAR(pnetinfo->gw);
585588
setSUBR(pnetinfo->sn);
586589
setSIPR(pnetinfo->ip);
590+
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
591+
_SUBN_[0] = pnetinfo->sn[0];
592+
_SUBN_[1] = pnetinfo->sn[1];
593+
_SUBN_[2] = pnetinfo->sn[2];
594+
_SUBN_[3] = pnetinfo->sn[3];
595+
#endif
587596
_DNS_[0] = pnetinfo->dns[0];
588597
_DNS_[1] = pnetinfo->dns[1];
589598
_DNS_[2] = pnetinfo->dns[2];
@@ -604,6 +613,12 @@ void wizchip_getnetinfo(wiz_NetInfo* pnetinfo)
604613
pnetinfo->dhcp = _DHCP_;
605614
}
606615

616+
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
617+
uint8_t *wizchip_getsubn(void) {
618+
return _SUBN_;
619+
}
620+
#endif
621+
607622
int8_t wizchip_setnetmode(netmode_type netmode)
608623
{
609624
uint8_t tmp = 0;

drivers/wiznet5k/ethernet/wizchip_conf.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* @todo You should select one, \b 5100, \b 5200 ,\b 5500 or etc. \n\n
5757
* ex> <code> #define \_WIZCHIP_ 5500 </code>
5858
*/
59-
#define _WIZCHIP_ 5500 // 5100, 5200, 5500
59+
#define _WIZCHIP_ 5200 // 5100, 5200, 5500
6060

6161
#define _WIZCHIP_IO_MODE_NONE_ 0x0000
6262
#define _WIZCHIP_IO_MODE_BUS_ 0x0100 /**< Bus interface mode */
@@ -515,6 +515,10 @@ void wizchip_setnetinfo(wiz_NetInfo* pnetinfo);
515515
*/
516516
void wizchip_getnetinfo(wiz_NetInfo* pnetinfo);
517517

518+
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
519+
uint8_t *wizchip_getsubn(void);
520+
#endif
521+
518522
/**
519523
* @ingroup extra_functions
520524
* @brief Set the network mode such WOL, PPPoE, Ping Block, and etc.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy