feat(lwip): Add UDP sync process trigger

This commit is contained in:
Dong Heng
2018-08-29 11:53:18 +08:00
parent 3a33beb28d
commit 1ca16e5a13
5 changed files with 48 additions and 9 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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()

View File

@ -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

View File

@ -238,6 +238,8 @@ static int low_level_send_cb(esp_aio_t* aio)
pbuf_free(pbuf);
udp_sync_trigger();
return 0;
}