Version V3.0
Add to W5300
This commit is contained in:
@ -10,7 +10,7 @@
|
||||
//! Download the latest version directly from GitHub. Please visit the our GitHub repository for ioLibrary.
|
||||
//! >> https://github.com/Wiznet/ioLibrary_Driver
|
||||
//! <2014/05/01> V1.0.1 Refer to M20140501
|
||||
//! 1. Explicit type casting in wizchip_bus_readbyte() & wizchip_bus_writebyte()
|
||||
//! 1. Explicit type casting in wizchip_bus_readdata() & wizchip_bus_writedata()
|
||||
// Issued by Mathias ClauBen.
|
||||
//! uint32_t type converts into ptrdiff_t first. And then recoverting it into uint8_t*
|
||||
//! For remove the warning when pointer type size is not 32bit.
|
||||
@ -95,21 +95,18 @@ void wizchip_cs_deselect(void) {}
|
||||
* @note This function help not to access wrong address. If you do not describe this function or register any functions,
|
||||
* null function is called.
|
||||
*/
|
||||
//M20140501 : Explict pointer type casting
|
||||
//uint8_t wizchip_bus_readbyte(uint32_t AddrSel) { return * ((volatile uint8_t *) AddrSel); };
|
||||
//uint8_t wizchip_bus_readbyte(uint32_t AddrSel) { return * ((volatile uint8_t *)((ptrdiff_t) AddrSel)); };
|
||||
uint8_t wizchip_bus_readbyte(uint32_t AddrSel) { return * ((volatile uint8_t *)((ptrdiff_t) AddrSel)); }
|
||||
//M20150601 : Rename the function for integrating with W5300
|
||||
//uint8_t wizchip_bus_readbyte(uint32_t AddrSel) { return * ((volatile uint8_t *)((ptrdiff_t) AddrSel)); }
|
||||
iodata_t wizchip_bus_readdata(uint32_t AddrSel) { return * ((volatile iodata_t *)((ptrdiff_t) AddrSel)); }
|
||||
|
||||
/**
|
||||
* @brief Default function to write in direct or indirect interface.
|
||||
* @note This function help not to access wrong address. If you do not describe this function or register any functions,
|
||||
* null function is called.
|
||||
*/
|
||||
|
||||
//M20140501 : Explict pointer type casting
|
||||
//void wizchip_bus_writebyte(uint32_t AddrSel, uint8_t wb) { *((volatile uint8_t*) AddrSel) = wb; };
|
||||
//void wizchip_bus_writebyte(uint32_t AddrSel, uint8_t wb) { *((volatile uint8_t*)((ptrdiff_t)AddrSel)) = wb; };
|
||||
void wizchip_bus_writebyte(uint32_t AddrSel, uint8_t wb) { *((volatile uint8_t*)((ptrdiff_t)AddrSel)) = wb; }
|
||||
//M20150601 : Rename the function for integrating with W5300
|
||||
//void wizchip_bus_writebyte(uint32_t AddrSel, uint8_t wb) { *((volatile uint8_t*)((ptrdiff_t)AddrSel)) = wb; }
|
||||
void wizchip_bus_writedata(uint32_t AddrSel, iodata_t wb) { *((volatile iodata_t*)((ptrdiff_t)AddrSel)) = wb; }
|
||||
|
||||
/**
|
||||
* @brief Default function to read in SPI interface.
|
||||
@ -173,8 +170,11 @@ _WIZCHIP WIZCHIP =
|
||||
wizchip_cris_exit,
|
||||
wizchip_cs_select,
|
||||
wizchip_cs_deselect,
|
||||
wizchip_bus_readbyte,
|
||||
wizchip_bus_writebyte
|
||||
//M20150601 : Rename the function
|
||||
//wizchip_bus_readbyte,
|
||||
//wizchip_bus_writebyte
|
||||
wizchip_bus_readdata,
|
||||
wizchip_bus_writedata,
|
||||
// wizchip_spi_readbyte,
|
||||
// wizchip_spi_writebyte
|
||||
};
|
||||
@ -211,10 +211,13 @@ void reg_wizchip_cs_cbfunc(void(*cs_sel)(void), void(*cs_desel)(void))
|
||||
}
|
||||
}
|
||||
|
||||
void reg_wizchip_bus_cbfunc(uint8_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, uint8_t wb))
|
||||
//M20150515 : For integrating with W5300
|
||||
//void reg_wizchip_bus_cbfunc(uint8_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, uint8_t wb))
|
||||
void reg_wizchip_bus_cbfunc(iodata_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, iodata_t wb))
|
||||
{
|
||||
while(!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_BUS_));
|
||||
|
||||
//M20150601 : Rename call back function for integrating with W5300
|
||||
/*
|
||||
if(!bus_rb || !bus_wb)
|
||||
{
|
||||
WIZCHIP.IF.BUS._read_byte = wizchip_bus_readbyte;
|
||||
@ -225,6 +228,17 @@ void reg_wizchip_bus_cbfunc(uint8_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint
|
||||
WIZCHIP.IF.BUS._read_byte = bus_rb;
|
||||
WIZCHIP.IF.BUS._write_byte = bus_wb;
|
||||
}
|
||||
*/
|
||||
if(!bus_rb || !bus_wb)
|
||||
{
|
||||
WIZCHIP.IF.BUS._read_data = wizchip_bus_readdata;
|
||||
WIZCHIP.IF.BUS._write_data = wizchip_bus_writedata;
|
||||
}
|
||||
else
|
||||
{
|
||||
WIZCHIP.IF.BUS._read_data = bus_rb;
|
||||
WIZCHIP.IF.BUS._write_data = bus_wb;
|
||||
}
|
||||
}
|
||||
|
||||
void reg_wizchip_spi_cbfunc(uint8_t (*spi_rb)(void), void (*spi_wb)(uint8_t wb))
|
||||
@ -290,7 +304,9 @@ int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg)
|
||||
case CW_GET_INTRMASK:
|
||||
*((intr_kind*)arg) = wizchip_getinterruptmask();
|
||||
break;
|
||||
#if _WIZCHIP_ > 5100
|
||||
//M20150601 : This can be supported by W5200, W5500
|
||||
//#if _WIZCHIP_ > 5100
|
||||
#if (_WIZCHIP_ == 5200 || _WIZCHIP_ == 5500)
|
||||
case CW_SET_INTRTIME:
|
||||
setINTLEVEL(*(uint16_t*)arg);
|
||||
break;
|
||||
@ -372,10 +388,21 @@ void wizchip_sw_reset(void)
|
||||
{
|
||||
uint8_t gw[4], sn[4], sip[4];
|
||||
uint8_t mac[6];
|
||||
//A20150601
|
||||
#if _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_
|
||||
uint16_t mr = (uint16_t)getMR();
|
||||
setMR(mr | MR_IND);
|
||||
#endif
|
||||
//
|
||||
getSHAR(mac);
|
||||
getGAR(gw); getSUBR(sn); getSIPR(sip);
|
||||
setMR(MR_RST);
|
||||
getMR(); // for delay
|
||||
//A2015051 : For indirect bus mode
|
||||
#if _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_BUS_INDIR_
|
||||
setMR(mr | MR_IND);
|
||||
#endif
|
||||
//
|
||||
setSHAR(mac);
|
||||
setGAR(gw);
|
||||
setSUBR(sn);
|
||||
@ -390,18 +417,44 @@ int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
|
||||
if(txsize)
|
||||
{
|
||||
tmp = 0;
|
||||
//M20150601 : For integrating with W5300
|
||||
#if _WIZCHIP_ == 5300
|
||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||
{
|
||||
if(txsize[i] >= 64) return -1; //No use 64KB even if W5300 support max 64KB memory allocation
|
||||
tmp += txsize[i];
|
||||
if(tmp > 16) return -1;
|
||||
if(tmp > 128) return -1;
|
||||
}
|
||||
if(tmp % 8) return -1;
|
||||
#else
|
||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||
{
|
||||
tmp += txsize[i];
|
||||
if(tmp > 16) return -1;
|
||||
}
|
||||
#endif
|
||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||
setSn_TXBUF_SIZE(i, txsize[i]);
|
||||
}
|
||||
if(rxsize)
|
||||
{
|
||||
tmp = 0;
|
||||
#if _WIZCHIP_ == 5300
|
||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||
{
|
||||
if(rxsize[i] >= 64) return -1; //No use 64KB even if W5300 support max 64KB memory allocation
|
||||
tmp += rxsize[i];
|
||||
if(tmp > 16) return -1;
|
||||
if(tmp > 128) return -1;
|
||||
}
|
||||
if(tmp % 8) return -1;
|
||||
#else
|
||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||
{
|
||||
tmp += rxsize[i];
|
||||
if(tmp > 16) return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||
setSn_RXBUF_SIZE(i, rxsize[i]);
|
||||
}
|
||||
@ -426,6 +479,9 @@ void wizchip_clrinterrupt(intr_kind intr)
|
||||
#if _WIZCHIP_ == 5100
|
||||
ir |= sir;
|
||||
setIR(ir);
|
||||
//A20150601 : For integrating with W5300
|
||||
#elif _WIZCHIP_ == 5300
|
||||
setIR( ((((uint16_t)ir) << 8) | (((uint16_t)sir) & 0x00FF)) );
|
||||
#else
|
||||
setIR(ir);
|
||||
setSIR(sir);
|
||||
@ -440,12 +496,19 @@ intr_kind wizchip_getinterrupt(void)
|
||||
#if _WIZCHIP_ == 5100
|
||||
ir = getIR();
|
||||
sir = ir & 0x0F;
|
||||
//A20150601 : For integrating with W5300
|
||||
#elif _WIZCHIP_ == 5300
|
||||
ret = getIR();
|
||||
ir = (uint8_t)(ret >> 8);
|
||||
sir = (uint8_t)ret;
|
||||
#else
|
||||
ir = getIR();
|
||||
sir = getSIR();
|
||||
#endif
|
||||
|
||||
#if _WIZCHIP_ < 5500
|
||||
//M20150601 : For Integrating with W5300
|
||||
//#if _WIZCHIP_ < 5500
|
||||
#if _WIZCHIP_ < 5200
|
||||
ir &= ~(1<<4); // IK_WOL
|
||||
#endif
|
||||
#if _WIZCHIP_ == 5200
|
||||
@ -471,6 +534,9 @@ void wizchip_setinterruptmask(intr_kind intr)
|
||||
simr &= 0x0F;
|
||||
imr |= simr;
|
||||
setIMR(imr);
|
||||
//A20150601 : For integrating with W5300
|
||||
#elif _WIZCHIP_ == 5300
|
||||
setIMR( ((((uint16_t)imr) << 8) | (((uint16_t)simr) & 0x00FF)) );
|
||||
#else
|
||||
setIMR(imr);
|
||||
setSIMR(simr);
|
||||
@ -485,6 +551,11 @@ intr_kind wizchip_getinterruptmask(void)
|
||||
#if _WIZCHIP_ == 5100
|
||||
imr = getIMR();
|
||||
simr = imr & 0x0F;
|
||||
//A20150601 : For integrating with W5300
|
||||
#elif _WIZCHIP_ == 5300
|
||||
ret = getIMR();
|
||||
imr = (uint8_t)(ret >> 8);
|
||||
simr = (uint8_t)ret;
|
||||
#else
|
||||
imr = getIMR();
|
||||
simr = getSIMR();
|
||||
|
Reference in New Issue
Block a user