diff --git a/components/lwip/port/esp8266/freertos/sys_arch.c b/components/lwip/port/esp8266/freertos/sys_arch.c index 91fd6322..e3bc1b4c 100644 --- a/components/lwip/port/esp8266/freertos/sys_arch.c +++ b/components/lwip/port/esp8266/freertos/sys_arch.c @@ -59,6 +59,8 @@ struct timeoutlist { //static u16_t nextthread = 0; int intlevel = 0; +static xTaskHandle s_tcpip_task_handle; + /*-----------------------------------------------------------------------------------*/ // Initialize sys arch void @@ -365,18 +367,27 @@ sys_now(void) sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio) { - xTaskHandle CreatedTask; portBASE_TYPE result; - result = xTaskCreate(thread, (const char *)name, stacksize, arg, prio, &CreatedTask); + result = xTaskCreate(thread, (const char *)name, stacksize, arg, prio, &s_tcpip_task_handle); if (result == pdPASS) { - return CreatedTask; + return s_tcpip_task_handle; } else { return NULL; } } +int sys_current_task_is_tcpip(void) +{ + return xTaskGetCurrentTaskHandle() == s_tcpip_task_handle ? 1 : 0; +} + +char *sys_current_task_name(void) +{ + return pcTaskGetTaskName(xTaskGetCurrentTaskHandle()); +} + /* This optional function does a "fast" critical region protection and returns the previous protection level. This function is only called during very short diff --git a/components/lwip/port/esp8266/freertos/udp_sync.c b/components/lwip/port/esp8266/freertos/udp_sync.c index 71ec3e50..4a4039f3 100644 --- a/components/lwip/port/esp8266/freertos/udp_sync.c +++ b/components/lwip/port/esp8266/freertos/udp_sync.c @@ -127,9 +127,9 @@ void udp_sync_ack(void *in_msg) void udp_sync_set_ret(void *netif, int ret) { /* Only poll and regitser can set current message */ - if (!s_cur_msg) { + if (!s_cur_msg || !sys_current_task_is_tcpip()) { /* You may use it to debug */ - //ESP_LOGE(TAG, "UDP sync ack error, current message is NULL"); + //ESP_LOGE(TAG, "UDP sync ack error, current message is %p, task name is %s", s_cur_msg, sys_current_task_name()); return ; } @@ -173,12 +173,29 @@ void udp_sync_proc(void) continue; udp_sync_send(s_udp_sync[i].msg); -#if 0 - //Todo: Add this later - if (s_udp_sync[i].ret != ERR_OK) + + if (s_udp_sync[i].ret == ERR_MEM) break; -#endif } } +/* + * @brief NULL function and just as sync message + */ +static void udp_sync_trigger_null(void *p) +{ + +} + +/* + * @brief trigger a UDP sync process + */ +void udp_sync_trigger(void) +{ + if (!s_udp_sync_num) + return ; + + tcpip_callback_with_block((tcpip_callback_fn)udp_sync_trigger_null, NULL, 0); +} + #endif /* ESP_UDP */ diff --git a/components/lwip/port/esp8266/include/arch/sys_arch.h b/components/lwip/port/esp8266/include/arch/sys_arch.h index 8bf1b568..4b3bd8a8 100644 --- a/components/lwip/port/esp8266/include/arch/sys_arch.h +++ b/components/lwip/port/esp8266/include/arch/sys_arch.h @@ -57,6 +57,10 @@ void sys_thread_sem_deinit(void); sys_sem_t* sys_thread_sem_get(void); err_t sys_mutex_trylock(sys_mutex_t *pxMutex); +int sys_current_task_is_tcpip(void); + +char *sys_current_task_name(void); + #define LWIP_NETCONN_THREAD_SEM_ALLOC() sys_thread_sem_init() #define LWIP_NETCONN_THREAD_SEM_FREE() sys_thread_sem_deinit() #define LWIP_NETCONN_THREAD_SEM_GET() sys_thread_sem_get() diff --git a/components/lwip/port/esp8266/include/udp_sync.h b/components/lwip/port/esp8266/include/udp_sync.h index b1040d49..055361e3 100644 --- a/components/lwip/port/esp8266/include/udp_sync.h +++ b/components/lwip/port/esp8266/include/udp_sync.h @@ -52,6 +52,11 @@ void udp_sync_set_ret(void *netif, int ret); */ void udp_sync_proc(void); +/* + * @brief trigger a UDP sync process + */ +void udp_sync_trigger(void); + #ifdef __cplusplus } #endif diff --git a/components/lwip/port/esp8266/netif/ethernetif.c b/components/lwip/port/esp8266/netif/ethernetif.c index 8ec20eca..1c3edf90 100644 --- a/components/lwip/port/esp8266/netif/ethernetif.c +++ b/components/lwip/port/esp8266/netif/ethernetif.c @@ -238,6 +238,8 @@ static int low_level_send_cb(esp_aio_t* aio) pbuf_free(pbuf); + udp_sync_trigger(); + return 0; }