drivers, wiznet5k: Properly fix ARP bug with W5200 chipset.

This commit is contained in:
Damien George 2014-09-01 00:06:05 +01:00
parent 0c0550bff0
commit 7da9145e47
4 changed files with 63 additions and 10 deletions

View File

@ -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);
@ -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);
@ -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;
}

View File

@ -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); \
@ -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
@ -1376,9 +1380,12 @@ 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
@ -1386,16 +1393,25 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
* @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
@ -1403,6 +1419,9 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
* @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
@ -1652,7 +1671,6 @@ 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
@ -1660,8 +1678,12 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
* @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
@ -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

View File

@ -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
@ -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_));
@ -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];
@ -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;

View File

@ -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 */
@ -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.