diff --git a/ChangeLog.md b/ChangeLog.md index b7360119..4f50fc32 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,7 @@ +## [2.5.2] - 2022-06-28 +### Changed +- modify the global lock to protect the at agent. + ## [2.5.1] - 2022-06-02 ### Added - add dynamic create and destroy api for task, sem, mutex, event, timer and corresponding unit test case. diff --git a/devices/ec20_200_600/ec600s.c b/devices/ec20_200_600/ec600s.c index 4b135183..e3109338 100644 --- a/devices/ec20_200_600/ec600s.c +++ b/devices/ec20_200_600/ec600s.c @@ -42,7 +42,7 @@ static int ec600s_check_ready(void) { at_echo_t echo; int try = 0; - + while (try++ < 10) { tos_at_echo_create(&echo, NULL, 0, NULL); tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT\r\n"); @@ -60,7 +60,7 @@ static int ec600s_echo_close(void) int try = 0; tos_at_echo_create(&echo, NULL, 0, NULL); - + while (try++ < 10) { tos_at_cmd_exec(AT_AGENT, &echo, 1000, "ATE0\r\n"); if (echo.status == AT_ECHO_STATUS_OK) { @@ -75,7 +75,7 @@ static int ec600s_sim_card_check(void) at_echo_t echo; int try = 0; char echo_buffer[32]; - + tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); while (try++ < 10) { tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+CPIN?\r\n"); @@ -84,7 +84,7 @@ static int ec600s_sim_card_check(void) } tos_sleep_ms(2000); } - + return -1; } @@ -94,7 +94,7 @@ static int ec600s_signal_quality_check(void) at_echo_t echo; char echo_buffer[32], *str; int try = 0; - + tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); while (try++ < 10) { tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+CSQ\r\n"); @@ -106,7 +106,7 @@ static int ec600s_signal_quality_check(void) if (!str) { return -1; } - + sscanf(str, "+CSQ:%d,%d", &rssi, &ber); if (rssi != 99) { return 0; @@ -122,7 +122,7 @@ static int ec600s_gsm_network_check(void) at_echo_t echo; char echo_buffer[32], *str; int try = 0; - + tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); while (try++ < 10) { tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+CREG?\r\n"); @@ -140,8 +140,8 @@ static int ec600s_gsm_network_check(void) } tos_sleep_ms(2000); } - - return -1; + + return -1; } static int ec600s_gprs_network_check(void) @@ -168,7 +168,7 @@ static int ec600s_gprs_network_check(void) } tos_sleep_ms(2000); } - + return -1; } @@ -181,7 +181,7 @@ static int ec600s_close_apn(void) if (echo.status == AT_ECHO_STATUS_OK) { return 0; } - + return -1; } @@ -206,17 +206,17 @@ static int ec600s_set_apn(void) static int ec600s_init(void) { printf("Init ec600s ...\n" ); - + if (ec600s_check_ready() != 0) { printf("wait module ready timeout, please check your module\n"); return -1; } - + if (ec600s_echo_close() != 0) { printf("echo close failed,please check your module\n"); return -1; } - + if(ec600s_sim_card_check() != 0) { printf("sim card check failed,please insert your card\n"); return -1; @@ -226,22 +226,22 @@ static int ec600s_init(void) printf("signal quality check status failed\n"); return -1; } - + if(ec600s_gsm_network_check() != 0) { printf("GSM network register status check fail\n"); return -1; } - + if(ec600s_gprs_network_check() != 0) { printf("GPRS network register status check fail\n"); return -1; } - + if(ec600s_close_apn() != 0) { printf("close apn failed\n"); return -1; } - + if (ec600s_set_apn() != 0) { printf("apn set FAILED\n"); return -1; @@ -259,14 +259,14 @@ static int ec600s_connect_establish(int id, sal_proto_t proto) char *query_result_str = NULL; char *remote_ip = NULL; char *remote_port = NULL; - + tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+QISTATE=1,%d\r\n", id); if (echo.status != AT_ECHO_STATUS_OK) { printf("query socket %d state fail\r\n", id); return -1; } - + sprintf(except_str, "+QISTATE: %d", id); query_result_str = strstr(echo_buffer, except_str); if (query_result_str) { @@ -277,13 +277,13 @@ static int ec600s_connect_establish(int id, sal_proto_t proto) memset(except_str, 0, sizeof(except_str)); sprintf(except_str, "+QIOPEN: %d,0", id); - + remote_ip = (char*)tos_at_channel_ip_get(AT_AGENT, id); remote_port = (char*)tos_at_channel_port_get(AT_AGENT, id); if (!remote_ip || !remote_port) { return -2; } - + tos_at_echo_create(&echo, NULL, 0, except_str); tos_at_cmd_exec_until(AT_AGENT, &echo, 4000, "AT+QIOPEN=1,%d,\"%s\",\"%s\",%d,0,1\r\n", id, proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", remote_ip, atoi(remote_port)); @@ -291,32 +291,32 @@ static int ec600s_connect_establish(int id, sal_proto_t proto) printf("establish socket %d on module fail\r\n", id); return -3; } - + return 0; } static int ec600s_connect(const char *ip, const char *port, sal_proto_t proto) { int id; - + id = tos_at_channel_alloc(AT_AGENT, ip, port); if (id == -1) { printf("at channel alloc fail\r\n"); return -1; } - + if (ec600s_connect_establish(id, proto) < 0) { tos_at_channel_free(AT_AGENT, id); return -2; } - + return id; } static int ec600s_connect_with_size(const char *ip, const char *port, sal_proto_t proto, size_t socket_buffer_size) { int id; - + id = tos_at_channel_alloc_with_size(AT_AGENT, ip, port, socket_buffer_size); if (id == -1) { printf("at channel alloc fail\r\n"); @@ -327,7 +327,7 @@ static int ec600s_connect_with_size(const char *ip, const char *port, sal_proto_ tos_at_channel_free(AT_AGENT, id); return -2; } - + return id; } @@ -348,29 +348,21 @@ int ec600s_send(int id, const void *buf, size_t len) if (!tos_at_channel_is_working(AT_AGENT, id)) { return -1; } - - if (tos_at_global_lock_pend(AT_AGENT) != 0) { - return -1; - } tos_at_echo_create(&echo, NULL, 0, ">"); tos_at_cmd_exec_until(AT_AGENT, &echo, 1000, "AT+QISEND=%d,%d\r\n", id, len); if (echo.status != AT_ECHO_STATUS_EXPECT) { - tos_at_global_lock_post(AT_AGENT); return -1; } tos_at_echo_create(&echo, NULL, 0, "SEND OK"); tos_at_raw_data_send_until(AT_AGENT, &echo, 10000, (uint8_t *)buf, len); if (echo.status != AT_ECHO_STATUS_EXPECT) { - tos_at_global_lock_post(AT_AGENT); return -1; } - tos_at_global_lock_post(AT_AGENT); - return len; } @@ -388,34 +380,26 @@ int ec600s_sendto(int id, char *ip, char *port, const void *buf, size_t len) { at_echo_t echo; - if (tos_at_global_lock_pend(AT_AGENT) != 0) { - return -1; - } - tos_at_echo_create(&echo, NULL, 0, ">"); tos_at_cmd_exec_until(AT_AGENT, &echo, 1000, "AT+QISEND=%d,%d\r\n", id, len); if (echo.status != AT_ECHO_STATUS_EXPECT) { - tos_at_global_lock_post(AT_AGENT); return -1; } tos_at_echo_create(&echo, NULL, 0, "SEND OK"); tos_at_raw_data_send(AT_AGENT, &echo, 1000, (uint8_t *)buf, len); if (echo.status != AT_ECHO_STATUS_EXPECT) { - tos_at_global_lock_post(AT_AGENT); return -1; } - tos_at_global_lock_post(AT_AGENT); - return len; } static void ec600s_transparent_mode_exit(void) { at_echo_t echo; - + tos_at_echo_create(&echo, NULL, 0, NULL); tos_at_cmd_exec(AT_AGENT, &echo, 500, "+++"); } @@ -423,7 +407,7 @@ static void ec600s_transparent_mode_exit(void) static int ec600s_close(int id) { at_echo_t echo; - + ec600s_transparent_mode_exit(); tos_at_echo_create(&echo, NULL, 0, NULL); @@ -467,7 +451,7 @@ __STATIC__ void ec600s_incoming_data_process(void) +QIURC: "recv",, */ - + while (1) { if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) { return; @@ -492,7 +476,7 @@ __STATIC__ void ec600s_incoming_data_process(void) if (tos_at_uart_read(AT_AGENT, &data, 1) != 1) { return; } - + do { #if !defined(MIN) #define MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -529,7 +513,7 @@ __STATIC__ void ec600s_domain_data_process(void) if (data == '0') { return; } - + if (data == '\"') { /* start parser domain */ while (1) { @@ -595,7 +579,7 @@ sal_module_t sal_module_ec600s = { int ec600s_sal_init(hal_uart_port_t uart_port) { - + if (tos_at_init(AT_AGENT, "ec600s_at", ec600s_at_parse_task_stk, uart_port, ec600s_at_event, sizeof(ec600s_at_event) / sizeof(ec600s_at_event[0])) != 0) { @@ -608,7 +592,7 @@ int ec600s_sal_init(hal_uart_port_t uart_port) if (tos_sal_module_init() != 0) { return -1; } - + return 0; } @@ -623,7 +607,7 @@ int ec600s_sal_deinit() tos_sal_module_register_default(); tos_at_deinit(AT_AGENT); - + return 0; } diff --git a/devices/esp8266/esp8266.c b/devices/esp8266/esp8266.c index 13c340e6..5ba6094c 100644 --- a/devices/esp8266/esp8266.c +++ b/devices/esp8266/esp8266.c @@ -105,12 +105,15 @@ int esp8266_join_ap(const char *ssid, const char *pwd) { int try = 0; at_echo_t echo; + char echo_buffer[128]; - tos_at_echo_create(&echo, NULL, 0, NULL); + tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); while (try++ < 10) { - tos_at_cmd_exec(AT_AGENT, &echo, 15000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd); + tos_at_cmd_exec(AT_AGENT, &echo, 20000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd); if (echo.status == AT_ECHO_STATUS_OK) { - return 0; + if (strstr(echo_buffer, "WIFI GOT IP")) { + return 0; + } } } return -1; @@ -200,10 +203,6 @@ static int esp8266_send(int id, const void *buf, size_t len) return -1; } - if (tos_at_global_lock_pend(AT_AGENT) != 0) { - return -1; - } - tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), ">"); #if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u tos_at_cmd_exec_until(&echo, 5000, @@ -218,7 +217,6 @@ static int esp8266_send(int id, const void *buf, size_t len) tos_at_channel_set_broken(AT_AGENT, id); } - tos_at_global_lock_post(AT_AGENT); return -1; } @@ -234,11 +232,9 @@ static int esp8266_send(int id, const void *buf, size_t len) tos_at_channel_set_broken(AT_AGENT, id); } - tos_at_global_lock_post(AT_AGENT); return -1; } - tos_at_global_lock_post(AT_AGENT); return len; } @@ -251,10 +247,6 @@ static int esp8266_sendto(int id, char *ip, char *port, const void *buf, size_t return -1; } - if (tos_at_global_lock_pend(AT_AGENT) != 0) { - return -1; - } - tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), ">"); if (ip && port) { @@ -280,7 +272,6 @@ static int esp8266_sendto(int id, char *ip, char *port, const void *buf, size_t tos_at_channel_set_broken(AT_AGENT, id); } - tos_at_global_lock_post(AT_AGENT); return -1; } @@ -296,11 +287,9 @@ static int esp8266_sendto(int id, char *ip, char *port, const void *buf, size_t tos_at_channel_set_broken(AT_AGENT, id); } - tos_at_global_lock_post(AT_AGENT); return -1; } - tos_at_global_lock_post(AT_AGENT); return len; } @@ -317,9 +306,9 @@ static int esp8266_recvfrom(int id, void *buf, size_t len) static int esp8266_close(int id) { at_echo_t echo; - + tos_at_echo_create(&echo, NULL, 0, NULL); - + #if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u tos_at_cmd_exec(AT_AGENT, &echo, 1000, "AT+CIPCLOSE\r\n"); #else @@ -441,7 +430,7 @@ __STATIC__ void esp8266_incoming_data_process(void) if (tos_at_uart_read(AT_AGENT, buffer, read_len) != read_len) { return; } - + //delay has two reason, wait for the data to be cached and untrigger scheduling tos_stopwatch_delay(200); @@ -501,7 +490,7 @@ int esp8266_sal_deinit() tos_sal_module_register_default(); tos_at_deinit(AT_AGENT); - + return 0; } diff --git a/kernel/core/include/tos_version.h b/kernel/core/include/tos_version.h index 81c127bc..88e55ada 100644 --- a/kernel/core/include/tos_version.h +++ b/kernel/core/include/tos_version.h @@ -25,8 +25,8 @@ #define TOS_VERSION_MAJOR 0x02 #define TOS_VERSION_MINOR 0x05 -#define TOS_VERSION_PATCH 0x01 -#define TOS_VERSION "2.5.1" +#define TOS_VERSION_PATCH 0x02 +#define TOS_VERSION "2.5.2" #endif /* _TOS_VERSION_H_ */ diff --git a/net/at/include/tos_at.h b/net/at/include/tos_at.h index f3c3f3b1..70a74fab 100644 --- a/net/at/include/tos_at.h +++ b/net/at/include/tos_at.h @@ -140,22 +140,26 @@ typedef struct at_agent_st { k_task_t parser; at_cache_t recv_cache; + /* protected the AT agent, so only one AT instruction is executing any one time. */ k_mutex_t global_lock; char *cmd_buf; - k_mutex_t cmd_buf_lock; + + /* global_lock has protected the at agent, so cmd buf lock is unnecessary, + the code will be removed in next version. */ + // k_mutex_t cmd_buf_lock; hal_uart_t uart; k_mutex_t uart_tx_lock; // k_mutex_t uart_rx_lock; - + #if AT_INPUT_TYPE_FRAME_EN k_mail_q_t uart_rx_frame_mail; uint8_t *uart_rx_frame_mail_buffer; uint16_t fifo_available_len; #else k_sem_t uart_rx_sem; - + #if AT_INPUT_SIMULATE_IDLE_EN k_timer_t idle_check_timer; #endif /* AT_INPUT_SIMULATE_IDLE_EN */ @@ -329,7 +333,7 @@ __API__ int tos_at_init(at_agent_t *at_agent, char *task_name, k_stack_t *stk, h * @brief De-initialize the at framework. * * @param[in] at_agent pointer to the at agent struct. - * + * * @attention None * * @return diff --git a/net/at/src/tos_at.c b/net/at/src/tos_at.c index 0e4e19e6..924d7a62 100644 --- a/net/at/src/tos_at.c +++ b/net/at/src/tos_at.c @@ -14,7 +14,7 @@ * as the other licenses applicable to the third-party components included * within TencentOS. *---------------------------------------------------------------------------*/ - + /* Note: If you find that the AT framework occasionally loses characters, @@ -46,11 +46,11 @@ __STATIC__ int at_uart_getchar_from_fifo(at_agent_t *at_agent, uint8_t *data) { TOS_CPU_CPSR_ALLOC(); k_err_t err; - + TOS_CPU_INT_DISABLE(); err = tos_chr_fifo_pop(&at_agent->uart_rx_fifo, data); TOS_CPU_INT_ENABLE(); - + return err; } @@ -79,30 +79,30 @@ __STATIC__ int at_uart_getchar(at_agent_t *at_agent, uint8_t *data, k_tick_t tim return -1; } } - + if (at_uart_getchar_from_fifo(at_agent, data) != K_ERR_NONE) { return -1; } - + return 0; - + #else tos_stopwatch_delay(1); if (tos_sem_pend(&at_agent->uart_rx_sem, timeout) != K_ERR_NONE) { return -1; } - + /* the uart_rx_fifo is only read by at_parser task, and it will be written in usart interrupt handler, so it is more effective to use critical sections. */ - + // if (tos_mutex_pend(&at_agent->uart_rx_lock) != K_ERR_NONE) { // return -1; // } - + if (at_uart_getchar_from_fifo(at_agent, data) != K_ERR_NONE) { return -1; } @@ -274,7 +274,7 @@ __STATIC__ at_parse_status_t at_uart_line_parse(at_agent_t *at_agent) recv_cache->buffer[recv_cache->buffer_size - 1] = '\0'; return AT_PARSE_STATUS_OVERFLOW; } - + if (at_get_event(at_agent) != K_NULL) { return AT_PARSE_STATUS_EVENT; } @@ -282,9 +282,9 @@ __STATIC__ at_parse_status_t at_uart_line_parse(at_agent_t *at_agent) if (at_is_echo_expect(at_agent)) { return AT_PARSE_STATUS_EXPECT; } - + AT_LOG("recv_cache:[%s](%d)\r\n", recv_cache->buffer, recv_cache->recv_len); - + if (strstr((char*)recv_cache->buffer, "OK")) { return AT_PARSE_STATUS_OK; } else if (strstr((char*)recv_cache->buffer, "FAIL")) { @@ -344,11 +344,11 @@ __STATIC__ void at_parser(void *arg) recv_cache = &at_agent->recv_cache; while (K_TRUE) { - + at_parse_status = at_uart_line_parse(at_agent); - + AT_LOG("at line parser end!(%d)\r\n", at_parse_status); - + tos_kprintln("--->%s", recv_cache->buffer); if (at_parse_status == AT_PARSE_STATUS_OVERFLOW) { @@ -368,7 +368,7 @@ __STATIC__ void at_parser(void *arg) if (!at_echo) { continue; } - + if (at_echo->buffer) { at_echo_buffer_copy(recv_cache, at_echo); } @@ -467,16 +467,24 @@ __API__ int tos_at_raw_data_send(at_agent_t *at_agent, at_echo_t *echo, uint32_t { int ret = 0; - if (echo) { - at_echo_attach(at_agent, echo); + if (!echo) { + return -1; } + if (tos_at_global_lock_pend(at_agent) != 0) { + return -1; + } + + at_echo_attach(at_agent, echo); + ret = at_uart_send(at_agent, buf, size, 0xFFFF); tos_task_delay(tos_millisec2tick(timeout)); at_agent->echo = K_NULL; + tos_at_global_lock_post(at_agent); + return ret; } @@ -488,7 +496,12 @@ __API__ int tos_at_raw_data_send_until(at_agent_t *at_agent, at_echo_t *echo, ui return -1; } + if (tos_at_global_lock_pend(at_agent) != 0) { + return -1; + } + if (tos_sem_create(&echo->__expect_notify, 0) != K_ERR_NONE) { + tos_at_global_lock_post(at_agent); return -1; } echo->__is_expecting = K_TRUE; @@ -504,6 +517,8 @@ __API__ int tos_at_raw_data_send_until(at_agent_t *at_agent, at_echo_t *echo, ui at_agent->echo = K_NULL; + tos_at_global_lock_post(at_agent); + return ret; } @@ -511,9 +526,9 @@ __STATIC__ int at_cmd_do_exec(at_agent_t *at_agent, const char *format, va_list { size_t cmd_len = 0; - if (tos_mutex_pend(&at_agent->cmd_buf_lock) != K_ERR_NONE) { - return -1; - } + // if (tos_mutex_pend(&at_agent->cmd_buf_lock) != K_ERR_NONE) { + // return -1; + // } cmd_len = vsnprintf(at_agent->cmd_buf, AT_CMD_BUFFER_SIZE, format, args); @@ -521,7 +536,7 @@ __STATIC__ int at_cmd_do_exec(at_agent_t *at_agent, const char *format, va_list at_uart_send(at_agent, (uint8_t *)at_agent->cmd_buf, cmd_len, 0xFFFF); - tos_mutex_post(&at_agent->cmd_buf_lock); + // tos_mutex_post(&at_agent->cmd_buf_lock); return 0; } @@ -530,23 +545,29 @@ __API__ int tos_at_cmd_exec(at_agent_t *at_agent, at_echo_t *echo, uint32_t time { int ret = 0; va_list args; - + if (!echo) { return -1; } - + + if (tos_at_global_lock_pend(at_agent) != 0) { + return -1; + } + if (tos_sem_create(&echo->__status_set_notify, 0) != K_ERR_NONE) { + tos_at_global_lock_post(at_agent); return -1; } at_echo_attach(at_agent, echo); - + va_start(args, cmd); ret = at_cmd_do_exec(at_agent, cmd, args); va_end(args); if (ret != 0) { at_agent->echo = K_NULL; + tos_at_global_lock_post(at_agent); return -1; } @@ -558,6 +579,8 @@ __API__ int tos_at_cmd_exec(at_agent_t *at_agent, at_echo_t *echo, uint32_t time at_agent->echo = K_NULL; + tos_at_global_lock_post(at_agent); + return ret; } @@ -570,7 +593,12 @@ __API__ int tos_at_cmd_exec_until(at_agent_t *at_agent, at_echo_t *echo, uint32_ return -1; } + if (tos_at_global_lock_pend(at_agent) != 0) { + return -1; + } + if (tos_sem_create(&echo->__expect_notify, 0) != K_ERR_NONE) { + tos_at_global_lock_post(at_agent); return -1; } echo->__is_expecting = K_TRUE; @@ -582,6 +610,7 @@ __API__ int tos_at_cmd_exec_until(at_agent_t *at_agent, at_echo_t *echo, uint32_ if (ret != 0) { at_agent->echo = K_NULL; + tos_at_global_lock_post(at_agent); return -1; } @@ -593,6 +622,8 @@ __API__ int tos_at_cmd_exec_until(at_agent_t *at_agent, at_echo_t *echo, uint32_ at_agent->echo = K_NULL; + tos_at_global_lock_post(at_agent); + return ret; } @@ -696,7 +727,7 @@ __API__ int tos_at_channel_read_timed(at_agent_t *at_agent, int channel_id, uint remain_tick = tos_millisec2tick(timeout); tos_stopwatch_countdown(&data_channel->timer, remain_tick); - + while (!tos_stopwatch_is_expired(&data_channel->timer)) { remain_tick = tos_stopwatch_remain(&data_channel->timer); if (remain_tick == (k_tick_t)0u) { @@ -710,7 +741,7 @@ __API__ int tos_at_channel_read_timed(at_agent_t *at_agent, int channel_id, uint read_len = tos_chr_fifo_pop_stream(&data_channel->rx_fifo, buffer + total_read_len, buffer_len - total_read_len); tos_mutex_post(&data_channel->rx_lock); - + if (read_len == 0) { remain_tick = tos_stopwatch_remain(&data_channel->timer); tos_sem_pend(&data_channel->rx_sem, remain_tick); @@ -752,13 +783,13 @@ __API__ int tos_at_channel_write(at_agent_t *at_agent, int channel_id, uint8_t * __STATIC_INLINE__ int at_channel_construct(at_data_channel_t *data_channel, const char *ip, const char *port, size_t socket_buffer_size) { uint8_t *fifo_buffer = K_NULL; - + fifo_buffer = tos_mmheap_alloc(socket_buffer_size); - + if (!fifo_buffer) { return -1; } - + if (tos_sem_create_max(&data_channel->rx_sem, 0, 1) != K_ERR_NONE) { goto errout; } @@ -860,7 +891,7 @@ __API__ int tos_at_channel_free(at_agent_t *at_agent, int channel_id) if (!data_channel) { return -1; } - + tos_sem_destroy(&data_channel->rx_sem); tos_mutex_destroy(&data_channel->rx_lock); @@ -957,7 +988,7 @@ __STATIC__ void tos_at_uart_input_notify(at_agent_t *at_agent) } __STATIC__ void idle_check_timer_callback(void *args) -{ +{ at_agent_t *at_agent = (at_agent_t *)args; tos_at_uart_input_notify(at_agent); } @@ -987,9 +1018,9 @@ __API__ int tos_at_init(at_agent_t *at_agent, char *task_name, k_stack_t *stk, h } at_agent->cmd_buf = (char *)buffer; - if (tos_mutex_create(&at_agent->cmd_buf_lock) != K_ERR_NONE) { - goto errout1; - } + // if (tos_mutex_create(&at_agent->cmd_buf_lock) != K_ERR_NONE) { + // goto errout1; + // } if (at_recv_cache_init(at_agent) != 0) { goto errout2; @@ -1000,9 +1031,9 @@ __API__ int tos_at_init(at_agent_t *at_agent, char *task_name, k_stack_t *stk, h if (!buffer) { goto errout3; } - + at_agent->uart_rx_frame_mail_buffer = (uint8_t *)buffer; - + if (tos_mail_q_create(&at_agent->uart_rx_frame_mail, buffer, AT_FRAME_LEN_MAIL_MAX, sizeof(at_frame_len_mail_t)) != K_ERR_NONE) { goto errout4; } @@ -1019,22 +1050,22 @@ __API__ int tos_at_init(at_agent_t *at_agent, char *task_name, k_stack_t *stk, h if (tos_mutex_create(&at_agent->uart_tx_lock) != K_ERR_NONE) { goto errout6; } - + if (tos_mutex_create(&at_agent->global_lock) != K_ERR_NONE) { goto errout7; } - + #if AT_INPUT_SIMULATE_IDLE_EN if (tos_timer_create(&at_agent->idle_check_timer, SIMULATE_IDLE_DEFAULT_TIME, 0, idle_check_timer_callback, at_agent, TOS_OPT_TIMER_ONESHOT) != K_ERR_NONE) { goto errout8; } -#endif /* AT_INPUT_SIMULATE_IDLE_EN */ +#endif /* AT_INPUT_SIMULATE_IDLE_EN */ if (tos_hal_uart_init(&at_agent->uart, uart_port) != 0) { goto errout9; } - + if (tos_task_create(&at_agent->parser, task_name, at_parser, at_agent, AT_PARSER_TASK_PRIO, stk, AT_PARSER_TASK_STACK_SIZE, 0) != K_ERR_NONE) { @@ -1044,18 +1075,18 @@ __API__ int tos_at_init(at_agent_t *at_agent, char *task_name, k_stack_t *stk, h return 0; errout10: tos_hal_uart_deinit(&at_agent->uart); - + errout9: #if AT_INPUT_SIMULATE_IDLE_EN - tos_timer_destroy(&at_agent->idle_check_timer); + tos_timer_destroy(&at_agent->idle_check_timer); errout8: #endif /* AT_INPUT_SIMULATE_IDLE_EN */ - + tos_mutex_destroy(&at_agent->global_lock); errout7: tos_mutex_destroy(&at_agent->uart_tx_lock); - + errout6: // tos_mutex_destroy(&at_agent->uart_rx_lock); @@ -1065,7 +1096,7 @@ errout6: #else tos_sem_destroy(&at_agent->uart_rx_sem); #endif /* AT_INPUT_TYPE_FRAME_EN */ - + #if AT_INPUT_TYPE_FRAME_EN errout4: tos_mmheap_free(at_agent->uart_rx_frame_mail_buffer); @@ -1076,9 +1107,9 @@ errout3: at_recv_cache_deinit(at_agent); errout2: - tos_mutex_destroy(&at_agent->cmd_buf_lock); + // tos_mutex_destroy(&at_agent->cmd_buf_lock); -errout1: +//errout1: tos_mmheap_free(at_agent->cmd_buf); at_agent->cmd_buf = K_NULL; @@ -1093,15 +1124,15 @@ errout0: __API__ void tos_at_deinit(at_agent_t *at_agent) { tos_task_destroy(&at_agent->parser); - + tos_hal_uart_deinit(&at_agent->uart); - + tos_mutex_destroy(&at_agent->global_lock); tos_mutex_destroy(&at_agent->uart_tx_lock); //tos_mutex_destroy(&at_agent->uart_tx_lock); - + #if AT_INPUT_SIMULATE_IDLE_EN tos_timer_destroy(&at_agent->idle_check_timer); #endif /* AT_INPUT_SIMULATE_IDLE_EN */ @@ -1113,10 +1144,10 @@ __API__ void tos_at_deinit(at_agent_t *at_agent) #else tos_sem_destroy(&at_agent->uart_rx_sem); #endif /* AT_INPUT_TYPE_FRAME_EN */ - + at_recv_cache_deinit(at_agent); - tos_mutex_destroy(&at_agent->cmd_buf_lock); + // tos_mutex_destroy(&at_agent->cmd_buf_lock); tos_mmheap_free(at_agent->cmd_buf); at_agent->cmd_buf = K_NULL; @@ -1136,12 +1167,12 @@ __API__ void tos_at_uart_input_frame(at_agent_t *at_agent, uint8_t *pdata, uint1 { int ret; at_frame_len_mail_t at_frame_len_mail; - + ret = tos_chr_fifo_push_stream(&at_agent->uart_rx_fifo, pdata, len); if (ret != len) { return; } - + at_frame_len_mail.frame_len = len; tos_mail_q_post(&at_agent->uart_rx_frame_mail, &at_frame_len_mail, sizeof(at_frame_len_mail_t)); }