Jelajahi Sumber

[at] 增加获取client锁接口,适配RTT主线和之前版本

ryancw 4 bulan lalu
induk
melakukan
eec8e291dc

+ 1 - 1
class/a9g/at_socket_a9g.c

@@ -228,7 +228,7 @@ static int a9g_socket_send(struct at_socket *socket, const char *buff, size_t bf
     at_response_t resp = RT_NULL;
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/air720/at_socket_air720.c

@@ -236,7 +236,7 @@ static int air720_socket_send(struct at_socket *socket, const char *buff, size_t
     at_response_t resp = RT_NULL;
     int device_socket = (int)socket->user_data;
     struct at_device *device = (struct at_device *)socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/bc26/at_socket_bc26.c

@@ -315,7 +315,7 @@ static int bc26_socket_send(struct at_socket *socket, const char *buff, size_t b
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
     struct at_device_bc26 *bc26 = (struct at_device_bc26 *) device->user_data;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/bc28/at_socket_bc28.c

@@ -311,7 +311,7 @@ static int bc28_socket_send(struct at_socket *socket, const char *buff,
     at_response_t resp = RT_NULL;
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/ec20/at_socket_ec20.c

@@ -515,7 +515,7 @@ static int ec20_socket_send(struct at_socket *socket, const char *buff, size_t b
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
     struct at_device_ec20 *ec20 = (struct at_device_ec20 *) device->user_data;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/ec200x/at_socket_ec200x.c

@@ -315,7 +315,7 @@ static int ec200x_socket_send(struct at_socket *socket, const char *buff, size_t
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
     struct at_device_ec200x *ec200x = (struct at_device_ec200x *) device->user_data;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/esp32/at_socket_esp32.c

@@ -194,7 +194,7 @@ static int esp32_socket_send(struct at_socket *socket, const char *buff, size_t
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
     struct at_device_esp32 *esp32 = (struct at_device_esp32 *) device->user_data;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
     RT_ASSERT(bfsz > 0);

+ 1 - 1
class/esp8266/at_socket_esp8266.c

@@ -289,7 +289,7 @@ static int esp8266_socket_send(struct at_socket *socket, const char *buff, size_
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
     struct at_device_esp8266 *esp8266 = (struct at_device_esp8266 *) device->user_data;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
     RT_ASSERT(bfsz > 0);

+ 1 - 1
class/l610/at_socket_l610.c

@@ -255,7 +255,7 @@ static int l610_socket_send(struct at_socket *socket, const char *buff, size_t b
     at_response_t resp = RT_NULL;
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
     int sock = -1;
 
        sock=l610_socket_fd[device_socket];

+ 1 - 1
class/m26/at_socket_m26.c

@@ -282,7 +282,7 @@ static int m26_socket_send(struct at_socket *socket, const char *buff, size_t bf
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
     struct at_device_m26 *m26 = (struct at_device_m26 *) device->user_data;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/m5311/at_socket_m5311.c

@@ -304,7 +304,7 @@ static int m5311_socket_send(struct at_socket *socket, const char *buff,
     at_response_t resp = RT_NULL;
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/m6315/at_socket_m6315.c

@@ -231,7 +231,7 @@ static int m6315_socket_send(struct at_socket *socket, const char *buff, size_t
     at_response_t resp = RT_NULL;
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/me3616/at_socket_me3616.c

@@ -252,7 +252,7 @@ static int me3616_socket_send(struct at_socket *socket, const char *buff, size_t
     at_response_t resp = RT_NULL;
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/ml305/at_socket_ml305.c

@@ -226,7 +226,7 @@ static int ml305_socket_send(struct at_socket *socket, const char *buff, size_t
     at_response_t resp = RT_NULL;
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/ml307/at_socket_ml307.c

@@ -227,7 +227,7 @@ static int ml307_socket_send(struct at_socket *socket, const char *buff, size_t
     at_response_t resp = RT_NULL;
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/mw31/at_socket_mw31.c

@@ -189,7 +189,7 @@ static int mw31_socket_send(struct at_socket *socket, const char *buff, size_t b
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
     struct at_device_mw31 *mw31 = (struct at_device_mw31 *) device->user_data;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
     char send_buf[20] = {0};
 
     RT_ASSERT(buff);

+ 1 - 1
class/n21/at_socket_n21.c

@@ -243,7 +243,7 @@ static int n21_socket_send(struct at_socket *socket, const char *buff, size_t bf
     at_response_t resp = RT_NULL;
     int device_socket = (int)socket->user_data;
     struct at_device *device = (struct at_device *)socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/n58/at_socket_n58.c

@@ -243,7 +243,7 @@ static int n58_socket_send(struct at_socket *socket, const char *buff, size_t bf
     at_response_t resp = RT_NULL;
     int device_socket = (int)socket->user_data;
     struct at_device *device = (struct at_device *)socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/n720/at_socket_n720.c

@@ -212,7 +212,7 @@ static int n720_socket_send(struct at_socket *socket, const char *buff, size_t b
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
     struct at_device_n720 *n720 = (struct at_device_n720 *) device->user_data;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/rw007/at_socket_rw007.c

@@ -194,7 +194,7 @@ static int rw007_socket_send(struct at_socket *socket, const char *buff, size_t
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
     struct at_device_rw007 *rw007 = (struct at_device_rw007 *) device->user_data;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
     RT_ASSERT(bfsz > 0);

+ 2 - 2
class/sim76xx/at_socket_sim76xx.c

@@ -190,7 +190,7 @@ static int sim76xx_socket_connect(struct at_socket *socket, char *ip, int32_t po
     at_response_t resp = RT_NULL;
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(ip);
     RT_ASSERT(port >= 0);
@@ -304,7 +304,7 @@ static int sim76xx_socket_send(struct at_socket *socket, const char *buff, size_
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
     struct at_device_sim76xx *sim76xx = (struct at_device_sim76xx *) device->user_data;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
     RT_ASSERT(bfsz > 0);

+ 1 - 1
class/sim800c/at_socket_sim800c.c

@@ -230,7 +230,7 @@ static int sim800c_socket_send(struct at_socket *socket, const char *buff, size_
     at_response_t resp = RT_NULL;
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
 

+ 1 - 1
class/w60x/at_socket_w60x.c

@@ -173,7 +173,7 @@ static int w60x_socket_send(struct at_socket *socket, const char *buff, size_t b
     int device_socket = (int) socket->user_data;
     struct at_device *device = (struct at_device *) socket->device;
     struct at_device_w60x *w60x = (struct at_device_w60x *) device->user_data;
-    rt_mutex_t lock = &(device->client->lock);
+    rt_mutex_t lock = at_device_get_client_lock(device);
 
     RT_ASSERT(buff);
     RT_ASSERT(bfsz > 0);

+ 2 - 0
inc/at_device.h

@@ -128,6 +128,8 @@ struct at_device *at_device_get_by_name(int type, const char *name);
 struct at_device *at_device_get_by_socket(int at_socket);
 #endif
 
+/* Get the client lock (mutex) of the specified AT device. */
+rt_mutex_t at_device_get_client_lock(struct at_device *device);
 /* AT device control operaions */
 int at_device_control(struct at_device *device, int cmd, void *arg);
 /* Register AT device class object */

+ 16 - 0
src/at_device.c

@@ -22,6 +22,22 @@ static rt_slist_t at_device_list = RT_SLIST_OBJECT_INIT(at_device_list);
 /* The global list of at device class */
 static rt_slist_t at_device_class_list = RT_SLIST_OBJECT_INIT(at_device_class_list);
 
+/**
+ * Get the client lock (mutex) of the specified AT device.
+ * This lock is used to ensure thread-safe access to the AT client.
+ * 
+ * @param device: Pointer to the AT device object.
+ * @return The client lock (rt_mutex_t) of the AT device.
+ */
+rt_mutex_t at_device_get_client_lock(struct at_device *device)
+{
+#if defined(RT_VERSION_CHECK) && (RTTHREAD_VERSION > RT_VERSION_CHECK(5, 2, 1))
+    return &(device->client->lock);
+#else
+    return device->client->lock;
+#endif
+}
+
 /**
  * This function will get the first initialized AT device.
  *