diff --git a/at_socket_esp8266.c b/at_socket_esp8266.c index e349870..be7c3ef 100644 --- a/at_socket_esp8266.c +++ b/at_socket_esp8266.c @@ -35,6 +35,8 @@ #define ESP8266_MODULE_SEND_MAX_SIZE 2048 #define ESP8266_WAIT_CONNECT_TIME 5000 +#define ESP8266_THREAD_STACK_SIZE 1024 +#define ESP8266_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX/2) /* set real event by current socket and current state */ #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -563,7 +565,7 @@ int at_client_port_init(void) } \ } while(0); \ -static int esp8266_net_init(void) +static void esp8266_init_thread_entry(void *parameter) { at_response_t resp = RT_NULL; rt_err_t result = RT_EOK; @@ -622,8 +624,25 @@ __exit: { LOG_E("AT network initialize failed (%d)!", result); } +} - return RT_EOK; +int esp8266_net_init(void) +{ +#ifdef PKG_AT_INIT_BY_THREAD + rt_thread_t tid; + + tid = rt_thread_create("esp8266_net_init", esp8266_init_thread_entry, RT_NULL,ESP8266_THREAD_STACK_SIZE, ESP8266_THREAD_PRIORITY, 20); + if (tid) + { + rt_thread_startup(tid); + } + else + { + LOG_E("Create AT initialization thread fail!"); + } +#else + esp8266_init_thread_entry(RT_NULL); +#endif } int esp8266_ping(int argc, char **argv) diff --git a/at_socket_m26.c b/at_socket_m26.c index 9d143c7..5d70354 100644 --- a/at_socket_m26.c +++ b/at_socket_m26.c @@ -35,6 +35,8 @@ #define M26_MODULE_SEND_MAX_SIZE 1460 #define M26_WAIT_CONNECT_TIME 5000 +#define M26_THREAD_STACK_SIZE 1024 +#define M26_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX/2) /* set real event by current socket and current state */ #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -648,7 +650,7 @@ int at_client_port_init(void) } while(0); \ /* init for M26 or MC20 */ -int m26_net_init(void) +static void m26_init_thread_entry(void *parameter) { #define CPIN_RETRY 10 #define CSQ_RETRY 10 @@ -670,8 +672,11 @@ int m26_net_init(void) } LOG_D("Start initializing the M26/MC20 module"); /* wait M26 startup finish */ - at_client_wait_connect(M26_WAIT_CONNECT_TIME); - + if (at_client_wait_connect(M26_WAIT_CONNECT_TIME)) + { + result = -RT_ETIMEOUT; + goto __exit; + } /* disable echo */ AT_SEND_CMD(resp, 0, 300, "ATE0"); /* get module version */ @@ -799,7 +804,25 @@ __exit: LOG_E("AT network initialize failed (%d)!", result); } - return result; +} + +int m26_net_init(void) +{ +#ifdef PKG_AT_INIT_BY_THREAD + rt_thread_t tid; + + tid = rt_thread_create("m26_net_init", m26_init_thread_entry, RT_NULL, M26_THREAD_STACK_SIZE, M26_THREAD_PRIORITY, 20); + if (tid) + { + rt_thread_startup(tid); + } + else + { + LOG_E("Create AT initialization thread fail!"); + } +#else + m26_init_thread_entry(RT_NULL); +#endif } int m26_ping(int argc, char **argv)