From 3fc92b3c91812a3c13fe7d5849c41f30ddd21528 Mon Sep 17 00:00:00 2001
From: mculover666 <2412828003@qq.com>
Date: Tue, 13 Apr 2021 20:50:48 +0800
Subject: [PATCH] remove the uart_rx_lock in AT framework,update tos version to
2.2.1
---
.../KEIL/mqttclient/TencentOS_tiny.uvoptx | 2 +-
.../tcp_through_module/TencentOS_tiny.uvoptx | 16 ++++++-
.../tcp_through_module/TencentOS_tiny.uvprojx | 7 ++-
.../tcp_through_module/tcp_through_module.c | 7 +++
kernel/core/include/tos_version.h | 4 +-
net/at/include/tos_at.h | 2 +-
net/at/src/tos_at.c | 44 ++++++++++++++-----
7 files changed, 63 insertions(+), 19 deletions(-)
diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvoptx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvoptx
index 310d61cd..3a3edf56 100644
--- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvoptx
+++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvoptx
@@ -410,7 +410,7 @@
examples
- 1
+ 0
0
0
0
diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvoptx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvoptx
index 67ad7807..00a87e67 100644
--- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvoptx
+++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvoptx
@@ -1254,6 +1254,18 @@
0
0
+
+ 12
+ 77
+ 1
+ 0
+ 0
+ 0
+ ..\..\..\..\devices\ec600s\ec600s.c
+ ec600s.c
+ 0
+ 0
+
@@ -1264,7 +1276,7 @@
0
13
- 77
+ 78
1
0
0
@@ -1284,7 +1296,7 @@
0
14
- 78
+ 79
1
0
0
diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvprojx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvprojx
index aec8a94f..064f8d58 100644
--- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvprojx
+++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvprojx
@@ -339,7 +339,7 @@
USE_HAL_DRIVER,STM32L431xx,WITH_TOS_NET_ADAPTER
- ..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\kernel\core\include;..\..\TOS-CONFIG;..\..\..\..\platform\arch\arm\cortex-m4\keil;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\BSP\Hardware\DHT11;..\..\BSP\Hardware\OLED;..\..\BSP\Hardware\BH1750;..\..\..\..\devices\esp8266;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\..\..\net\sal_module_wrapper;..\..\..\..\devices\ec20;..\..\..\..\devices\ec200s;..\..\..\..\devices\air724;..\..\..\..\devices\l610
+ ..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\kernel\core\include;..\..\TOS-CONFIG;..\..\..\..\platform\arch\arm\cortex-m4\keil;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\BSP\Hardware\DHT11;..\..\BSP\Hardware\OLED;..\..\BSP\Hardware\BH1750;..\..\..\..\devices\esp8266;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\..\..\net\sal_module_wrapper;..\..\..\..\devices\ec20;..\..\..\..\devices\ec200s;..\..\..\..\devices\air724;..\..\..\..\devices\l610;..\..\..\..\devices\ec600s
@@ -818,6 +818,11 @@
1
..\..\..\..\devices\l610\l610.c
+
+ ec600s.c
+ 1
+ ..\..\..\..\devices\ec600s\ec600s.c
+
diff --git a/examples/tcp_through_module/tcp_through_module.c b/examples/tcp_through_module/tcp_through_module.c
index 9c8e2f8b..98bb7677 100644
--- a/examples/tcp_through_module/tcp_through_module.c
+++ b/examples/tcp_through_module/tcp_through_module.c
@@ -9,6 +9,7 @@
//#define USE_EC200S
//#define USE_AIR724
//#define USE_L610
+//#define USE_EC600S
#ifdef USE_ESP8266
#include "esp8266.h"
@@ -38,6 +39,10 @@
#include "l610.h"
#endif
+#ifdef USE_EC600S
+#include "ec600s.h"
+#endif
+
#define TCP_TEST_TASK0_STK_SIZE 4096
void tcp_test0(void);
osThreadDef(tcp_test0, osPriorityNormal, 1, TCP_TEST_TASK0_STK_SIZE);
@@ -114,6 +119,8 @@ void application_entry(void *arg)
air724_sal_init(HAL_UART_PORT_0);
#elif defined(USE_L610)
l610_sal_init(HAL_UART_PORT_0);
+#elif defined(USE_EC600S)
+ ec600s_sal_init(HAL_UART_PORT_0);
#endif
socket_id_0 = tos_sal_module_connect("117.50.111.72", "8080", TOS_SAL_PROTO_TCP);
diff --git a/kernel/core/include/tos_version.h b/kernel/core/include/tos_version.h
index 31feeb01..8b055ade 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 0x02
-#define TOS_VERSION_PATCH 0x00
-#define TOS_VERSION "2.2.0"
+#define TOS_VERSION_PATCH 0x01
+#define TOS_VERSION "2.2.1"
#endif /* _TOS_VERSION_H_ */
diff --git a/net/at/include/tos_at.h b/net/at/include/tos_at.h
index aa9a0b12..5e537267 100644
--- a/net/at/include/tos_at.h
+++ b/net/at/include/tos_at.h
@@ -122,7 +122,7 @@ typedef struct at_agent_st {
hal_uart_t uart;
k_mutex_t uart_tx_lock;
- k_mutex_t uart_rx_lock;
+// k_mutex_t uart_rx_lock;
k_sem_t uart_rx_sem;
k_chr_fifo_t uart_rx_fifo;
uint8_t *uart_rx_fifo_buffer;
diff --git a/net/at/src/tos_at.c b/net/at/src/tos_at.c
index 47b8bd5f..04b67432 100644
--- a/net/at/src/tos_at.c
+++ b/net/at/src/tos_at.c
@@ -14,6 +14,15 @@
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
+
+/*
+Note:
+ If you find that the AT framework occasionally loses characters,
+ this may be caused by the unnecessary critical section of at_channel,
+ so you can remove the critical section of ring_queue in tos_ring_queue.c.
+ Once you remove, ring queue becomes only a data structure,
+ you must use critical section or mutex to protect the data in ring_queue.
+*/
#include "tos_at.h"
@@ -39,6 +48,7 @@ __API__ int tos_at_global_lock_post(void)
__STATIC__ int at_uart_getchar(uint8_t *data, k_tick_t timeout)
{
+ TOS_CPU_CPSR_ALLOC();
k_err_t err;
tos_stopwatch_delay(1);
@@ -46,14 +56,24 @@ __STATIC__ int at_uart_getchar(uint8_t *data, k_tick_t timeout)
if (tos_sem_pend(&AT_AGENT->uart_rx_sem, timeout) != K_ERR_NONE) {
return -1;
}
-
- if (tos_mutex_pend(&AT_AGENT->uart_rx_lock) != 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;
+// }
+
+ TOS_CPU_INT_DISABLE();
err = tos_chr_fifo_pop(&AT_AGENT->uart_rx_fifo, data);
+
+ TOS_CPU_INT_ENABLE();
- tos_mutex_post(&AT_AGENT->uart_rx_lock);
+// tos_mutex_post(&AT_AGENT->uart_rx_lock);
return err == K_ERR_NONE ? 0 : -1;
}
@@ -469,11 +489,11 @@ __API__ int tos_at_cmd_exec(at_echo_t *echo, uint32_t timeout, const char *cmd,
int ret = 0;
va_list args;
- if (tos_sem_create(&echo->__status_set_notify, 0) != K_ERR_NONE) {
+ if (!echo) {
return -1;
}
- if (!echo) {
+ if (tos_sem_create(&echo->__status_set_notify, 0) != K_ERR_NONE) {
return -1;
}
@@ -883,9 +903,9 @@ __API__ int tos_at_init(hal_uart_port_t uart_port, at_event_t *event_table, size
goto errout3;
}
- if (tos_mutex_create(&AT_AGENT->uart_rx_lock) != K_ERR_NONE) {
- goto errout4;
- }
+// if (tos_mutex_create(&AT_AGENT->uart_rx_lock) != K_ERR_NONE) {
+// goto errout4;
+// }
if (tos_mutex_create(&AT_AGENT->uart_tx_lock) != K_ERR_NONE) {
goto errout5;
@@ -917,9 +937,9 @@ errout6:
tos_mutex_destroy(&AT_AGENT->uart_tx_lock);
errout5:
- tos_mutex_destroy(&AT_AGENT->uart_rx_lock);
+// tos_mutex_destroy(&AT_AGENT->uart_rx_lock);
-errout4:
+//errout4:
tos_sem_destroy(&AT_AGENT->uart_rx_sem);
errout3:
--
GitLab