forked from xuos/xiuos
feat: keep client connect request after timeout
This commit is contained in:
parent
f8b8ac46ca
commit
e0de3d1e46
|
@ -67,7 +67,9 @@ void InitBoardHardware()
|
||||||
InitHwUart();
|
InitHwUart();
|
||||||
InstallConsole("uart1", "uart1_drv", "uart1_dev1");
|
InstallConsole("uart1", "uart1_drv", "uart1_dev1");
|
||||||
|
|
||||||
|
#ifdef BSP_USING_ETH
|
||||||
InitHwEth();
|
InitHwEth();
|
||||||
|
#endif
|
||||||
|
|
||||||
KPrintf("consle init completed.\n");
|
KPrintf("consle init completed.\n");
|
||||||
KPrintf("board initialization......\n");
|
KPrintf("board initialization......\n");
|
||||||
|
|
|
@ -103,28 +103,6 @@ void WCHNET_CreateTcpSocket(uint8_t* DESIP, uint16_t srcport, uint16_t desport,
|
||||||
mStopIfError(i);
|
mStopIfError(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
|
||||||
* @fn WCHNET_CreateTcpSocketListen
|
|
||||||
*
|
|
||||||
* @brief Create TCP Socket for Listening
|
|
||||||
*
|
|
||||||
* @return none
|
|
||||||
*/
|
|
||||||
void WCHNET_CreateTcpSocketListen(uint16_t srcport, uint8_t* SocketId)
|
|
||||||
{
|
|
||||||
uint8_t i;
|
|
||||||
SOCK_INF TmpSocketInf;
|
|
||||||
|
|
||||||
memset((void*)&TmpSocketInf, 0, sizeof(SOCK_INF));
|
|
||||||
TmpSocketInf.SourPort = srcport;
|
|
||||||
TmpSocketInf.ProtoType = PROTO_TYPE_TCP;
|
|
||||||
i = WCHNET_SocketCreat(SocketId, &TmpSocketInf);
|
|
||||||
KPrintf("SocketIdForListen %d\r\n", *SocketId);
|
|
||||||
mStopIfError(i);
|
|
||||||
i = WCHNET_SocketListen(*SocketId); // listen for connections
|
|
||||||
mStopIfError(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* @fn WCHNET_DataLoopback
|
* @fn WCHNET_DataLoopback
|
||||||
*
|
*
|
||||||
|
@ -164,9 +142,9 @@ void WCHNET_DataLoopback(uint8_t id)
|
||||||
* @param socketid - socket id.
|
* @param socketid - socket id.
|
||||||
* intstat - interrupt status
|
* intstat - interrupt status
|
||||||
*
|
*
|
||||||
* @return none
|
* @return 0 or TIME_OUT
|
||||||
*/
|
*/
|
||||||
void WCHNET_HandleSockInt(uint8_t socketid, uint8_t intstat)
|
int WCHNET_HandleSockInt(uint8_t socketid, uint8_t intstat)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
|
@ -208,7 +186,9 @@ void WCHNET_HandleSockInt(uint8_t socketid, uint8_t intstat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KPrintf("TCP Timeout\r\n");
|
KPrintf("TCP Timeout\r\n");
|
||||||
|
return TIME_OUT;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
|
@ -216,9 +196,9 @@ void WCHNET_HandleSockInt(uint8_t socketid, uint8_t intstat)
|
||||||
*
|
*
|
||||||
* @brief Global Interrupt Handle
|
* @brief Global Interrupt Handle
|
||||||
*
|
*
|
||||||
* @return none
|
* @return 0 or SockInt
|
||||||
*/
|
*/
|
||||||
void WCHNET_HandleGlobalInt(void)
|
int WCHNET_HandleGlobalInt(void)
|
||||||
{
|
{
|
||||||
uint8_t intstat;
|
uint8_t intstat;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
@ -242,10 +222,12 @@ void WCHNET_HandleGlobalInt(void)
|
||||||
if (intstat & GINT_STAT_SOCKET) { // socket related interrupt
|
if (intstat & GINT_STAT_SOCKET) { // socket related interrupt
|
||||||
for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) {
|
for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) {
|
||||||
socketint = WCHNET_GetSocketInt(i);
|
socketint = WCHNET_GetSocketInt(i);
|
||||||
if (socketint)
|
if (socketint) {
|
||||||
WCHNET_HandleSockInt(i, socketint);
|
return WCHNET_HandleSockInt(i, socketint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t InitHwEth()
|
uint8_t InitHwEth()
|
||||||
|
|
|
@ -9,7 +9,6 @@ uint16_t desport = 1000; // destination port
|
||||||
uint16_t srcport = 1000; // source port
|
uint16_t srcport = 1000; // source port
|
||||||
|
|
||||||
uint8_t SocketId;
|
uint8_t SocketId;
|
||||||
uint8_t SocketIdForListen; // Socket for Listening
|
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* @fn TCP client
|
* @fn TCP client
|
||||||
|
@ -30,7 +29,9 @@ int Tcp_Client(void)
|
||||||
/*Query the Ethernet global interrupt,
|
/*Query the Ethernet global interrupt,
|
||||||
* if there is an interrupt, call the global interrupt handler*/
|
* if there is an interrupt, call the global interrupt handler*/
|
||||||
if (WCHNET_QueryGlobalInt()) {
|
if (WCHNET_QueryGlobalInt()) {
|
||||||
WCHNET_HandleGlobalInt();
|
if (WCHNET_HandleGlobalInt() == TIME_OUT) {
|
||||||
|
WCHNET_CreateTcpSocket(DESIP, srcport, desport, &SocketId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,29 +45,3 @@ int test_tcp_client(int argc, char* argv[])
|
||||||
|
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||||
test_tcp_client, test_tcp_client, test tcp client);
|
test_tcp_client, test_tcp_client, test tcp client);
|
||||||
|
|
||||||
int Tcp_Server(void)
|
|
||||||
{
|
|
||||||
WCHNET_CreateTcpSocketListen(srcport, &SocketIdForListen); // Create TCP Socket for Listening
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
/*Ethernet library main task function,
|
|
||||||
* which needs to be called cyclically*/
|
|
||||||
WCHNET_MainTask();
|
|
||||||
/*Query the Ethernet global interrupt,
|
|
||||||
* if there is an interrupt, call the global interrupt handler*/
|
|
||||||
if (WCHNET_QueryGlobalInt()) {
|
|
||||||
WCHNET_HandleGlobalInt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_tcp_server(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
KPrintf("TCPServer Test\r\n");
|
|
||||||
Tcp_Server();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
|
||||||
test_tcp_server, test_tcp_server, test tcp server);
|
|
|
@ -31,7 +31,9 @@ uint8_t InitHwEth();
|
||||||
void WCHNET_CreateTcpSocket(uint8_t* DESIP, uint16_t srcport, uint16_t desport, uint8_t* SocketId);
|
void WCHNET_CreateTcpSocket(uint8_t* DESIP, uint16_t srcport, uint16_t desport, uint8_t* SocketId);
|
||||||
void WCHNET_CreateTcpSocketListen(uint16_t srcport, uint8_t* SocketId);
|
void WCHNET_CreateTcpSocketListen(uint16_t srcport, uint8_t* SocketId);
|
||||||
|
|
||||||
void WCHNET_HandleGlobalInt(void);
|
int WCHNET_HandleGlobalInt(void);
|
||||||
|
|
||||||
|
#define TIME_OUT -1
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue