void ip_init(void){ wiz_NetInfo netInfo; uint8_t bufSize[] = {2, 2, 2, 2}; reg_wizchip_cs_cbfunc(cs_sel, cs_desel); reg_wizchip_spi_cbfunc(spi_rb, spi_wb); wizphy_reset(); wizchip_init(bufSize, bufSize); memcpy_P(&netInfo, &network_info, sizeof(wiz_NetInfo)); wizchip_setnetinfo(&netInfo); sock_state=IP_STATE_NO_SOCKET; }
// brief Initialize modules static void W5500_Init(void){ // Set Tx and Rx buffer size to 2KB uint8_t buffsize[8] = { 2, 2, 2, 2, 2, 2, 2, 2 }; // Reset module PMOD_PORT &= ~_BV(RST_W5500); //Set Rst low _delay_ms(500); //Minimun of 500us, 10ms to be safe PMOD_PORT |= _BV(RST_W5500); //Set rst high _delay_ms(1); // Wizchip initialize wizchip_init(buffsize, buffsize, 0, 0, cs_sel, cs_desel, 0, 0, spi_rb, spi_wb); // Wizchip netconf ctlnetwork(CN_SET_NETINFO, (void*) &gWIZNETINFO); ctlwizchip(CW_SET_PHYCONF, (void*) &phyConf); }
int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg) { uint8_t tmp = 0; uint8_t* ptmp[2] = {0,0}; switch(cwtype) { case CW_RESET_WIZCHIP: wizchip_sw_reset(); break; case CW_INIT_WIZCHIP: if(arg != 0) { ptmp[0] = (uint8_t*)arg; ptmp[1] = ptmp[0] + _WIZCHIP_SOCK_NUM_; } return wizchip_init(ptmp[0], ptmp[1]);; case CW_CLR_INTERRUPT: wizchip_clrinterrupt(*((intr_kind*)arg)); break; case CW_GET_INTERRUPT: *((intr_kind*)arg) = wizchip_getinterrupt(); break; case CW_SET_INTRMASK: wizchip_setinterruptmask(*((intr_kind*)arg)); break; case CW_GET_INTRMASK: *((intr_kind*)arg) = wizchip_getinterruptmask(); break; #if _WIZCHIP_ > 5100 case CW_SET_INTRTIME: setINTLEVEL(*(uint16_t*)arg); break; case CW_GET_INTRTIME: *(uint16_t*)arg = getINTLEVEL(); break; #endif case CW_GET_ID: ((uint8_t*)arg)[0] = WIZCHIP.id[0]; ((uint8_t*)arg)[1] = WIZCHIP.id[1]; ((uint8_t*)arg)[2] = WIZCHIP.id[2]; ((uint8_t*)arg)[3] = WIZCHIP.id[3]; ((uint8_t*)arg)[4] = WIZCHIP.id[4]; ((uint8_t*)arg)[5] = 0; break; #if _WIZCHIP_ == 5500 case CW_RESET_PHY: wizphy_reset(); break; case CW_SET_PHYCONF: wizphy_setphyconf((wiz_PhyConf*)arg); break; case CW_GET_PHYCONF: wizphy_getphyconf((wiz_PhyConf*)arg); break; case CW_GET_PHYSTATUS: break; case CW_SET_PHYPOWMODE: return wizphy_setphypmode(*(uint8_t*)arg); #endif case CW_GET_PHYPOWMODE: tmp = wizphy_getphypmode(); if((int8_t)tmp == -1) return -1; *(uint8_t*)arg = tmp; break; case CW_GET_PHYLINK: tmp = wizphy_getphylink(); if((int8_t)tmp == -1) return -1; *(uint8_t*)arg = tmp; break; default: return -1; } return 0; }
int main(void) { uint8_t tmp=0; int32_t ret = 0; uint8_t memsize[2][8] = {{2,2,2,2,2,2,2,2},{2,2,2,2,2,2,2,2}}; uint8_t txsize[8] = {2,2,2,2,2,2,2,2}; uint8_t rxsize[8] = {2,2,2,2,2,2,2,2}; uint8_t pDestaddr[4] = {192,168,0,200}; int8_t num; uint8_t ping_reply_received = 0; /////////////////////////////////////////// // Host dependent peripheral initialized // /////////////////////////////////////////// platform_init(); ////////// // TODO // //////////////////////////////////////////////////////////////////////////////////////////////////// // First of all, Should register SPI callback functions implemented by user for accessing WIZCHIP // //////////////////////////////////////////////////////////////////////////////////////////////////// /* Critical section callback - No use in this example */ //reg_wizchip_cris_cbfunc(0, 0); /* Chip selection call back */ #if _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_ reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect); #elif _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_FDM_ reg_wizchip_cs_cbfunc(wizchip_select, wizchip_select); // CS must be tried with LOW. #else #if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SIP_) != _WIZCHIP_IO_MODE_SIP_ #error "Unknown _WIZCHIP_IO_MODE_" #else reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect); #endif #endif /* SPI Read & Write callback function */ reg_wizchip_spi_cbfunc(wizchip_read, wizchip_write); //////////////////////////////////////////////////////////////////////// /* WIZCHIP SOCKET Buffer initialize */ wizchip_init(txsize,rxsize); /* Network initialization */ network_init(); /*******************************/ /* WIZnet W5500 Code Examples */ /* TCPS/UDPS IPRAW test */ /*******************************/ printf("------------PING_TEST_START-----------------------\r\n"); tmp = ping_auto(0,pDestaddr); //tmp = ping_count(0,3,pDestaddr); if(tmp == SUCCESS) printf("-----------PING TEST OK----------\r\n"); else printf("----------ERROR = %d----------\r\n",tmp); } // end of main()