summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author朱天龙 (Armink) <[email protected]>2018-08-21 13:35:27 +0800
committerGitHub <[email protected]>2018-08-21 13:35:27 +0800
commit738d03f22b47ab67935df3c974004e99be7099b5 (patch)
tree9a01892c6a7129f83d87de686ac5fe87413bf0b9
parent312897d2ce27740cd39c16f594202342aae89966 (diff)
parentc2e6f20caf71f5db55915e1eb57426a56800b572 (diff)
Merge pull request #1728 from chenyong111/master
[net][at] Modify the AT client initialization process, delete AT sock…
-rw-r--r--components/net/at/at_socket/at_socket.c47
-rw-r--r--components/net/at/include/at.h2
-rw-r--r--components/net/at/src/at_client.c26
3 files changed, 32 insertions, 43 deletions
diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c
index 5646f1049f..3580df957b 100644
--- a/components/net/at/at_socket/at_socket.c
+++ b/components/net/at/at_socket/at_socket.c
@@ -64,8 +64,6 @@ typedef enum {
/* the global array of available sockets */
static struct at_socket sockets[AT_SOCKETS_NUM] = { 0 };
-/* the global AT socket lock */
-static rt_mutex_t at_socket_lock = RT_NULL;
/* AT device socket options */
static struct at_device_ops *at_dev_ops = RT_NULL;
@@ -257,12 +255,23 @@ static void at_do_event_changes(struct at_socket *sock, at_event_t event, rt_boo
static struct at_socket *alloc_socket(void)
{
- char sem_name[RT_NAME_MAX];
- char lock_name[RT_NAME_MAX];
+ static rt_mutex_t at_slock = RT_NULL;
+ char name[RT_NAME_MAX];
struct at_socket *sock;
int idx;
- rt_mutex_take(at_socket_lock, RT_WAITING_FOREVER);
+ if(at_slock == RT_NULL)
+ {
+ /* create AT socket lock */
+ at_slock = rt_mutex_create("at_s", RT_IPC_FLAG_FIFO);
+ if (at_slock == RT_NULL)
+ {
+ LOG_E("No memory for AT socket lock!");
+ return RT_NULL;
+ }
+ }
+
+ rt_mutex_take(at_slock, RT_WAITING_FOREVER);
/* find an empty at socket entry */
for (idx = 0; idx < AT_SOCKETS_NUM && sockets[idx].magic; idx++);
@@ -282,25 +291,25 @@ static struct at_socket *alloc_socket(void)
sock->errevent = RT_NULL;
rt_slist_init(&sock->recvpkt_list);
- rt_snprintf(sem_name, RT_NAME_MAX, "%s%d", "at_recv_notice_", idx);
+ rt_snprintf(name, RT_NAME_MAX, "%s%d", "at_sr", idx);
/* create AT socket receive mailbox */
- if ((sock->recv_notice = rt_sem_create(sem_name, 0, RT_IPC_FLAG_FIFO)) == RT_NULL)
+ if ((sock->recv_notice = rt_sem_create(name, 0, RT_IPC_FLAG_FIFO)) == RT_NULL)
{
goto __err;
}
- rt_snprintf(lock_name, RT_NAME_MAX, "%s%d", "at_recv_lock_", idx);
+ rt_snprintf(name, RT_NAME_MAX, "%s%d", "at_sr", idx);
/* create AT socket receive ring buffer lock */
- if((sock->recv_lock = rt_mutex_create(lock_name, RT_IPC_FLAG_FIFO)) == RT_NULL)
+ if((sock->recv_lock = rt_mutex_create(name, RT_IPC_FLAG_FIFO)) == RT_NULL)
{
goto __err;
}
- rt_mutex_release(at_socket_lock);
+ rt_mutex_release(at_slock);
return sock;
__err:
- rt_mutex_release(at_socket_lock);
+ rt_mutex_release(at_slock);
return RT_NULL;
}
@@ -486,7 +495,6 @@ static void at_closed_notice_cb(int socket, at_socket_evt_t event, const char *b
at_do_event_changes(sock, AT_EVENT_RECV, RT_TRUE);
at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE);
-// LOG_D("socket (%d) closed by remote");
sock->state = AT_SOCKET_CLOSED;
rt_sem_release(sock->recv_notice);
}
@@ -767,7 +775,6 @@ int at_send(int socket, const void *data, size_t size, int flags)
return at_sendto(socket, data, size, flags, RT_NULL, 0);
}
-
int at_getsockopt(int socket, int level, int optname, void *optval, socklen_t *optlen)
{
struct at_socket *sock;
@@ -1123,17 +1130,3 @@ void at_scoket_device_register(const struct at_device_ops *ops)
RT_ASSERT(ops->set_event_cb);
at_dev_ops = (struct at_device_ops *) ops;
}
-
-static int at_socket_init(void)
-{
- /* create AT socket lock */
- at_socket_lock = rt_mutex_create("at_socket_lock", RT_IPC_FLAG_FIFO);
- if (!at_socket_lock)
- {
- LOG_E("No memory for AT socket lock!");
- return -RT_ENOMEM;
- }
-
- return RT_EOK;
-}
-INIT_COMPONENT_EXPORT(at_socket_init);
diff --git a/components/net/at/include/at.h b/components/net/at/include/at.h
index 746d56b2ac..b1b80013f8 100644
--- a/components/net/at/include/at.h
+++ b/components/net/at/include/at.h
@@ -27,7 +27,7 @@
#include <rtthread.h>
-#define AT_SW_VERSION "0.2.5"
+#define AT_SW_VERSION "0.3.0"
#define DBG_ENABLE
#define DBG_SECTION_NAME "AT"
diff --git a/components/net/at/src/at_client.c b/components/net/at/src/at_client.c
index 31bd0dcbf9..e2fd93e577 100644
--- a/components/net/at/src/at_client.c
+++ b/components/net/at/src/at_client.c
@@ -663,6 +663,13 @@ void at_set_urc_table(const struct at_urc *table, rt_size_t size)
}
+/**
+ * initialize AT client.
+ *
+ * @return 0: initialize success
+ * -1: initialize failed
+ * -5: no memory
+ */
int at_client_init(void)
{
int result = RT_EOK;
@@ -747,11 +754,6 @@ int at_client_init(void)
goto __exit;
}
- if ((result = at_client_port_init()) != RT_EOK)
- {
- LOG_E("AT client port initialize failed(%d).", result);
- }
-
__exit:
if (!result)
{
@@ -773,14 +775,8 @@ __exit:
return result;
}
-INIT_COMPONENT_EXPORT(at_client_init);
-
-RT_WEAK int at_client_port_init(void)
-{
- at_client_local->urc_table = RT_NULL;
- at_client_local->urc_table_size = 0;
-
- LOG_E("The client porting initialize for AT client is not implement.");
- return 0;
-}
+#ifdef FINSH_USING_MSH
+#include <finsh.h>
+MSH_CMD_EXPORT(at_client_init, initialize AT client);
+#endif