未验证 提交 738d03f2 编写于 作者: armink_ztl's avatar armink_ztl 提交者: GitHub

Merge pull request #1728 from chenyong111/master

[net][at] Modify the AT client initialization process, delete AT sock…
......@@ -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);
......@@ -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"
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册