fixed socket bug and optimize with lwip flag and other codes

This commit is contained in:
wlyu
2022-01-17 15:21:15 +08:00
parent c0de7ca44c
commit 169c3c3c5d
8 changed files with 746 additions and 783 deletions
File diff suppressed because it is too large Load Diff
@@ -84,11 +84,9 @@
char lwip_ipaddr[] = {192, 168, 250, 253};
char lwip_netmask[] = {255, 255, 255, 0};
char lwip_gwaddr[] = {192, 168, 250, 252};
int is_lwip_test = 0; //for lwip input thread
char lwip_flag = 0;
x_ticks_t lwip_sys_now;
static int lwip_init_flag = 0;
struct sys_timeouts {
struct sys_timeo *next;
@@ -491,7 +489,7 @@ void lwip_config_net(char *ip, char *mask, char *gw)
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
};
if(lwip_init_flag)
if(chk_lwip_bit(LWIP_INIT_FLAG))
{
lw_print("lw: [%s] already ...\n", __func__);
@@ -507,7 +505,7 @@ void lwip_config_net(char *ip, char *mask, char *gw)
netif_set_up(&gnetif);
return;
}
lwip_init_flag = 1;
set_lwip_bit(LWIP_INIT_FLAG);
lw_print("lw: [%s] start ...\n", __func__);
@@ -522,7 +520,7 @@ void lwip_config_net(char *ip, char *mask, char *gw)
netif_set_default(&gnetif);
netif_set_up(&gnetif);
if(is_lwip_test)
if(chk_lwip_bit(LWIP_PRINT_FLAG))
{
lw_pr_info("\r\n************************************************\r\n");
lw_pr_info(" Network Configuration\r\n");
@@ -553,12 +551,13 @@ void lwip_config_tcp(char *ip, char *mask, char *gw)
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
};
if(lwip_init_flag)
if(chk_lwip_bit(LWIP_INIT_FLAG))
{
lw_print("lw: [%s] already ...\n", __func__);
return;
}
lwip_init_flag = 1;
set_lwip_bit(LWIP_INIT_FLAG);
tcpip_init(NULL, NULL);
@@ -66,7 +66,7 @@
#define LWIP_DEMO_TIMES 3
#define LWIP_TASK_STACK_SIZE 4096
#define LWIP_TASK_PRIO 15
#define LWIP_DEMO_TASK_PRIO 20
/* MAC address configuration. */
#define configMAC_ADDR {0x02, 0x12, 0x13, 0x10, 0x15, 0x11}
@@ -82,16 +82,23 @@ typedef int32 sys_mbox_t;
typedef int32 sys_thread_t;
typedef x_base sys_prot_t;
#define MS_PER_SYSTICK_F407 1000/TICK_PER_SECOND
#define MS_PER_SYSTICK_F407 (1000 / TICK_PER_SECOND)
//debug rtos with IRQ
//#define FSL_RTOS_XIUOS
extern char lwip_flag;
#define LWIP_INIT_FLAG (1 << 0)
#define LWIP_PRINT_FLAG (1 << 1)
#define set_lwip_bit(__bit) lwip_flag |= (__bit)
#define clr_lwip_bit(__bit) lwip_flag &= ~(__bit)
#define chk_lwip_bit(__bit) ((lwip_flag & (__bit)) == (__bit))
extern char lwip_ipaddr[];
extern char lwip_netmask[];
extern char lwip_gwaddr[];
extern int is_lwip_test;
extern int lwip_sempahore;
extern struct netif gnetif;
void lwip_tcp_init(void);
@@ -133,7 +133,7 @@ void lwip_dhcp_test(void)
ETH_BSP_Config();
lwip_config_net(ip_addr, ip_addr, ip_addr);
is_lwip_test = 1;
set_lwip_bit(LWIP_PRINT_FLAG);
dhcp_start(&gnetif);
@@ -167,7 +167,7 @@ void lwip_dhcp_test(void)
}
}
is_lwip_test = 0;
clr_lwip_bit(LWIP_PRINT_FLAG);
}
@@ -101,11 +101,13 @@ void lwip_ping_thread(int argc, char *argv[])
return;
}
}
#if (LWIP_DHCP) && (PING_USE_SOCKETS)
else
{
get_url_ip(argv[1]);
return;
}
#endif
}
lw_print("lw: [%s] argc %d\n", __func__, argc);
@@ -105,7 +105,7 @@ void lwip_tcp_send_run(int argc, char *argv[])
ETH_BSP_Config();
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
sys_thread_new("tcp send", lwip_tcp_send_thread, NULL, LWIP_TASK_STACK_SIZE, LWIP_TASK_PRIO);
sys_thread_new("tcp send", lwip_tcp_send_thread, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
@@ -105,10 +105,6 @@ static u32_t ping_time;
static struct raw_pcb *ping_pcb;
#endif /* PING_USE_SOCKETS */
#define PING_THREAD_STACKSIZE 4096
#define PING_THREAD_PRIO 15
/** Prepare a echo ICMP request */
static void
ping_prepare_echo( struct icmp_echo_hdr *iecho, u16_t len)
@@ -268,7 +264,7 @@ ping_thread(void *arg)
s = lwip_socket(AF_INET6, SOCK_RAW, IP6_NEXTH_ICMP6);
}
#else
s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP);
s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP);
#endif
if (s < 0) {
lw_print("lw: [%s] ping failed %d!\n", __func__, s);
@@ -412,7 +408,7 @@ ping_init(const ip_addr_t* ping_addr)
ping_target = ping_addr;
#if PING_USE_SOCKETS
th = sys_thread_new("ping_thread", ping_thread, NULL, PING_THREAD_STACKSIZE, PING_THREAD_PRIO);
th = sys_thread_new("ping_thread", ping_thread, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
lw_print("lw: [%s] new thread %d addr %#x\n", __func__, th, (*ping_addr).addr);
#else /* PING_USE_SOCKETS */
ping_raw_init();
@@ -476,6 +472,7 @@ int lwip_ping_recv(int s, int *ttl)
return len;
}
#if (LWIP_DHCP) && (PING_USE_SOCKETS)
int get_url_ip(char* url)
{
#if LWIP_VERSION_MAJOR >= 2U
@@ -539,6 +536,6 @@ int get_url_ip(char* url)
lwip_close(s);
return 0;
}
#endif
#endif /* LWIP_RAW */