Skip to content

Commit

Permalink
drivers, wiznet5k: Properly fix ARP bug with W5200 chipset.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgeorge committed Sep 1, 2014
1 parent 0c0550b commit 7da9145
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 10 deletions.
19 changes: 14 additions & 5 deletions drivers/wiznet5k/ethernet/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,19 @@ int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port)
setSn_DIPR(sn,addr);
setSn_DPORT(sn,port);
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR(0);
setSUBR(wizchip_getsubn());
#endif
setSn_CR(sn,Sn_CR_CONNECT);
while(getSn_CR(sn));
if(sock_io_mode & (1<<sn)) return SOCK_BUSY;
while(getSn_SR(sn) != SOCK_ESTABLISHED)
{
if (getSn_SR(sn) == SOCK_CLOSED) {
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR((uint8_t*)"\x00\x00\x00\x00");
#endif
return SOCKERR_SOCKCLOSED;
}
if (getSn_IR(sn) & Sn_IR_TIMEOUT)
{
setSn_IR(sn, Sn_IR_TIMEOUT);
Expand Down Expand Up @@ -390,15 +396,12 @@ int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t
wiz_send_data(sn, buf, len);

#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR(0);
setSUBR(wizchip_getsubn());
#endif

setSn_CR(sn,Sn_CR_SEND);
/* wait to process the command... */
while(getSn_CR(sn));
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR((uint8_t*)"\x00\x00\x00\x00");
#endif
while(1)
{
tmp = getSn_IR(sn);
Expand All @@ -412,10 +415,16 @@ int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t
else if(tmp & Sn_IR_TIMEOUT)
{
setSn_IR(sn, Sn_IR_TIMEOUT);
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR((uint8_t*)"\x00\x00\x00\x00");
#endif
return SOCKERR_TIMEOUT;
}
////////////
}
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR((uint8_t*)"\x00\x00\x00\x00");
#endif
return len;
}

Expand Down
31 changes: 28 additions & 3 deletions drivers/wiznet5k/ethernet/w5200/w5200.h
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,9 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
* @param (uint16_t)intlevel Value to set @ref INTLEVEL register.
* @sa getINTLEVEL()
*/
#if 0 // dpgeorge
// dpgeorge: not yet implemented
#define setINTLEVEL(intlevel) (void)intlevel
#if 0
#define setINTLEVEL(intlevel) {\
WIZCHIP_WRITE(INTLEVEL, (uint8_t)(intlevel >> 8)); \
WIZCHIP_WRITE(WIZCHIP_OFFSET_INC(INTLEVEL,1), (uint8_t) intlevel); \
Expand All @@ -1329,7 +1331,9 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
* @return uint16_t. Value of @ref INTLEVEL register.
* @sa setINTLEVEL()
*/
#if 0 // dpgeorge
// dpgeorge: not yet implemented
#define getINTLEVEL() (0)
#if 0
#define getINTLEVEL() \
((WIZCHIP_READ(INTLEVEL) << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(INTLEVEL,1)))
#endif
Expand Down Expand Up @@ -1376,33 +1380,48 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
* @param (uint8_t)sir Value to set @ref SIR register.
* @sa getSIR()
*/
// dpgeorge: not yet implemented
#define setSIR(sir) ((void)sir)
#if 0
#define setSIR(sir) \
WIZCHIP_WRITE(SIR, sir)
#endif

/**
* @ingroup Common_register_access_function
* @brief Get @ref SIR register
* @return uint8_t. Value of @ref SIR register.
* @sa setSIR()
*/
// dpgeorge: not yet implemented
#define getSIR() (0)
#if 0
#define getSIR() \
WIZCHIP_READ(SIR)
#endif

/**
* @ingroup Common_register_access_function
* @brief Set @ref SIMR register
* @param (uint8_t)simr Value to set @ref SIMR register.
* @sa getSIMR()
*/
// dpgeorge: not yet implemented
#define setSIMR(simr) ((void)simr)
#if 0
#define setSIMR(simr) \
WIZCHIP_WRITE(SIMR, simr)
#endif

/**
* @ingroup Common_register_access_function
* @brief Get @ref SIMR register
* @return uint8_t. Value of @ref SIMR register.
* @sa setSIMR()
*/
// dpgeorge: not yet implemented
#define getSIMR() (0)
#if 0
#define getSIMR() \
WIZCHIP_READ(SIMR)
#endif
Expand Down Expand Up @@ -1652,16 +1671,19 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
#define getSn_IR(sn) \
(WIZCHIP_READ(Sn_IR(sn)) & 0x1F)

#if 0 // dpgeorge
/**
* @ingroup Socket_register_access_function
* @brief Set @ref Sn_IMR register
* @param (uint8_t)sn Socket number. It should be <b>0 ~ 7</b>.
* @param (uint8_t)imr Value to set @ref Sn_IMR
* @sa getSn_IMR()
*/
// dpgeorge: not yet implemented
#define setSn_IMR(sn, imr) (void)sn; (void)imr
#if 0
#define setSn_IMR(sn, imr) \
WIZCHIP_WRITE(Sn_IMR(sn), (imr & 0x1F))
#endif

/**
* @ingroup Socket_register_access_function
Expand All @@ -1670,6 +1692,9 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
* @return uint8_t. Value of @ref Sn_IMR.
* @sa setSn_IMR()
*/
// dpgeorge: not yet implemented
#define getSn_IMR(sn) (0)
#if 0
#define getSn_IMR(sn) \
(WIZCHIP_READ(Sn_IMR(sn)) & 0x1F)
#endif
Expand Down
17 changes: 16 additions & 1 deletion drivers/wiznet5k/ethernet/wizchip_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ _WIZCHIP WIZCHIP =
// .IF.SPI._write_byte = wizchip_spi_writebyte
};

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

Expand Down Expand Up @@ -168,7 +171,7 @@ void reg_wizchip_bus_cbfunc(uint8_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint
}
}

void reg_wizchip_spi_cbfunc((void (*spi_rb)(uint8_t *, uint32_t), void (*spi_wb)(const uint8_t *, uint32_t))
void reg_wizchip_spi_cbfunc(void (*spi_rb)(uint8_t *, uint32_t), void (*spi_wb)(const uint8_t *, uint32_t))
{
while(!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_SPI_));

Expand Down Expand Up @@ -584,6 +587,12 @@ void wizchip_setnetinfo(wiz_NetInfo* pnetinfo)
setGAR(pnetinfo->gw);
setSUBR(pnetinfo->sn);
setSIPR(pnetinfo->ip);
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
_SUBN_[0] = pnetinfo->sn[0];
_SUBN_[1] = pnetinfo->sn[1];
_SUBN_[2] = pnetinfo->sn[2];
_SUBN_[3] = pnetinfo->sn[3];
#endif
_DNS_[0] = pnetinfo->dns[0];
_DNS_[1] = pnetinfo->dns[1];
_DNS_[2] = pnetinfo->dns[2];
Expand All @@ -604,6 +613,12 @@ void wizchip_getnetinfo(wiz_NetInfo* pnetinfo)
pnetinfo->dhcp = _DHCP_;
}

#if _WIZCHIP_ == 5200 // for W5200 ARP errata
uint8_t *wizchip_getsubn(void) {
return _SUBN_;
}
#endif

int8_t wizchip_setnetmode(netmode_type netmode)
{
uint8_t tmp = 0;
Expand Down
6 changes: 5 additions & 1 deletion drivers/wiznet5k/ethernet/wizchip_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* @todo You should select one, \b 5100, \b 5200 ,\b 5500 or etc. \n\n
* ex> <code> #define \_WIZCHIP_ 5500 </code>
*/
#define _WIZCHIP_ 5500 // 5100, 5200, 5500
#define _WIZCHIP_ 5200 // 5100, 5200, 5500

#define _WIZCHIP_IO_MODE_NONE_ 0x0000
#define _WIZCHIP_IO_MODE_BUS_ 0x0100 /**< Bus interface mode */
Expand Down Expand Up @@ -515,6 +515,10 @@ void wizchip_setnetinfo(wiz_NetInfo* pnetinfo);
*/
void wizchip_getnetinfo(wiz_NetInfo* pnetinfo);

#if _WIZCHIP_ == 5200 // for W5200 ARP errata
uint8_t *wizchip_getsubn(void);
#endif

/**
* @ingroup extra_functions
* @brief Set the network mode such WOL, PPPoE, Ping Block, and etc.
Expand Down

0 comments on commit 7da9145

Please sign in to comment.