at_perf:modify the global lock to protect at agent
This commit is contained in:
@@ -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.
|
||||
|
@@ -349,28 +349,20 @@ int ec600s_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, 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,27 +380,19 @@ 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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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_ */
|
||||
|
||||
|
@@ -140,10 +140,14 @@ 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;
|
||||
|
@@ -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;
|
||||
}
|
||||
@@ -535,7 +550,12 @@ __API__ int tos_at_cmd_exec(at_agent_t *at_agent, at_echo_t *echo, uint32_t time
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -547,6 +567,7 @@ __API__ int tos_at_cmd_exec(at_agent_t *at_agent, at_echo_t *echo, uint32_t time
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -1116,7 +1147,7 @@ __API__ void tos_at_deinit(at_agent_t *at_agent)
|
||||
|
||||
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;
|
||||
|
Reference in New Issue
Block a user