int8_t ctlnetwork(ctlnetwork_type cntype, void* arg) { switch(cntype) { case CN_SET_NETINFO: wizchip_setnetinfo((wiz_NetInfo*)arg); break; case CN_GET_NETINFO: wizchip_getnetinfo((wiz_NetInfo*)arg); break; case CN_SET_NETMODE: return wizchip_setnetmode(*(netmode_type*)arg); case CN_GET_NETMODE: *(netmode_type*)arg = wizchip_getnetmode(); break; case CN_SET_TIMEOUT: wizchip_settimeout((wiz_NetTimeout*)arg); break; case CN_GET_TIMEOUT: wizchip_gettimeout((wiz_NetTimeout*)arg); break; default: return -1; } return 0; }
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; }
/*Start of Main Functions*/ int main(void) { led_ctrl led1,led2; uint8_t SSLSockNo = 0; wiz_ssl_context sslContext; int ret; /*Usart initialization for Debug.*/ USART1Initialze(); printf("USART initialized.\n\r"); uint32_t i,j; /*LED initialization.*/ led_initialize(); led1 = led2 = ON; led2Ctrl(led2); led1Ctrl(led1); /*W5500 initialization.*/ W5500HardwareInitilize(); printf("W5500 hardware interface initialized.\n\r"); W5500Initialze(); printf("W5500 IC initialized.\n\r"); /*Set network informations*/ wizchip_setnetinfo(&gWIZNETINFO); print_network_information(); sysTickInit(); WIZnetRegFuncTicker(getSysTick); wiz_mbedtls_ssl_init(&sslContext,&SSLSockNo); wiz_mbedtls_ssl_socket(SSLSockNo,Sn_MR_TCP,3000,0x00); wiz_mbedtls_ssl_connect(SSLSockNo,testIP,443,1000); ret = wiz_mbedtls_ssl_handshake(&sslContext); if(ret == 0) { while(1) { memset(tempBuffer,0,BUFFER_SIZE); ret = wiz_mbedtls_ssl_read(sslContext.ssl,tempBuffer,BUFFER_SIZE); if(ret > 0) { printf("Received data: %s\r\n",tempBuffer); wiz_mbedtls_ssl_write(sslContext.ssl,tempBuffer,ret); } } } printf("ERROR: %d\r\n",ret); }
/* *System initialize */ uint8_t wizSystemInit(void) { uint8_t W5500SockBufSize[2][8] = {{2,2,2,2,2,2,2,2,},{2,2,2,2,2,2,2,2}}; uint32_t tickStart; /* spi function register */ reg_wizchip_spi_cbfunc(W5500ReadByte, W5500WriteByte); /* CS function register */ reg_wizchip_cs_cbfunc(W5500Select, W5500DeSelect); /* Critical section */ reg_wizchip_cris_cbfunc(spiMutexEnter,spiMutexExit); //W5500Select(); if(ctlwizchip(CW_INIT_WIZCHIP,(void*)W5500SockBufSize) == -1) { #if WIZSYSTEM_DEBUG == 1 printf("W5500 initialized fail.\r\n"); #endif return -1; } /*Set network information by default*/ wizchip_setnetinfo(&NetInfo); tickStart = HAL_GetTick(); do{//check phy status. randomKey++; if((HAL_GetTick() - tickStart) > NETINFO_LINK_TIMEOUT) { #if WIZSYSTEM_DEBUG == 1 printf("Ethernet Link timeout.\r\n"); #endif return -1; } }while(!isLinked()); return 1; }