0
0
Fork 0

feat(lwip) & build: Imporve netconn code, modify the default idf tool to use the sdk under the project path

This commit is contained in:
windowsair 2021-11-14 22:04:32 +08:00
parent 676908adae
commit 687929b43d
6 changed files with 40 additions and 12 deletions

2
idf.py
View File

@ -118,7 +118,7 @@ def check_environment():
if not executable_exists(["cmake", "--version"]):
raise FatalError("'cmake' must be available on the PATH to use %s" % PROG)
# find the directory idf.py is in, then the parent directory of this, and assume this is IDF_PATH
detected_idf_path = _realpath(os.path.join(os.path.dirname(__file__), ".."))
detected_idf_path = _realpath(os.path.join(os.path.dirname(__file__), "./ESP8266_RTOS_SDK"))
if "IDF_PATH" in os.environ:
set_idf_path = _realpath(os.environ["IDF_PATH"])
if set_idf_path != detected_idf_path:

View File

@ -173,13 +173,16 @@ void app_main()
DAP_Setup();
timer_init();
// Specify the usbip server task
#if (USE_KCP == 1)
xTaskCreate(kcp_server_task, "kcp_server", 4096, NULL, 7, NULL);
#else
//xTaskCreate(tcp_netconn_task, "tcp_server", 4096, NULL, 14, NULL);
#elif (USE_TCP_NETCONN == 1)
xTaskCreate(tcp_netconn_task, "tcp_server", 4096, NULL, 14, NULL);
#else // BSD style
xTaskCreate(tcp_server_task, "tcp_server", 4096, NULL, 14, NULL);
#endif
// DAP handle task
xTaskCreate(DAP_Thread, "DAP_Task", 2048, NULL, 10, &kDAPTaskHandle);
// SWO Trace Task

View File

@ -57,8 +57,8 @@ typedef struct
extern TaskHandle_t kDAPTaskHandle;
extern int kRestartDAPHandle;
extern uint8_t kState;
uint8_t kStateNetconn = ACCEPTING;
struct netconn *kNetconn = NULL;
int tcp_netconn_send(const void *buffer, size_t len)
@ -72,8 +72,8 @@ int tcp_netconn_send(const void *buffer, size_t len)
static void netCallback(struct netconn *conn, enum netconn_evt evt, uint16_t length)
{
// Show some callback information (debug)
debug("sock:%u\tsta:%u\tevt:%u\tlen:%u\ttyp:%u\tfla:%02X\terr:%d",
(uint32_t)conn, conn->state, evt, length, conn->type, conn->flags, conn->last_err);
debug("sock:%u\tsta:%u\tevt:%u\tlen:%u\ttyp:%u\tfla:%02x\terr:%d",
(uint32_t)conn, conn->state, evt, length, conn->type, conn->flags, conn->pending_err);
netconn_events events;
@ -173,14 +173,14 @@ void tcp_netconn_task()
{
netbuf_data(netbuf, (void *)&buffer, &len_buf);
kNetconn = events.nc;
switch (kStateNetconn)
switch (kState)
{
case ACCEPTING:
kStateNetconn = ATTACHING;
kState = ATTACHING;
case ATTACHING:
attach((uint8_t *)buffer, len_buf);
kStateNetconn = EMULATING; // FIXME
kState = EMULATING;
break;
case EMULATING:
@ -194,8 +194,18 @@ void tcp_netconn_task()
}
else
{
if (events.nc->pending_err == ERR_CLSD)
{
continue; // The same hacky way to treat a closed connection
}
os_printf("Shutting down socket and restarting...\r\n");
close_tcp_netconn(events.nc);
printf("Error read netconn %u, close it \n", (uint32_t)events.nc);
if (kState == EMULATING)
kState = ACCEPTING;
// Restart DAP Handle
kRestartDAPHandle = 1;
if (kDAPTaskHandle)
xTaskNotifyGive(kDAPTaskHandle);
}
}
}

View File

@ -4,5 +4,6 @@
#include <stdint.h>
int tcp_netconn_send(const void *buffer, size_t len);
void tcp_netconn_task();
#endif

View File

@ -3,6 +3,7 @@
#include "main/usbip_server.h"
#include "main/kcp_server.h"
#include "main/tcp_netconn.h"
#include "main/DAP_handle.h"
#include "main/wifi_configuration.h"
@ -37,8 +38,9 @@ static void send_stage2_unlink(usbip_stage2_header *req_header);
int usbip_network_send(int s, const void *dataptr, size_t size, int flags) {
#if (USE_KCP == 1)
return kcp_network_send(dataptr, size);
#else
//return tcp_netconn_send(dataptr, size);
#elif (USE_TCP_NETCONN == 1)
return tcp_netconn_send(dataptr, size);
#else // BSD style
return send(s, dataptr, size, flags);
#endif
}

View File

@ -19,11 +19,23 @@
#define DAP_IP_ADDRESS 192, 168, 137, 123
#define DAP_IP_GATEWAY 192, 168, 137, 1
#define DAP_IP_NETMASK 255, 255, 255, 0
//
#define USE_TCP_NETCONN 0
// DO NOT CHANGE
#define PORT 3240
#define CONFIG_EXAMPLE_IPV4 1
#define USE_KCP 0
#define MTU_SIZE 1500
//
#if (USE_TCP_NETCONN == 1 && USE_KCP == 1)
#error Can not use KCP and TCP at the same time!
#endif
#if (USE_KCP == 1)
#warning KCP is a very experimental feature, and it should not be used under any circumstances. Please make sure what you are doing. Related usbip version: https://github.com/windowsair/usbip-win
#endif
#endif