fixed pull conflict and socket ping test bug

This commit is contained in:
wlyu 2021-12-22 16:09:34 +08:00
commit aa43d46953
9 changed files with 68 additions and 43 deletions

View File

@ -32,11 +32,13 @@
* Includes
******************************************************************************/
//#if LWIP_IPV4 && LWIP_RAW
#if 1
#include <transform.h>
#include "lwip/opt.h"
#if LWIP_IPV4 && LWIP_RAW
#include "ping.h"
#include "lwip/opt.h"
#include "lwip/timeouts.h"
#include "lwip/init.h"
#include "netif/ethernet.h"
@ -88,6 +90,8 @@
* Variables
******************************************************************************/
static pthread_t ping_demo_id = 0;
/*******************************************************************************
* Code
******************************************************************************/
@ -95,7 +99,7 @@
/*!
* @brief Main function.
*/
int lwip_ping_test(void)
static void *lwip_ping_test(void *param)
{
struct netif fsl_netif0;
#if defined(FSL_FEATURE_SOC_LPC_ENET_COUNT) && (FSL_FEATURE_SOC_LPC_ENET_COUNT > 0)
@ -127,8 +131,6 @@ int lwip_ping_test(void)
netif_set_default(&fsl_netif0);
netif_set_up(&fsl_netif0);
ping_init(&fsl_netif0_gw);
lw_print("\r\n************************************************\r\n");
lw_print(" PING example\r\n");
lw_print("************************************************\r\n");
@ -140,6 +142,8 @@ int lwip_ping_test(void)
((u8_t *)&fsl_netif0_gw)[2], ((u8_t *)&fsl_netif0_gw)[3]);
lw_print("************************************************\r\n");
ping_init(&fsl_netif0_gw);
while (1)
{
/* Poll the driver, get any outstanding frames */
@ -148,8 +152,25 @@ int lwip_ping_test(void)
}
}
void lwip_ping_thread(void)
{
int result = 0;
pthread_attr_t attr;
attr.schedparam.sched_priority = 15;
attr.stacksize = 4096;
result = pthread_create(&ping_demo_id, &attr, lwip_ping_test, NULL);
if (0 == result) {
lw_print("lwip_ping_test successfully!\n");
} else {
lw_print("lwip_ping_test failed! error code is %d\n", result);
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
LwPingTest, lwip_ping_test, lwip_ping_test);
LwPingTest, lwip_ping_thread, lwip_ping_thread);
#endif

View File

@ -63,4 +63,3 @@ int LwipUdpDemo(int argc, char *argv[])
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
UdpTest, LwipUdpDemo, UDP socket demo function);
#endif

View File

@ -102,6 +102,9 @@ 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
@ -354,8 +357,6 @@ ping_send(struct raw_pcb *raw, const ip_addr_t *addr)
#endif /* LWIP_DEBUG */
}
pbuf_free(p);
// lw_print("lw: [%s] send %d\n", __func__, ping_size);
}
static void
@ -390,9 +391,6 @@ ping_send_now(void)
#endif /* PING_USE_SOCKETS */
#define PING_THREAD_STACKSIZE 4096
#define PING_THREAD_PRIO 0
void
ping_init(const ip_addr_t* ping_addr)
{
@ -402,7 +400,7 @@ ping_init(const ip_addr_t* ping_addr)
#if PING_USE_SOCKETS
th = sys_thread_new("ping_thread", ping_thread, NULL, PING_THREAD_STACKSIZE, PING_THREAD_PRIO);
lw_print("lw: [%s] sys %d addr %#x\n", __func__, th, (*ping_addr).addr);
lw_print("lw: [%s] new thread %d addr %#x\n", __func__, th, (*ping_addr).addr);
#else /* PING_USE_SOCKETS */
ping_raw_init();
#endif /* PING_USE_SOCKETS */

View File

@ -7,7 +7,7 @@
* PING_USE_SOCKETS: Set to 1 to use sockets, otherwise the raw api is used
*/
#ifndef PING_USE_SOCKETS
#define PING_USE_SOCKETS 0//LWIP_SOCKET
#define PING_USE_SOCKETS LWIP_SOCKET
#endif
void ping_init(const ip_addr_t* ping_addr);

View File

@ -326,7 +326,7 @@ int gethostname_lwip(char* name, size_t len);
* Copyright 2017-2018 (c) Stefan Profanter, fortiss GmbH
* Copyright 2018 (c) Jose Cabral, fortiss GmbH
*/
// tst by wly
#define UA_ARCHITECTURE_FREERTOSLWIP 1
#ifdef UA_ARCHITECTURE_FREERTOSLWIP

View File

@ -207,16 +207,18 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
---------------------------------
*/
#define DEFAULT_RAW_RECVMBOX_SIZE 10
#define DEFAULT_UDP_RECVMBOX_SIZE 10
#define DEFAULT_TCP_RECVMBOX_SIZE 10
#define DEFAULT_ACCEPTMBOX_SIZE 10
#define DEFAULT_THREAD_PRIO 25
#define DEFAULT_THREAD_STACKSIZE 1024
#define TCPIP_THREAD_NAME "lwip"
#define TCPIP_THREAD_STACKSIZE 2048
#define TCPIP_THREAD_NAME "tcp"
#define TCPIP_THREAD_STACKSIZE 4096
#define TCPIP_MBOX_SIZE 8
#define TCPIP_THREAD_PRIO 3
#define TCPIP_THREAD_PRIO 25
//#define IPERF_SERVER_THREAD_NAME "iperf_server"
//#define IPERF_SERVER_THREAD_STACKSIZE 1024
@ -234,8 +236,12 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
#define LWIP_IPV4 1
#define LWIP_RAW 1
#define FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE
#define MEMP_LIB_MALLOC 1
#define MEMP_MEM_MALLOC 1
#define lw_print KPrintf
#endif /* __LWIPOPTS_H__ */

View File

@ -269,12 +269,13 @@ sys_thread_t sys_thread_new(const char *name, lwip_thread_fn function, void *arg
arg,
(uint32)stacksize,
(uint8)prio);
if (handle >= 0)
{
StartupKTask(handle);
lw_print("lw: [%s] create %s handle %x\n", __func__, name, handle);
return handle;
}
lw_print("lw: [%s] create %s failed\n", __func__, name);
return -ERROR;
}

View File

@ -1754,7 +1754,7 @@
* sys_thread_new() when the thread is created.
*/
#if !defined TCPIP_THREAD_STACKSIZE || defined __DOXYGEN__
#define TCPIP_THREAD_STACKSIZE 0
#define TCPIP_THREAD_STACKSIZE 4096
#endif
/**
@ -1763,7 +1763,7 @@
* sys_thread_new() when the thread is created.
*/
#if !defined TCPIP_THREAD_PRIO || defined __DOXYGEN__
#define TCPIP_THREAD_PRIO 1
#define TCPIP_THREAD_PRIO 25
#endif
/**
@ -1772,7 +1772,7 @@
* sys_mbox_new() when tcpip_init is called.
*/
#if !defined TCPIP_MBOX_SIZE || defined __DOXYGEN__
#define TCPIP_MBOX_SIZE 0
#define TCPIP_MBOX_SIZE 10
#endif
/**
@ -1821,7 +1821,7 @@
* sys_thread_new() when the thread is created.
*/
#if !defined DEFAULT_THREAD_STACKSIZE || defined __DOXYGEN__
#define DEFAULT_THREAD_STACKSIZE 0
#define DEFAULT_THREAD_STACKSIZE 4096
#endif
/**
@ -1830,7 +1830,7 @@
* sys_thread_new() when the thread is created.
*/
#if !defined DEFAULT_THREAD_PRIO || defined __DOXYGEN__
#define DEFAULT_THREAD_PRIO 1
#define DEFAULT_THREAD_PRIO 25
#endif
/**
@ -1839,7 +1839,7 @@
* to sys_mbox_new() when the recvmbox is created.
*/
#if !defined DEFAULT_RAW_RECVMBOX_SIZE || defined __DOXYGEN__
#define DEFAULT_RAW_RECVMBOX_SIZE 0
#define DEFAULT_RAW_RECVMBOX_SIZE 10
#endif
/**
@ -1848,7 +1848,7 @@
* to sys_mbox_new() when the recvmbox is created.
*/
#if !defined DEFAULT_UDP_RECVMBOX_SIZE || defined __DOXYGEN__
#define DEFAULT_UDP_RECVMBOX_SIZE 0
#define DEFAULT_UDP_RECVMBOX_SIZE 10
#endif
/**
@ -1857,7 +1857,7 @@
* to sys_mbox_new() when the recvmbox is created.
*/
#if !defined DEFAULT_TCP_RECVMBOX_SIZE || defined __DOXYGEN__
#define DEFAULT_TCP_RECVMBOX_SIZE 0
#define DEFAULT_TCP_RECVMBOX_SIZE 10
#endif
/**
@ -1866,7 +1866,7 @@
* sys_mbox_new() when the acceptmbox is created.
*/
#if !defined DEFAULT_ACCEPTMBOX_SIZE || defined __DOXYGEN__
#define DEFAULT_ACCEPTMBOX_SIZE 0
#define DEFAULT_ACCEPTMBOX_SIZE 10
#endif
/**
* @}

View File

@ -130,7 +130,7 @@ typedef void (*lwip_thread_fn)(void *arg);
* If the mutex has been created, ERR_OK should be returned. Returning any
* other error will provide a hint what went wrong, but except for assertions,
* no real error handling is implemented.
*
*
* @param mutex pointer to the mutex to create
* @return ERR_OK if successful, another err_t otherwise
*/
@ -205,13 +205,13 @@ void sys_sem_signal(sys_sem_t *sem);
* "timeout" argument is non-zero, the thread should only be blocked for the
* specified time (measured in milliseconds). If the "timeout" argument is zero,
* the thread should be blocked until the semaphore is signalled.
*
*
* The return value is SYS_ARCH_TIMEOUT if the semaphore wasn't signaled within
* the specified time or any other value if it was signaled (with or without
* waiting).
* Notice that lwIP implements a function with a similar name,
* sys_sem_wait(), that uses the sys_arch_sem_wait() function.
*
*
* @param sem the semaphore to wait for
* @param timeout timeout in milliseconds to wait (0 = wait forever)
* @return SYS_ARCH_TIMEOUT on timeout, any other value on success
@ -277,7 +277,7 @@ void sys_msleep(u32_t ms); /* only has a (close to) 1 ms resolution. */
* If the mailbox has been created, ERR_OK should be returned. Returning any
* other error will provide a hint what went wrong, but except for assertions,
* no real error handling is implemented.
*
*
* @param mbox pointer to the mbox to create
* @param size (minimum) number of messages in this mbox
* @return ERR_OK if successful, another err_t otherwise
@ -287,7 +287,7 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int size);
* @ingroup sys_mbox
* Post a message to an mbox - may not fail
* -> blocks if full, only to be used from tasks NOT from ISR!
*
*
* @param mbox mbox to posts the message
* @param msg message to post (ATTENTION: can be NULL)
*/
@ -297,7 +297,7 @@ void sys_mbox_post(sys_mbox_t *mbox, void *msg);
* Try to post a message to an mbox - may fail if full.
* Can be used from ISR (if the sys arch layer allows this).
* Returns ERR_MEM if it is full, else, ERR_OK if the "msg" is posted.
*
*
* @param mbox mbox to posts the message
* @param msg message to post (ATTENTION: can be NULL)
*/
@ -307,7 +307,7 @@ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg);
* Try to post a message to an mbox - may fail if full.
* To be be used from ISR.
* Returns ERR_MEM if it is full, else, ERR_OK if the "msg" is posted.
*
*
* @param mbox mbox to posts the message
* @param msg message to post (ATTENTION: can be NULL)
*/
@ -324,10 +324,10 @@ err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg);
* The return values are the same as for the sys_arch_sem_wait() function:
* SYS_ARCH_TIMEOUT if there was a timeout, any other value if a messages
* is received.
*
*
* Note that a function with a similar name, sys_mbox_fetch(), is
* implemented by lwIP.
*
* implemented by lwIP.
*
* @param mbox mbox to get a message from
* @param msg pointer where the message is stored
* @param timeout maximum time (in milliseconds) to wait for a message (0 = wait forever)
@ -346,7 +346,7 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout);
* example, a naive implementation could be:
* \#define sys_arch_mbox_tryfetch(mbox,msg) sys_arch_mbox_fetch(mbox,msg,1)
* although this would introduce unnecessary delays.
*
*
* @param mbox mbox to get a message from
* @param msg pointer where the message is stored
* @return 0 (milliseconds) if a message has been received
@ -363,7 +363,7 @@ u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg);
* Deallocates a mailbox. If there are messages still present in the
* mailbox when the mailbox is deallocated, it is an indication of a
* programming error in lwIP and the developer should be notified.
*
*
* @param mbox mbox to delete
*/
void sys_mbox_free(sys_mbox_t *mbox);
@ -411,7 +411,7 @@ void sys_mbox_set_invalid(sys_mbox_t *mbox);
* the "stacksize" parameter. The id of the new thread is returned. Both the id
* and the priority are system dependent.
* ATTENTION: although this function returns a value, it MUST NOT FAIL (ports have to assert this!)
*
*
* @param name human-readable name for the thread (used for debugging purposes)
* @param thread thread-function
* @param arg parameter passed to 'thread'