Revert "MDIO added"
This commit is contained in:
@ -1,18 +1,6 @@
|
||||
/*******************************************************************************************************************************************************
|
||||
* Copyright <20><>I 2016 <WIZnet Co.,Ltd.>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the <20><><EFBFBD><EFBFBD>Software<72><65><EFBFBD><EFBFBD>),
|
||||
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED <20><><EFBFBD><EFBFBD>AS IS<49><53><EFBFBD><EFBFBD>, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*********************************************************************************************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include "loopback.h"
|
||||
#include "socket.h"
|
||||
#include "wizchip_conf.h"
|
||||
|
||||
#if LOOPBACK_MODE == LOOPBACK_MAIN_NOBLCOK
|
||||
@ -33,30 +21,32 @@ int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port)
|
||||
if(getSn_IR(sn) & Sn_IR_CON)
|
||||
{
|
||||
#ifdef _LOOPBACK_DEBUG_
|
||||
getSn_DIPR(sn, destip);
|
||||
destport = getSn_DPORT(sn);
|
||||
printf("%d:Connected - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
|
||||
getSn_DIPR(sn, destip);
|
||||
destport = getSn_DPORT(sn);
|
||||
|
||||
printf("%d:Connected - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
|
||||
#endif
|
||||
setSn_IR(sn,Sn_IR_CON);
|
||||
setSn_IR(sn,Sn_IR_CON);
|
||||
}
|
||||
if((size = getSn_RX_RSR(sn)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur.
|
||||
if((size = getSn_RX_RSR(sn)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur.
|
||||
{
|
||||
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
|
||||
ret = recv(sn, buf, size);
|
||||
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
|
||||
ret = recv(sn, buf, size);
|
||||
|
||||
if(ret <= 0) return ret; // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY.
|
||||
sentsize = 0;
|
||||
if(ret <= 0) return ret; // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY.
|
||||
size = (uint16_t) ret;
|
||||
sentsize = 0;
|
||||
|
||||
while(size != sentsize)
|
||||
{
|
||||
ret = send(sn, buf+sentsize, size-sentsize);
|
||||
if(ret < 0)
|
||||
{
|
||||
close(sn);
|
||||
return ret;
|
||||
}
|
||||
sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
|
||||
}
|
||||
while(size != sentsize)
|
||||
{
|
||||
ret = send(sn, buf+sentsize, size-sentsize);
|
||||
if(ret < 0)
|
||||
{
|
||||
close(sn);
|
||||
return ret;
|
||||
}
|
||||
sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SOCK_CLOSE_WAIT :
|
||||
@ -70,7 +60,7 @@ int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port)
|
||||
break;
|
||||
case SOCK_INIT :
|
||||
#ifdef _LOOPBACK_DEBUG_
|
||||
printf("%d:Listen, TCP server loopback, port [%d]\r\n", sn, port);
|
||||
printf("%d:Listen, TCP server loopback, port [%d]\r\n", sn, port);
|
||||
#endif
|
||||
if( (ret = listen(sn)) != SOCK_OK) return ret;
|
||||
break;
|
||||
@ -102,7 +92,7 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo
|
||||
// uint16_t destport = 5000;
|
||||
|
||||
// Port number for TCP client (will be increased)
|
||||
uint16_t any_port = 50000;
|
||||
static uint16_t any_port = 50000;
|
||||
|
||||
// Socket Status Transitions
|
||||
// Check the W5500 Socket n status register (Sn_SR, The 'Sn_SR' controlled by Sn_CR command or Packet send/recv status)
|
||||
@ -112,35 +102,36 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo
|
||||
if(getSn_IR(sn) & Sn_IR_CON) // Socket n interrupt register mask; TCP CON interrupt = connection with peer is successful
|
||||
{
|
||||
#ifdef _LOOPBACK_DEBUG_
|
||||
printf("%d:Connected to - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
|
||||
printf("%d:Connected to - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
|
||||
#endif
|
||||
setSn_IR(sn, Sn_IR_CON); // this interrupt should be write the bit cleared to '1'
|
||||
setSn_IR(sn, Sn_IR_CON); // this interrupt should be write the bit cleared to '1'
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Data Transaction Parts; Handle the [data receive and send] process
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
if((size = getSn_RX_RSR(sn)) > 0) // Sn_RX_RSR: Socket n Received Size Register, Receiving data length
|
||||
if((size = getSn_RX_RSR(sn)) > 0) // Sn_RX_RSR: Socket n Received Size Register, Receiving data length
|
||||
{
|
||||
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE; // DATA_BUF_SIZE means user defined buffer size (array)
|
||||
ret = recv(sn, buf, size); // Data Receive process (H/W Rx socket buffer -> User's buffer)
|
||||
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE; // DATA_BUF_SIZE means user defined buffer size (array)
|
||||
ret = recv(sn, buf, size); // Data Receive process (H/W Rx socket buffer -> User's buffer)
|
||||
|
||||
if(ret <= 0) return ret; // If the received data length <= 0, receive failed and process end
|
||||
sentsize = 0;
|
||||
if(ret <= 0) return ret; // If the received data length <= 0, receive failed and process end
|
||||
size = (uint16_t) ret;
|
||||
sentsize = 0;
|
||||
|
||||
// Data sentsize control
|
||||
while(size != sentsize)
|
||||
{
|
||||
ret = send(sn, buf+sentsize, size-sentsize); // Data send process (User's buffer -> Destination through H/W Tx socket buffer)
|
||||
if(ret < 0) // Send Error occurred (sent data length < 0)
|
||||
{
|
||||
close(sn); // socket close
|
||||
return ret;
|
||||
}
|
||||
sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
|
||||
}
|
||||
// Data sentsize control
|
||||
while(size != sentsize)
|
||||
{
|
||||
ret = send(sn, buf+sentsize, size-sentsize); // Data send process (User's buffer -> Destination through H/W Tx socket buffer)
|
||||
if(ret < 0) // Send Error occurred (sent data length < 0)
|
||||
{
|
||||
close(sn); // socket close
|
||||
return ret;
|
||||
}
|
||||
sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
break;
|
||||
|
||||
case SOCK_CLOSE_WAIT :
|
||||
@ -155,16 +146,19 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo
|
||||
|
||||
case SOCK_INIT :
|
||||
#ifdef _LOOPBACK_DEBUG_
|
||||
printf("%d:Try to connect to the %d.%d.%d.%d : %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport);
|
||||
printf("%d:Try to connect to the %d.%d.%d.%d : %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport);
|
||||
#endif
|
||||
if( (ret = connect(sn, destip, destport)) != SOCK_OK) return ret; // Try to TCP connect to the TCP server (destination)
|
||||
if( (ret = connect(sn, destip, destport)) != SOCK_OK) return ret; // Try to TCP connect to the TCP server (destination)
|
||||
break;
|
||||
|
||||
case SOCK_CLOSED:
|
||||
close(sn);
|
||||
if((ret=socket(sn, Sn_MR_TCP, any_port++, 0x00)) != sn) return ret; // TCP socket open with 'any_port' port number
|
||||
close(sn);
|
||||
if((ret=socket(sn, Sn_MR_TCP, any_port++, 0x00)) != sn){
|
||||
if(any_port == 0xffff) any_port = 50000;
|
||||
return ret; // TCP socket open with 'any_port' port number
|
||||
}
|
||||
#ifdef _LOOPBACK_DEBUG_
|
||||
//printf("%d:TCP client loopback start\r\n",sn);
|
||||
//printf("%d:TCP client loopback start\r\n",sn);
|
||||
//printf("%d:Socket opened\r\n",sn);
|
||||
#endif
|
||||
break;
|
||||
@ -228,62 +222,4 @@ int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t loopback_iperf(uint8_t sn, uint8_t* buf, uint16_t port)
|
||||
{
|
||||
int32_t ret;
|
||||
uint16_t size = 0;
|
||||
|
||||
#ifdef _LOOPBACK_DEBUG_
|
||||
uint8_t destip[4];
|
||||
uint16_t destport;
|
||||
#endif
|
||||
|
||||
switch(getSn_SR(sn))
|
||||
{
|
||||
case SOCK_ESTABLISHED :
|
||||
if(getSn_IR(sn) & Sn_IR_CON)
|
||||
{
|
||||
#ifdef _LOOPBACK_DEBUG_
|
||||
getSn_DIPR(sn, destip);
|
||||
destport = getSn_DPORT(sn);
|
||||
printf("%d:Connected - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
|
||||
#endif
|
||||
setSn_IR(sn,Sn_IR_CON);
|
||||
}
|
||||
if((size = getSn_RX_RSR(sn)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur.
|
||||
{
|
||||
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
|
||||
ret = recv(sn, buf, size);
|
||||
}
|
||||
break;
|
||||
case SOCK_CLOSE_WAIT :
|
||||
#ifdef _LOOPBACK_DEBUG_
|
||||
//printf("%d:CloseWait\r\n",sn);
|
||||
#endif
|
||||
if((ret = disconnect(sn)) != SOCK_OK) return ret;
|
||||
#ifdef _LOOPBACK_DEBUG_
|
||||
printf("%d:Socket Closed\r\n", sn);
|
||||
#endif
|
||||
break;
|
||||
case SOCK_INIT :
|
||||
#ifdef _LOOPBACK_DEBUG_
|
||||
printf("%d:Listen, TCP server loopback, port [%d]\r\n", sn, port);
|
||||
#endif
|
||||
if( (ret = listen(sn)) != SOCK_OK) return ret;
|
||||
break;
|
||||
case SOCK_CLOSED:
|
||||
#ifdef _LOOPBACK_DEBUG_
|
||||
//printf("%d:TCP server loopback start\r\n",sn);
|
||||
#endif
|
||||
if((ret = socket(sn, Sn_MR_TCP, port, 0x00)) != sn) return ret;
|
||||
#ifdef _LOOPBACK_DEBUG_
|
||||
//printf("%d:Socket opened\r\n",sn);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,23 +1,7 @@
|
||||
/*******************************************************************************************************************************************************
|
||||
* Copyright <20><>I 2016 <WIZnet Co.,Ltd.>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the <20><><EFBFBD><EFBFBD>Software<72><65><EFBFBD><EFBFBD>),
|
||||
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED <20><><EFBFBD><EFBFBD>AS IS<49><53><EFBFBD><EFBFBD>, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*********************************************************************************************************************************************************/
|
||||
#ifndef _LOOPBACK_H_
|
||||
#define _LOOPBACK_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "socket.h"
|
||||
#include "W7500x_wztoe.h"
|
||||
|
||||
|
||||
/* Loopback test debug message printout enable */
|
||||
#define _LOOPBACK_DEBUG_
|
||||
@ -43,7 +27,4 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo
|
||||
/* UDP Loopback test example */
|
||||
int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port);
|
||||
|
||||
/* TCP Server loopback test example for performance test (iperf, receive only) */
|
||||
int32_t loopback_iperf(uint8_t sn, uint8_t* buf, uint16_t port);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user