mqueue: add file_mq_xx for kernel use

Change-Id: Ida12f5938388cca2f233a4cde90277a218033645
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd
2020-12-24 20:53:17 +08:00
committed by Xiang Xiao
parent 3bc33572e3
commit f63db66382
37 changed files with 1158 additions and 484 deletions
+6 -6
View File
@@ -166,7 +166,7 @@ static int conn_tx_kthread(int argc, FAR char *argv[])
/* Get next ACL packet for connection */
ret = bt_queue_receive(conn->tx_queue, &buf);
ret = bt_queue_receive(&conn->tx_queue, &buf);
DEBUGASSERT(ret >= 0 && buf != NULL);
UNUSED(ret);
@@ -195,7 +195,7 @@ static int conn_tx_kthread(int argc, FAR char *argv[])
* result in a successful termination of this thread.
*/
ret = mq_getattr(conn->tx_queue, &attr);
ret = file_mq_getattr(&conn->tx_queue, &attr);
if (ret != OK)
{
break;
@@ -206,7 +206,7 @@ static int conn_tx_kthread(int argc, FAR char *argv[])
break;
}
ret = bt_queue_receive(conn->tx_queue, &buf);
ret = bt_queue_receive(&conn->tx_queue, &buf);
if (ret >= 0)
{
DEBUGASSERT(buf != NULL);
@@ -470,7 +470,7 @@ void bt_conn_send(FAR struct bt_conn_s *conn, FAR struct bt_buf_s *buf)
while ((buf = (FAR struct bt_buf_s *)sq_remfirst(&fraglist)) != NULL)
{
bt_queue_send(conn->tx_queue, buf, BT_NORMAL_PRIO);
bt_queue_send(&conn->tx_queue, buf, BT_NORMAL_PRIO);
}
}
@@ -569,7 +569,7 @@ void bt_conn_set_state(FAR struct bt_conn_s *conn,
ret = bt_queue_open(BT_CONN_TX, O_RDWR | O_CREAT,
CONFIG_BLUETOOTH_TXCONN_NMSGS,
&conn->tx_queue);
DEBUGASSERT(ret >= 0 && g_btdev.tx_queue != 0);
DEBUGASSERT(ret >= 0);
UNUSED(ret);
/* Get exclusive access to the handoff structure. The count will
@@ -609,7 +609,7 @@ void bt_conn_set_state(FAR struct bt_conn_s *conn,
if (old_state == BT_CONN_CONNECTED ||
old_state == BT_CONN_DISCONNECT)
{
bt_queue_send(conn->tx_queue, bt_buf_alloc(BT_DUMMY, NULL, 0),
bt_queue_send(&conn->tx_queue, bt_buf_alloc(BT_DUMMY, NULL, 0),
BT_NORMAL_PRIO);
}
+2 -2
View File
@@ -49,7 +49,7 @@
#include <nuttx/config.h>
#include <mqueue.h>
#include <nuttx/mqueue.h>
#include "bt_atomic.h"
@@ -96,7 +96,7 @@ struct bt_conn_s
/* Queue for outgoing ACL data */
mqd_t tx_queue;
struct file tx_queue;
FAR struct bt_keys_s *keys;
+4 -5
View File
@@ -1012,7 +1012,7 @@ static int hci_tx_kthread(int argc, FAR char *argv[])
/* Get next command - wait if necessary */
buf = NULL;
ret = bt_queue_receive(g_btdev.tx_queue, &buf);
ret = bt_queue_receive(&g_btdev.tx_queue, &buf);
DEBUGASSERT(ret >= 0 && buf != NULL);
UNUSED(ret);
@@ -1450,10 +1450,9 @@ static void cmd_queue_init(void)
* the Tx queue and received by logic on the Tx kernel thread.
*/
g_btdev.tx_queue = NULL;
ret = bt_queue_open(BT_HCI_TX, O_RDWR | O_CREAT,
CONFIG_BLUETOOTH_TXCMD_NMSGS, &g_btdev.tx_queue);
DEBUGASSERT(ret >= 0 && g_btdev.tx_queue != NULL);
DEBUGASSERT(ret >= 0);
UNUSED(ret);
nxsem_init(&g_btdev.ncmd_sem, 0, 1);
@@ -1769,7 +1768,7 @@ int bt_hci_cmd_send(uint16_t opcode, FAR struct bt_buf_s *buf)
return 0;
}
ret = bt_queue_send(g_btdev.tx_queue, buf, BT_NORMAL_PRIO);
ret = bt_queue_send(&g_btdev.tx_queue, buf, BT_NORMAL_PRIO);
if (ret < 0)
{
wlerr("ERROR: bt_queue_send() failed: %d\n", ret);
@@ -1813,7 +1812,7 @@ int bt_hci_cmd_send_sync(uint16_t opcode, FAR struct bt_buf_s *buf,
/* Send the frame */
ret = bt_queue_send(g_btdev.tx_queue, buf, BT_NORMAL_PRIO);
ret = bt_queue_send(&g_btdev.tx_queue, buf, BT_NORMAL_PRIO);
if (ret < 0)
{
wlerr("ERROR: bt_queue_send() failed: %d\n", ret);
+3 -3
View File
@@ -50,7 +50,7 @@
#include <nuttx/config.h>
#include <stdbool.h>
#include <mqueue.h>
#include <nuttx/mqueue.h>
#include <nuttx/semaphore.h>
#include <nuttx/wireless/bluetooth/bt_driver.h>
@@ -118,11 +118,11 @@ struct bt_dev_s
/* Queue for incoming HCI events and ACL data */
mqd_t rx_queue;
struct file rx_queue;
/* Queue for outgoing HCI commands */
mqd_t tx_queue;
struct file tx_queue;
/* Registered HCI driver */
+13 -17
View File
@@ -94,10 +94,9 @@ struct bt_bufmsg_s
****************************************************************************/
int bt_queue_open(FAR const char *name, int oflags, int nmsgs,
FAR mqd_t *mqd)
FAR struct file *mqd)
{
struct mq_attr attr;
mqd_t newmqd;
int ret = OK;
/* Initialize the message queue attributes */
@@ -106,17 +105,12 @@ int bt_queue_open(FAR const char *name, int oflags, int nmsgs,
attr.mq_msgsize = BT_MSGSIZE;
attr.mq_flags = BT_MSGFLAGS;
newmqd = mq_open(name, oflags, 0666, &attr);
if (newmqd == (mqd_t)-1)
ret = file_mq_open(mqd, name, oflags, 0666, &attr);
if (ret < 0)
{
/* REVISIT: mq_open() modifies the errno value */
ret = -get_errno();
gerr("ERROR: mq_open(%s) failed: %d\n", name, ret);
newmqd = NULL;
gerr("ERROR: file_mq_open(%s) failed: %d\n", name, ret);
}
*mqd = newmqd;
return ret;
}
@@ -137,7 +131,7 @@ int bt_queue_open(FAR const char *name, int oflags, int nmsgs,
*
****************************************************************************/
int bt_queue_receive(mqd_t mqd, FAR struct bt_buf_s **buf)
int bt_queue_receive(struct file *mqd, FAR struct bt_buf_s **buf)
{
union
{
@@ -153,10 +147,10 @@ int bt_queue_receive(mqd_t mqd, FAR struct bt_buf_s **buf)
/* Wait for the next message */
u.msg.buf = NULL;
msgsize = nxmq_receive(mqd, u.msgbuf, BT_MSGSIZE, &priority);
msgsize = file_mq_receive(mqd, u.msgbuf, BT_MSGSIZE, &priority);
if (msgsize < 0)
{
wlerr("ERROR: nxmq_receive() failed: %ld\n", (long)msgsize);
wlerr("ERROR: file_mq_receive() failed: %ld\n", (long)msgsize);
return (int)msgsize;
}
@@ -193,7 +187,9 @@ int bt_queue_receive(mqd_t mqd, FAR struct bt_buf_s **buf)
*
****************************************************************************/
int bt_queue_send(mqd_t mqd, FAR struct bt_buf_s *buf, unsigned int priority)
int bt_queue_send(struct file *mqd,
FAR struct bt_buf_s *buf,
unsigned int priority)
{
struct bt_bufmsg_s msg;
int ret;
@@ -203,11 +199,11 @@ int bt_queue_send(mqd_t mqd, FAR struct bt_buf_s *buf, unsigned int priority)
/* Format and send the buffer message */
msg.buf = buf;
ret = nxmq_send(mqd, (FAR const char *)&msg, sizeof(struct bt_bufmsg_s),
priority);
ret = file_mq_send(mqd, (FAR const char *)&msg,
sizeof(struct bt_bufmsg_s), priority);
if (ret < 0)
{
wlerr("ERROR: mq_send() failed: %d\n", ret);
wlerr("ERROR: file_mq_send() failed: %d\n", ret);
}
return ret;
+4 -4
View File
@@ -43,9 +43,9 @@
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <nuttx/mqueue.h>
#include <limits.h>
#include <mqueue.h>
/****************************************************************************
* Pre-processor Definitions
@@ -100,7 +100,7 @@ struct bt_buf_s; /* Forward Reference */
****************************************************************************/
int bt_queue_open(FAR const char *name, int oflags, int nmsgs,
FAR mqd_t *mqd);
FAR struct file *mqd);
/****************************************************************************
* Name: bt_queue_receive
@@ -119,7 +119,7 @@ int bt_queue_open(FAR const char *name, int oflags, int nmsgs,
*
****************************************************************************/
int bt_queue_receive(mqd_t mqd, FAR struct bt_buf_s **buf);
int bt_queue_receive(struct file *mqd, FAR struct bt_buf_s **buf);
/****************************************************************************
* Name: bt_queue_send
@@ -141,7 +141,7 @@ int bt_queue_receive(mqd_t mqd, FAR struct bt_buf_s **buf);
*
****************************************************************************/
int bt_queue_send(mqd_t mqd,
int bt_queue_send(struct file *mqd,
FAR struct bt_buf_s *buf,
unsigned int priority);