You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/01/05 08:40:56 UTC
[incubator-nuttx] 02/02: mqueue: add file_mq_xx for kernel use
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit f63db663820209073ee934c3ee5a5b360438f780
Author: ligd <li...@xiaomi.com>
AuthorDate: Thu Dec 24 20:53:17 2020 +0800
mqueue: add file_mq_xx for kernel use
Change-Id: Ida12f5938388cca2f233a4cde90277a218033645
Signed-off-by: ligd <li...@xiaomi.com>
---
arch/arm/src/cxd56xx/cxd56_farapi.c | 1 +
arch/arm/src/cxd56xx/cxd56_powermgr.c | 55 +++---
arch/xtensa/src/esp32/esp32_wifi_adapter.c | 38 ++--
audio/audio.c | 18 +-
drivers/audio/audio_null.c | 27 +--
drivers/audio/cs4344.c | 33 ++--
drivers/audio/cs4344.h | 2 +-
drivers/audio/cs43l22.c | 33 ++--
drivers/audio/cs43l22.h | 2 +-
drivers/audio/cxd56.c | 69 +++----
drivers/audio/cxd56.h | 2 +-
drivers/audio/cxd56_src.c | 20 +-
drivers/audio/vs1053.c | 42 ++---
drivers/audio/wm8776.c | 33 ++--
drivers/audio/wm8776.h | 4 +-
drivers/audio/wm8904.c | 33 ++--
drivers/audio/wm8904.h | 2 +-
drivers/audio/wm8994.c | 31 ++--
drivers/audio/wm8994.h | 4 +-
drivers/lcd/ssd1306_base.c | 1 +
drivers/sensors/mpu60x0.c | 1 +
fs/mqueue/mq_close.c | 28 +++
fs/mqueue/mq_open.c | 237 ++++++++++++++++--------
fs/mqueue/mq_unlink.c | 32 +++-
include/nuttx/mqueue.h | 285 ++++++++++++++++++++++++++++-
sched/mqueue/mq_getattr.c | 64 +++++--
sched/mqueue/mq_receive.c | 73 ++++++--
sched/mqueue/mq_send.c | 71 +++++--
sched/mqueue/mq_setattr.c | 69 +++++--
sched/mqueue/mq_timedreceive.c | 83 +++++++--
sched/mqueue/mq_timedsend.c | 96 +++++++---
wireless/bluetooth/bt_conn.c | 12 +-
wireless/bluetooth/bt_conn.h | 4 +-
wireless/bluetooth/bt_hcicore.c | 9 +-
wireless/bluetooth/bt_hcicore.h | 6 +-
wireless/bluetooth/bt_queue.c | 30 ++-
wireless/bluetooth/bt_queue.h | 8 +-
37 files changed, 1116 insertions(+), 442 deletions(-)
diff --git a/arch/arm/src/cxd56xx/cxd56_farapi.c b/arch/arm/src/cxd56xx/cxd56_farapi.c
index 0fb2bdd..048ef03 100644
--- a/arch/arm/src/cxd56xx/cxd56_farapi.c
+++ b/arch/arm/src/cxd56xx/cxd56_farapi.c
@@ -42,6 +42,7 @@
#include <nuttx/arch.h>
#include <nuttx/sched.h>
#include <nuttx/irq.h>
+#include <nuttx/signal.h>
#include <debug.h>
#include <errno.h>
diff --git a/arch/arm/src/cxd56xx/cxd56_powermgr.c b/arch/arm/src/cxd56xx/cxd56_powermgr.c
index 3ec4655..08b68ee 100644
--- a/arch/arm/src/cxd56xx/cxd56_powermgr.c
+++ b/arch/arm/src/cxd56xx/cxd56_powermgr.c
@@ -42,11 +42,11 @@
#include <nuttx/config.h>
#include <nuttx/kmalloc.h>
+#include <nuttx/mqueue.h>
#include <debug.h>
#include <errno.h>
#include <sched.h>
-#include <mqueue.h>
#include <fcntl.h>
#include <queue.h>
@@ -172,16 +172,16 @@ static int cxd56_pmmsghandler(int cpuid, int protoid, uint32_t pdata,
****************************************************************************/
static struct cxd56_pm_target_id_s g_target_id_table;
-static mqd_t g_queuedesc;
-static sem_t g_bootsync;
-static sem_t g_regcblock;
-static sem_t g_freqlock;
-static sem_t g_freqlockwait;
-static dq_queue_t g_cbqueue;
-static sq_queue_t g_freqlockqueue;
-static sq_queue_t g_wakelockqueue;
-static uint32_t g_clockcange_start;
-static int g_freqlock_flag;
+static struct file g_queuedesc;
+static sem_t g_bootsync;
+static sem_t g_regcblock;
+static sem_t g_freqlock;
+static sem_t g_freqlockwait;
+static dq_queue_t g_cbqueue;
+static sq_queue_t g_freqlockqueue;
+static sq_queue_t g_wakelockqueue;
+static uint32_t g_clockcange_start;
+static int g_freqlock_flag;
static struct pm_cpu_wakelock_s g_wlock =
PM_CPUWAKELOCK_INIT(PM_CPUWAKELOCK_TAG('P', 'M', 0));
@@ -433,20 +433,23 @@ static void cxd56_pm_do_hotsleep(uint32_t idletime)
static int cxd56_pm_maintask(int argc, FAR char *argv[])
{
- int size;
struct cxd56_pm_message_s message;
struct mq_attr attr;
+ int size;
+ int ret;
attr.mq_maxmsg = 8;
attr.mq_msgsize = sizeof(struct cxd56_pm_message_s);
attr.mq_curmsgs = 0;
attr.mq_flags = 0;
- g_queuedesc = mq_open("cxd56_pm_message", O_RDWR | O_CREAT, 0666, &attr);
- DEBUGASSERT((int)g_queuedesc != ERROR);
- if (g_queuedesc < 0)
+ ret = file_mq_open(&g_queuedesc, "cxd56_pm_message",
+ O_RDWR | O_CREAT, 0666, &attr);
+ DEBUGASSERT(ret >= 0);
+ if (ret < 0)
{
pmerr("Failed to create message queue\n");
+ return ret;
}
/* Register power manager messaging protocol handler. */
@@ -461,8 +464,8 @@ static int cxd56_pm_maintask(int argc, FAR char *argv[])
while (1)
{
- size = mq_receive(g_queuedesc, (FAR char *)&message, sizeof(message),
- NULL);
+ size = file_mq_receive(&g_queuedesc, (FAR char *)&message,
+ sizeof(message), NULL);
if (size == sizeof(message))
{
switch (message.mid)
@@ -530,21 +533,21 @@ static int cxd56_pmmsghandler(int cpuid, int protoid, uint32_t pdata,
if (msgid == MSGID_CLK_CHG_START)
{
message.mid = MQMSG_CLK_CHG_START;
- ret = mq_send(g_queuedesc, (FAR const char *)&message, sizeof(message),
- CXD56_PM_MESSAGE_PRIO);
+ ret = file_mq_send(&g_queuedesc, (FAR const char *)&message,
+ sizeof(message), CXD56_PM_MESSAGE_PRIO);
if (ret < 0)
{
- pmerr("ERR:mq_send(CLK_CHG_START)\n");
+ pmerr("ERR:file_mq_send(CLK_CHG_START)\n");
}
}
else if (msgid == MSGID_CLK_CHG_END)
{
message.mid = MQMSG_CLK_CHG_END;
- ret = mq_send(g_queuedesc, (FAR const char *)&message, sizeof(message),
- CXD56_PM_MESSAGE_PRIO);
+ ret = file_mq_send(&g_queuedesc, (FAR const char *)&message,
+ sizeof(message), CXD56_PM_MESSAGE_PRIO);
if (ret < 0)
{
- pmerr("ERR:mq_send(CLK_CHG_END)\n");
+ pmerr("ERR:file_mq_send(CLK_CHG_END)\n");
}
}
else if (msgid == MSGID_FREQLOCK)
@@ -800,11 +803,11 @@ int cxd56_pm_hotsleep(int idletime)
message.mid = MQMSG_HOT_SLEEP;
message.data = (uint32_t)idletime;
- ret = mq_send(g_queuedesc, (FAR const char *)&message, sizeof(message),
- CXD56_PM_MESSAGE_PRIO);
+ ret = file_mq_send(&g_queuedesc, (FAR const char *)&message,
+ sizeof(message), CXD56_PM_MESSAGE_PRIO);
if (ret < 0)
{
- pmerr("ERR:mq_send(HOT_SLEEP)\n");
+ pmerr("ERR:file_mq_send(HOT_SLEEP)\n");
return -1;
}
diff --git a/arch/xtensa/src/esp32/esp32_wifi_adapter.c b/arch/xtensa/src/esp32/esp32_wifi_adapter.c
index 4df8bda..1f479cf 100644
--- a/arch/xtensa/src/esp32/esp32_wifi_adapter.c
+++ b/arch/xtensa/src/esp32/esp32_wifi_adapter.c
@@ -29,7 +29,6 @@
#include <string.h>
#include <assert.h>
#include <pthread.h>
-#include <mqueue.h>
#include <fcntl.h>
#include <unistd.h>
#include <clock/clock.h>
@@ -37,6 +36,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "nuttx/kmalloc.h"
+#include <nuttx/mqueue.h>
#include "nuttx/spinlock.h"
#include <nuttx/irq.h>
#include <nuttx/semaphore.h>
@@ -88,9 +88,9 @@ struct irq_adpt
struct mq_adpt
{
- mqd_t mq; /* Message queue handle */
- uint32_t msgsize; /* Message size */
- char name[16]; /* Message queue name */
+ struct file mq; /* Message queue handle */
+ uint32_t msgsize; /* Message size */
+ char name[16]; /* Message queue name */
};
/* WiFi time private data */
@@ -1254,8 +1254,8 @@ static int32_t esp_mutex_unlock(void *mutex_data)
static void *esp_queue_create(uint32_t queue_len, uint32_t item_size)
{
struct mq_attr attr;
- mqd_t mq;
struct mq_adpt *mq_adpt;
+ int ret;
mq_adpt = kmm_malloc(sizeof(struct mq_adpt));
if (!mq_adpt)
@@ -1272,15 +1272,15 @@ static void *esp_queue_create(uint32_t queue_len, uint32_t item_size)
attr.mq_curmsgs = 0;
attr.mq_flags = 0;
- mq = mq_open(mq_adpt->name, O_RDWR | O_CREAT, 0644, &attr);
- if (!mq)
+ ret = file_mq_open(&mq_adpt->mq, mq_adpt->name,
+ O_RDWR | O_CREAT, 0644, &attr);
+ if (ret < 0)
{
wlerr("ERROR: Failed to create mqueue\n");
kmm_free(mq_adpt);
return NULL;
}
- mq_adpt->mq = mq;
mq_adpt->msgsize = item_size;
return (void *)mq_adpt;
@@ -1304,8 +1304,8 @@ static void esp_queue_delete(void *queue)
{
struct mq_adpt *mq_adpt = (struct mq_adpt *)queue;
- mq_close(mq_adpt->mq);
- mq_unlink(mq_adpt->name);
+ file_mq_close(&mq_adpt->mq);
+ file_mq_unlink(mq_adpt->name);
kmm_free(mq_adpt);
}
@@ -1341,8 +1341,8 @@ static int32_t esp_queue_send_generic(void *queue, void *item,
* instead of application API
*/
- ret = nxmq_send(mq_adpt->mq, (const char *)item,
- mq_adpt->msgsize, prio);
+ ret = file_mq_send(&mq_adpt->mq, (const char *)item,
+ mq_adpt->msgsize, prio);
if (ret < 0)
{
wlerr("ERROR: Failed to send message to mqueue error=%d\n",
@@ -1363,8 +1363,8 @@ static int32_t esp_queue_send_generic(void *queue, void *item,
esp_update_time(&timeout, ticks);
}
- ret = mq_timedsend(mq_adpt->mq, (const char *)item,
- mq_adpt->msgsize, prio, &timeout);
+ ret = file_mq_timedsend(&mq_adpt->mq, (const char *)item,
+ mq_adpt->msgsize, prio, &timeout);
if (ret < 0)
{
wlerr("ERROR: Failed to timedsend message to mqueue error=%d\n",
@@ -1491,8 +1491,8 @@ static int32_t esp_queue_recv(void *queue, void *item, uint32_t ticks)
if (ticks == OSI_FUNCS_TIME_BLOCKING)
{
- ret = mq_receive(mq_adpt->mq, (char *)item,
- mq_adpt->msgsize, &prio);
+ ret = file_mq_receive(&mq_adpt->mq, (char *)item,
+ mq_adpt->msgsize, &prio);
if (ret < 0)
{
wlerr("ERROR: Failed to receive from mqueue error=%d\n", ret);
@@ -1512,8 +1512,8 @@ static int32_t esp_queue_recv(void *queue, void *item, uint32_t ticks)
esp_update_time(&timeout, ticks);
}
- ret = mq_timedreceive(mq_adpt->mq, (char *)item,
- mq_adpt->msgsize, &prio, &timeout);
+ ret = file_mq_timedreceive(&mq_adpt->mq, (char *)item,
+ mq_adpt->msgsize, &prio, &timeout);
if (ret < 0)
{
wlerr("ERROR: Failed to timedreceive from mqueue error=%d\n",
@@ -1544,7 +1544,7 @@ static uint32_t esp_queue_msg_waiting(void *queue)
struct mq_attr attr;
struct mq_adpt *mq_adpt = (struct mq_adpt *)queue;
- ret = mq_getattr(mq_adpt->mq, &attr);
+ ret = file_mq_getattr(&mq_adpt->mq, &attr);
if (ret < 0)
{
wlerr("ERROR: Failed to get attr from mqueue error=%d\n", ret);
diff --git a/audio/audio.c b/audio/audio.c
index 05fbcb9..c468f50 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -46,7 +46,6 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-#include <mqueue.h>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
@@ -91,7 +90,7 @@ struct audio_upperhalf_s
volatile bool started; /* True: playback is active */
sem_t exclsem; /* Supports mutual exclusion */
FAR struct audio_lowerhalf_s *dev; /* lower-half state */
- mqd_t usermq; /* User mode app's message queue */
+ struct file *usermq; /* User mode app's message queue */
};
/****************************************************************************
@@ -608,8 +607,7 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
audinfo("AUDIOIOC_REGISTERMQ\n");
- upper->usermq = (mqd_t) arg;
- ret = OK;
+ ret = fs_getfilep((mqd_t)arg, &upper->usermq);
}
break;
@@ -739,8 +737,8 @@ static inline void audio_dequeuebuffer(FAR struct audio_upperhalf_s *upper,
msg.session = session;
#endif
apb->flags |= AUDIO_APB_DEQUEUED;
- nxmq_send(upper->usermq, (FAR const char *)&msg, sizeof(msg),
- CONFIG_AUDIO_BUFFER_DEQUEUE_PRIO);
+ file_mq_send(upper->usermq, (FAR const char *)&msg, sizeof(msg),
+ CONFIG_AUDIO_BUFFER_DEQUEUE_PRIO);
}
}
@@ -777,8 +775,8 @@ static inline void audio_complete(FAR struct audio_upperhalf_s *upper,
#ifdef CONFIG_AUDIO_MULTI_SESSION
msg.session = session;
#endif
- nxmq_send(upper->usermq, (FAR const char *)&msg, sizeof(msg),
- CONFIG_AUDIO_BUFFER_DEQUEUE_PRIO);
+ file_mq_send(upper->usermq, (FAR const char *)&msg, sizeof(msg),
+ CONFIG_AUDIO_BUFFER_DEQUEUE_PRIO);
}
}
@@ -810,8 +808,8 @@ static inline void audio_message(FAR struct audio_upperhalf_s *upper,
#ifdef CONFIG_AUDIO_MULTI_SESSION
msg->session = session;
#endif
- nxmq_send(upper->usermq, (FAR const char *)msg, sizeof(*msg),
- CONFIG_AUDIO_BUFFER_DEQUEUE_PRIO);
+ file_mq_send(upper->usermq, (FAR const char *)msg, sizeof(*msg),
+ CONFIG_AUDIO_BUFFER_DEQUEUE_PRIO);
}
}
diff --git a/drivers/audio/audio_null.c b/drivers/audio/audio_null.c
index d153e34..d4aabb71 100644
--- a/drivers/audio/audio_null.c
+++ b/drivers/audio/audio_null.c
@@ -72,7 +72,7 @@ struct null_dev_s
{
struct audio_lowerhalf_s dev; /* Audio lower half (this device) */
uint32_t scaler; /* Data bytes to sec scaler (bytes per sec) */
- mqd_t mq; /* Message queue for receiving messages */
+ struct file mq; /* Message queue for receiving messages */
char mqname[16]; /* Our message queue name */
pthread_t threadid; /* ID of our thread */
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
@@ -499,7 +499,8 @@ static void *null_workerthread(pthread_addr_t pvarg)
{
/* Wait for messages from our message queue */
- msglen = nxmq_receive(priv->mq, (FAR char *)&msg, sizeof(msg), &prio);
+ msglen = file_mq_receive(&priv->mq, (FAR char *)&msg,
+ sizeof(msg), &prio);
/* Handle the case when we return with no message */
@@ -537,9 +538,8 @@ static void *null_workerthread(pthread_addr_t pvarg)
/* Close the message queue */
- mq_close(priv->mq);
- mq_unlink(priv->mqname);
- priv->mq = NULL;
+ file_mq_close(&priv->mq);
+ file_mq_unlink(priv->mqname);
priv->terminate = false;
/* Send an AUDIO_MSG_COMPLETE message to the client */
@@ -587,13 +587,14 @@ static int null_start(FAR struct audio_lowerhalf_s *dev)
attr.mq_curmsgs = 0;
attr.mq_flags = 0;
- priv->mq = mq_open(priv->mqname, O_RDWR | O_CREAT, 0644, &attr);
- if (priv->mq == NULL)
+ ret = file_mq_open(&priv->mq, priv->mqname,
+ O_RDWR | O_CREAT, 0644, &attr);
+ if (ret < 0)
{
/* Error creating message queue! */
auderr("ERROR: Couldn't allocate message queue\n");
- return -ENOMEM;
+ return ret;
}
/* Join any old worker thread we had created to prevent a memory leak */
@@ -655,8 +656,8 @@ static int null_stop(FAR struct audio_lowerhalf_s *dev)
term_msg.msg_id = AUDIO_MSG_STOP;
term_msg.u.data = 0;
- nxmq_send(priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
- CONFIG_AUDIO_NULL_MSG_PRIO);
+ file_mq_send(&priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
+ CONFIG_AUDIO_NULL_MSG_PRIO);
/* Join the worker thread */
@@ -727,11 +728,11 @@ static int null_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
msg.msg_id = AUDIO_MSG_ENQUEUE;
msg.u.ptr = apb;
- ret = nxmq_send(priv->mq, (FAR const char *)&msg,
- sizeof(msg), CONFIG_AUDIO_NULL_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *)&msg,
+ sizeof(msg), CONFIG_AUDIO_NULL_MSG_PRIO);
if (ret < 0)
{
- auderr("ERROR: nxmq_send failed: %d\n", ret);
+ auderr("ERROR: file_mq_send failed: %d\n", ret);
}
audinfo("Return OK\n");
diff --git a/drivers/audio/cs4344.c b/drivers/audio/cs4344.c
index 928a573..a44466a 100644
--- a/drivers/audio/cs4344.c
+++ b/drivers/audio/cs4344.c
@@ -583,11 +583,11 @@ cs4344_senddone(FAR struct i2s_dev_s *i2s,
*/
msg.msg_id = AUDIO_MSG_COMPLETE;
- ret = nxmq_send(priv->mq, (FAR const char *)&msg, sizeof(msg),
- CONFIG_CS4344_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *)&msg, sizeof(msg),
+ CONFIG_CS4344_MSG_PRIO);
if (ret < 0)
{
- auderr("ERROR: nxmq_send failed: %d\n", ret);
+ auderr("ERROR: file_mq_send failed: %d\n", ret);
}
}
@@ -786,13 +786,14 @@ static int cs4344_start(FAR struct audio_lowerhalf_s *dev)
attr.mq_curmsgs = 0;
attr.mq_flags = 0;
- priv->mq = mq_open(priv->mqname, O_RDWR | O_CREAT, 0644, &attr);
- if (priv->mq == NULL)
+ ret = file_mq_open(&priv->mq, priv->mqname,
+ O_RDWR | O_CREAT, 0644, &attr);
+ if (ret < 0)
{
/* Error creating message queue! */
auderr("ERROR: Couldn't allocate message queue\n");
- return -ENOMEM;
+ return ret;
}
/* Join any old worker thread we had created to prevent a memory leak */
@@ -849,8 +850,8 @@ static int cs4344_stop(FAR struct audio_lowerhalf_s *dev)
term_msg.msg_id = AUDIO_MSG_STOP;
term_msg.u.data = 0;
- nxmq_send(priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
- CONFIG_CS4344_MSG_PRIO);
+ file_mq_send(&priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
+ CONFIG_CS4344_MSG_PRIO);
/* Join the worker thread */
@@ -962,16 +963,16 @@ static int cs4344_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
*/
ret = OK;
- if (priv->mq != NULL)
+ if (priv->mq.f_inode != NULL)
{
term_msg.msg_id = AUDIO_MSG_ENQUEUE;
term_msg.u.data = 0;
- ret = nxmq_send(priv->mq, (FAR const char *)&term_msg,
- sizeof(term_msg), CONFIG_CS4344_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *)&term_msg,
+ sizeof(term_msg), CONFIG_CS4344_MSG_PRIO);
if (ret < 0)
{
- auderr("ERROR: nxmq_send failed: %d\n", ret);
+ auderr("ERROR: file_mq_send failed: %d\n", ret);
}
}
@@ -1189,7 +1190,8 @@ static void *cs4344_workerthread(pthread_addr_t pvarg)
/* Wait for messages from our message queue */
- msglen = nxmq_receive(priv->mq, (FAR char *)&msg, sizeof(msg), &prio);
+ msglen = file_mq_receive(&priv->mq, (FAR char *)&msg,
+ sizeof(msg), &prio);
/* Handle the case when we return with no message */
@@ -1274,9 +1276,8 @@ static void *cs4344_workerthread(pthread_addr_t pvarg)
/* Close the message queue */
- mq_close(priv->mq);
- mq_unlink(priv->mqname);
- priv->mq = NULL;
+ file_mq_close(&priv->mq);
+ file_mq_unlink(priv->mqname);
/* Send an AUDIO_MSG_COMPLETE message to the client */
diff --git a/drivers/audio/cs4344.h b/drivers/audio/cs4344.h
index 44d914e..18377ae 100644
--- a/drivers/audio/cs4344.h
+++ b/drivers/audio/cs4344.h
@@ -67,7 +67,7 @@ struct cs4344_dev_s
FAR struct i2s_dev_s *i2s; /* I2S driver to use */
struct dq_queue_s pendq; /* Queue of pending buffers to be sent */
struct dq_queue_s doneq; /* Queue of sent buffers to be returned */
- mqd_t mq; /* Message queue for receiving messages */
+ struct file mq; /* Message queue for receiving messages */
char mqname[16]; /* Our message queue name */
pthread_t threadid; /* ID of our thread */
uint32_t bitrate; /* Actual programmed bit rate */
diff --git a/drivers/audio/cs43l22.c b/drivers/audio/cs43l22.c
index 3ab0759..4a99bcb 100644
--- a/drivers/audio/cs43l22.c
+++ b/drivers/audio/cs43l22.c
@@ -1016,11 +1016,11 @@ cs43l22_senddone(FAR struct i2s_dev_s *i2s,
*/
msg.msg_id = AUDIO_MSG_COMPLETE;
- ret = nxmq_send(priv->mq, (FAR const char *)&msg, sizeof(msg),
- CONFIG_CS43L22_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *)&msg, sizeof(msg),
+ CONFIG_CS43L22_MSG_PRIO);
if (ret < 0)
{
- auderr("ERROR: nxmq_send failed: %d\n", ret);
+ auderr("ERROR: file_mq_send failed: %d\n", ret);
}
}
@@ -1223,13 +1223,14 @@ static int cs43l22_start(FAR struct audio_lowerhalf_s *dev)
attr.mq_curmsgs = 0;
attr.mq_flags = 0;
- priv->mq = mq_open(priv->mqname, O_RDWR | O_CREAT, 0644, &attr);
- if (priv->mq == NULL)
+ ret = file_mq_open(&priv->mq, priv->mqname,
+ O_RDWR | O_CREAT, 0644, &attr);
+ if (ret < 0)
{
/* Error creating message queue! */
auderr("ERROR: Couldn't allocate message queue\n");
- return -ENOMEM;
+ return ret;
}
/* Join any old worker thread we had created to prevent a memory leak */
@@ -1286,8 +1287,8 @@ static int cs43l22_stop(FAR struct audio_lowerhalf_s *dev)
term_msg.msg_id = AUDIO_MSG_STOP;
term_msg.u.data = 0;
- nxmq_send(priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
- CONFIG_CS43L22_MSG_PRIO);
+ file_mq_send(&priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
+ CONFIG_CS43L22_MSG_PRIO);
/* Join the worker thread */
@@ -1409,16 +1410,16 @@ static int cs43l22_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
*/
ret = OK;
- if (priv->mq != NULL)
+ if (priv->mq.f_inode != NULL)
{
term_msg.msg_id = AUDIO_MSG_ENQUEUE;
term_msg.u.data = 0;
- ret = nxmq_send(priv->mq, (FAR const char *)&term_msg,
- sizeof(term_msg), CONFIG_CS43L22_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *)&term_msg,
+ sizeof(term_msg), CONFIG_CS43L22_MSG_PRIO);
if (ret < 0)
{
- auderr("ERROR: nxmq_send failed: %d\n", ret);
+ auderr("ERROR: file_mq_send failed: %d\n", ret);
}
}
@@ -1684,7 +1685,8 @@ static void *cs43l22_workerthread(pthread_addr_t pvarg)
/* Wait for messages from our message queue */
- msglen = nxmq_receive(priv->mq, (FAR char *)&msg, sizeof(msg), &prio);
+ msglen = file_mq_receive(&priv->mq, (FAR char *)&msg,
+ sizeof(msg), &prio);
/* Handle the case when we return with no message */
@@ -1769,9 +1771,8 @@ static void *cs43l22_workerthread(pthread_addr_t pvarg)
/* Close the message queue */
- mq_close(priv->mq);
- mq_unlink(priv->mqname);
- priv->mq = NULL;
+ file_mq_close(&priv->mq);
+ file_mq_unlink(priv->mqname);
/* Send an AUDIO_MSG_COMPLETE message to the client */
diff --git a/drivers/audio/cs43l22.h b/drivers/audio/cs43l22.h
index bd0089d..103adf5 100644
--- a/drivers/audio/cs43l22.h
+++ b/drivers/audio/cs43l22.h
@@ -340,7 +340,7 @@ struct cs43l22_dev_s
FAR struct i2s_dev_s *i2s; /* I2S driver to use */
struct dq_queue_s pendq; /* Queue of pending buffers to be sent */
struct dq_queue_s doneq; /* Queue of sent buffers to be returned */
- mqd_t mq; /* Message queue for receiving messages */
+ struct file mq; /* Message queue for receiving messages */
char mqname[16]; /* Our message queue name */
pthread_t threadid; /* ID of our thread */
uint32_t bitrate; /* Actual programmed bit rate */
diff --git a/drivers/audio/cxd56.c b/drivers/audio/cxd56.c
index 80aeb5f..babe0ca 100644
--- a/drivers/audio/cxd56.c
+++ b/drivers/audio/cxd56.c
@@ -1301,12 +1301,12 @@ static void _process_audio_with_src(cxd56_dmahandle_t hdl, uint16_t err_code)
msg.msg_id = AUDIO_MSG_STOP;
msg.u.data = 0;
spin_unlock_irqrestore(flags);
- ret = nxmq_send(dev->mq, (FAR const char *)&msg,
- sizeof(msg), CONFIG_CXD56_MSG_PRIO);
+ ret = file_mq_send(&dev->mq, (FAR const char *)&msg,
+ sizeof(msg), CONFIG_CXD56_MSG_PRIO);
flags = spin_lock_irqsave();
if (ret != OK)
{
- auderr("ERROR: nxmq_send to stop failed (%d)\n", ret);
+ auderr("ERROR: file_mq_send to stop failed (%d)\n", ret);
}
}
}
@@ -1335,12 +1335,12 @@ static void _process_audio_with_src(cxd56_dmahandle_t hdl, uint16_t err_code)
msg.msg_id = AUDIO_MSG_STOP;
msg.u.data = 0;
spin_unlock_irqrestore(flags);
- ret = nxmq_send(dev->mq, (FAR const char *)&msg,
- sizeof(msg), CONFIG_CXD56_MSG_PRIO);
+ ret = file_mq_send(&dev->mq, (FAR const char *)&msg,
+ sizeof(msg), CONFIG_CXD56_MSG_PRIO);
flags = spin_lock_irqsave();
if (ret != OK)
{
- auderr("ERROR: nxmq_send to stop failed (%d)\n", ret);
+ auderr("ERROR: file_mq_send to stop failed (%d)\n", ret);
}
request_buffer = false;
@@ -1348,19 +1348,19 @@ static void _process_audio_with_src(cxd56_dmahandle_t hdl, uint16_t err_code)
}
}
- if (request_buffer && dev->mq != NULL)
+ if (request_buffer && dev->mq.f_inode != NULL)
{
/* Request more data */
msg.msg_id = AUDIO_MSG_DATA_REQUEST;
msg.u.data = 0;
spin_unlock_irqrestore(flags);
- ret = nxmq_send(dev->mq, (FAR const char *) &msg,
- sizeof(msg), CONFIG_CXD56_MSG_PRIO);
+ ret = file_mq_send(&dev->mq, (FAR const char *) &msg,
+ sizeof(msg), CONFIG_CXD56_MSG_PRIO);
flags = spin_lock_irqsave();
if (ret != OK)
{
- auderr("ERROR: nxmq_send to request failed (%d)\n", ret);
+ auderr("ERROR: file_mq_send to request failed (%d)\n", ret);
}
}
@@ -1403,25 +1403,25 @@ static void _process_audio(cxd56_dmahandle_t hdl, uint16_t err_code)
dq_count(&dev->up_pendq));
msg.msg_id = AUDIO_MSG_STOP;
msg.u.data = 0;
- ret = nxmq_send(dev->mq, (FAR const char *)&msg,
- sizeof(msg), CONFIG_CXD56_MSG_PRIO);
+ ret = file_mq_send(&dev->mq, (FAR const char *)&msg,
+ sizeof(msg), CONFIG_CXD56_MSG_PRIO);
if (ret != OK)
{
- auderr("ERROR: nxmq_send to stop failed (%d)\n", ret);
+ auderr("ERROR: file_mq_send to stop failed (%d)\n", ret);
}
}
}
- else if (dev->mq != NULL)
+ else if (dev->mq.f_inode != NULL)
{
/* Request more data */
msg.msg_id = AUDIO_MSG_DATA_REQUEST;
msg.u.data = 0;
- ret = nxmq_send(dev->mq, (FAR const char *) &msg,
- sizeof(msg), CONFIG_CXD56_MSG_PRIO);
+ ret = file_mq_send(&dev->mq, (FAR const char *) &msg,
+ sizeof(msg), CONFIG_CXD56_MSG_PRIO);
if (ret != OK)
{
- auderr("ERROR: nxmq_send to request failed (%d)\n", ret);
+ auderr("ERROR: file_mq_send to request failed (%d)\n", ret);
}
}
}
@@ -3031,11 +3031,11 @@ static int cxd56_stop(FAR struct audio_lowerhalf_s *lower)
msg.msg_id = AUDIO_MSG_STOP;
msg.u.data = 0;
- ret = nxmq_send(priv->mq, (FAR const char *)&msg,
- sizeof(msg), CONFIG_CXD56_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *)&msg,
+ sizeof(msg), CONFIG_CXD56_MSG_PRIO);
if (ret != OK)
{
- auderr("ERROR: nxmq_send stop message failed (%d)\n", ret);
+ auderr("ERROR: file_mq_send stop message failed (%d)\n", ret);
return ret;
}
@@ -3392,13 +3392,13 @@ static int cxd56_start_dma(FAR struct cxd56_dev_s *dev)
msg.u.data = 0;
spin_unlock_irqrestore(flags);
- ret = nxmq_send(dev->mq, (FAR const char *)&msg,
- sizeof(msg), CONFIG_CXD56_MSG_PRIO);
+ ret = file_mq_send(&dev->mq, (FAR const char *)&msg,
+ sizeof(msg), CONFIG_CXD56_MSG_PRIO);
flags = spin_lock_irqsave();
if (ret != OK)
{
- auderr("ERROR: nxmq_send for stop failed (%d)\n", ret);
+ auderr("ERROR: file_mq_send for stop failed (%d)\n", ret);
goto exit;
}
}
@@ -3443,16 +3443,16 @@ static int cxd56_enqueuebuffer(FAR struct audio_lowerhalf_s *lower,
spin_unlock_irqrestore(flags);
- if (priv->mq != NULL)
+ if (priv->mq.f_inode != NULL)
{
msg.msg_id = AUDIO_MSG_ENQUEUE;
msg.u.data = 0;
- ret = nxmq_send(priv->mq, (FAR const char *) &msg,
- sizeof(msg), CONFIG_CXD56_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *) &msg,
+ sizeof(msg), CONFIG_CXD56_MSG_PRIO);
if (ret != OK)
{
- auderr("ERROR: nxmq_send to enqueue failed (%d)\n", ret);
+ auderr("ERROR: file_mq_send to enqueue failed (%d)\n", ret);
return ret;
}
}
@@ -3554,7 +3554,8 @@ static void *cxd56_workerthread(pthread_addr_t pvarg)
while (priv->running)
{
- size = nxmq_receive(priv->mq, (FAR char *)&msg, sizeof(msg), &prio);
+ size = file_mq_receive(&priv->mq, (FAR char *)&msg,
+ sizeof(msg), &prio);
/* Handle the case when we return with no message */
@@ -3631,9 +3632,8 @@ static void *cxd56_workerthread(pthread_addr_t pvarg)
}
}
- mq_close(priv->mq);
- mq_unlink(priv->mqname);
- priv->mq = NULL;
+ file_mq_close(&priv->mq);
+ file_mq_unlink(priv->mqname);
/* Send AUDIO_MSG_COMPLETE to the client */
@@ -3665,11 +3665,12 @@ static int cxd56_init_worker(FAR struct audio_lowerhalf_s *dev)
m_attr.mq_curmsgs = 0;
m_attr.mq_flags = 0;
- priv->mq = mq_open(priv->mqname, O_RDWR | O_CREAT, 0644, &m_attr);
- if (priv->mq == NULL)
+ ret = file_mq_open(&priv->mq, priv->mqname,
+ O_RDWR | O_CREAT, 0644, &m_attr);
+ if (ret < 0)
{
auderr("ERROR: Could not allocate message queue.\n");
- return -ENOMEM;
+ return ret;
}
/* Join any old worker thread we had created to prevent a memory leak */
diff --git a/drivers/audio/cxd56.h b/drivers/audio/cxd56.h
index efff9d3..b4c453f 100644
--- a/drivers/audio/cxd56.h
+++ b/drivers/audio/cxd56.h
@@ -279,7 +279,7 @@ struct cxd56_dev_s
const FAR struct cxd56_lower_s *lower; /* Pointer to the board lower functions */
enum cxd56_devstate_e state; /* Driver state */
enum cxd56_dmahandle_e dma_handle; /* DMA handle */
- mqd_t mq; /* Message queue for receiving messages */
+ struct file mq; /* Message queue for receiving messages */
char mqname[16]; /* Our message queue name */
pthread_t threadid; /* ID of our thread */
sem_t pendsem; /* Protect pendq */
diff --git a/drivers/audio/cxd56_src.c b/drivers/audio/cxd56_src.c
index 70ec599..23ba90c 100644
--- a/drivers/audio/cxd56_src.c
+++ b/drivers/audio/cxd56_src.c
@@ -91,7 +91,7 @@ struct cxd56_srcdata_s
struct dq_queue_s *outq;
char mqname[32];
- mqd_t mq;
+ struct file mq;
sem_t pendsem;
pthread_t threadid;
@@ -369,7 +369,8 @@ static void *cxd56_src_thread(pthread_addr_t pvarg)
while (g_src.state == CXD56_SRC_RUNNING)
{
- size = nxmq_receive(g_src.mq, (FAR char *)&msg, sizeof(msg), &prio);
+ size = file_mq_receive(&g_src.mq, (FAR char *)&msg,
+ sizeof(msg), &prio);
/* Handle the case when we return with no message */
@@ -450,11 +451,12 @@ int cxd56_src_init(FAR struct cxd56_dev_s *dev,
m_attr.mq_curmsgs = 0;
m_attr.mq_flags = 0;
- g_src.mq = mq_open(g_src.mqname, O_RDWR | O_CREAT, 0644, &m_attr);
- if (g_src.mq == NULL)
+ ret = file_mq_open(&g_src.mq, g_src.mqname,
+ O_RDWR | O_CREAT, 0644, &m_attr);
+ if (ret < 0)
{
auderr("ERROR: Could not allocate SRC message queue.\n");
- return -ENOMEM;
+ return ret;
}
#ifdef DUMP_DATA
@@ -562,8 +564,8 @@ int cxd56_src_enqueue(FAR struct ap_buffer_s *apb)
msg.msg_id = AUDIO_MSG_ENQUEUE;
msg.u.ptr = apb;
- ret = nxmq_send(g_src.mq, (FAR const char *)&msg,
- sizeof(msg), CONFIG_CXD56_MSG_PRIO);
+ ret = file_mq_send(&g_src.mq, (FAR const char *)&msg,
+ sizeof(msg), CONFIG_CXD56_MSG_PRIO);
if (ret != OK)
{
auderr("ERROR: SRC APB enqueue failed (%d)\n", ret);
@@ -589,8 +591,8 @@ int cxd56_src_stop(void)
msg.msg_id = AUDIO_MSG_STOP;
msg.u.data = 0;
- ret = nxmq_send(g_src.mq, (FAR const char *)&msg,
- sizeof(msg), CONFIG_CXD56_MSG_PRIO);
+ ret = file_mq_send(&g_src.mq, (FAR const char *)&msg,
+ sizeof(msg), CONFIG_CXD56_MSG_PRIO);
if (ret != OK)
{
auderr("ERROR: SRC stop failed (%d)\n", ret);
diff --git a/drivers/audio/vs1053.c b/drivers/audio/vs1053.c
index 5dcf1c3..131dcc6 100644
--- a/drivers/audio/vs1053.c
+++ b/drivers/audio/vs1053.c
@@ -120,7 +120,7 @@ struct vs1053_struct_s
struct dq_queue_s apbq; /* Our queue for enqueued buffers */
unsigned long spi_freq; /* Frequency to run the SPI bus at. */
unsigned long chip_freq; /* Current chip frequency */
- mqd_t mq; /* Message queue for receiving messages */
+ struct file mq; /* Message queue for receiving messages */
char mqname[16]; /* Our message queue name */
pthread_t threadid; /* ID of our thread */
sem_t apbq_sem; /* Audio Pipeline Buffer Queue sem access */
@@ -1276,8 +1276,8 @@ static int vs1053_dreq_isr(int irq, FAR void *context, FAR void *arg)
if (dev->running)
{
msg.msg_id = AUDIO_MSG_DATA_REQUEST;
- nxmq_send(dev->mq, (FAR const char *)&msg, sizeof(msg),
- CONFIG_VS1053_MSG_PRIO);
+ file_mq_send(&dev->mq, (FAR const char *)&msg, sizeof(msg),
+ CONFIG_VS1053_MSG_PRIO);
}
else
{
@@ -1341,7 +1341,7 @@ static void *vs1053_workerthread(pthread_addr_t pvarg)
/* Wait for messages from our message queue */
- size = nxmq_receive(dev->mq, (FAR char *)&msg, sizeof(msg), &prio);
+ size = file_mq_receive(&dev->mq, (FAR char *)&msg, sizeof(msg), &prio);
/* Handle the case when we return with no message */
@@ -1426,9 +1426,8 @@ static void *vs1053_workerthread(pthread_addr_t pvarg)
/* Close the message queue */
- mq_close(dev->mq);
- mq_unlink(dev->mqname);
- dev->mq = NULL;
+ file_mq_close(&dev->mq);
+ file_mq_unlink(dev->mqname);
/* Send an AUDIO_MSG_COMPLETE message to the client */
@@ -1493,13 +1492,14 @@ static int vs1053_start(FAR struct audio_lowerhalf_s *lower)
attr.mq_msgsize = sizeof(struct audio_msg_s);
attr.mq_curmsgs = 0;
attr.mq_flags = 0;
- dev->mq = mq_open(dev->mqname, O_RDWR | O_CREAT, 0644, &attr);
- if (dev->mq == NULL)
+ ret = file_mq_open(&dev->mq, dev->mqname,
+ O_RDWR | O_CREAT, 0644, &attr);
+ if (ret < 0)
{
/* Error creating message queue! */
auderr("ERROR: Couldn't allocate message queue\n");
- return -ENOMEM;
+ return ret;
}
/* Pop the first enqueued buffer */
@@ -1571,8 +1571,8 @@ static int vs1053_stop(FAR struct audio_lowerhalf_s *lower)
term_msg.msg_id = AUDIO_MSG_STOP;
term_msg.u.data = 0;
- nxmq_send(dev->mq, (FAR const char *)&term_msg, sizeof(term_msg),
- CONFIG_VS1053_MSG_PRIO);
+ file_mq_send(&dev->mq, (FAR const char *)&term_msg, sizeof(term_msg),
+ CONFIG_VS1053_MSG_PRIO);
/* Join the worker thread */
@@ -1683,12 +1683,12 @@ static int vs1053_enqueuebuffer(FAR struct audio_lowerhalf_s *lower,
/* Send a message indicating a new buffer enqueued */
- if (dev->mq != NULL)
+ if (dev->mq.f_inode != NULL)
{
term_msg.msg_id = AUDIO_MSG_ENQUEUE;
term_msg.u.data = 0;
- nxmq_send(dev->mq, (FAR const char *)&term_msg,
- sizeof(term_msg), CONFIG_VS1053_MSG_PRIO);
+ file_mq_send(&dev->mq, (FAR const char *)&term_msg,
+ sizeof(term_msg), CONFIG_VS1053_MSG_PRIO);
}
}
@@ -1875,21 +1875,15 @@ struct audio_lowerhalf_s *vs1053_initialize(FAR struct spi_dev_s *spi,
/* Allocate a VS1053 device structure */
- dev = (struct vs1053_struct_s *)kmm_malloc(sizeof(struct vs1053_struct_s));
+ dev = (struct vs1053_struct_s *)kmm_zalloc(sizeof(struct vs1053_struct_s));
if (dev)
{
/* Initialize the VS1053 device structure */
dev->lower.ops = &g_audioops;
- dev->lower.upper = NULL;
- dev->lower.priv = NULL;
dev->hw_lower = lower;
dev->spi_freq = CONFIG_VS1053_XTALI / 7;
dev->spi = spi;
- dev->mq = NULL;
- dev->busy = false;
- dev->threadid = 0;
- dev->running = false;
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
dev->volume = 250; /* 25% volume as default */
@@ -1898,10 +1892,6 @@ struct audio_lowerhalf_s *vs1053_initialize(FAR struct spi_dev_s *spi,
#endif
#endif
-#ifndef CONFIG_AUDIO_EXCLUDE_TONE
- dev->bass = 0;
- dev->treble = 0;
-#endif
nxsem_init(&dev->apbq_sem, 0, 1);
dq_init(&dev->apbq);
diff --git a/drivers/audio/wm8776.c b/drivers/audio/wm8776.c
index 8794965..53dadc1 100644
--- a/drivers/audio/wm8776.c
+++ b/drivers/audio/wm8776.c
@@ -572,11 +572,11 @@ static void wm8776_senddone(FAR struct i2s_dev_s *i2s,
*/
msg.msg_id = AUDIO_MSG_COMPLETE;
- ret = mq_send(priv->mq, (FAR const char *)&msg, sizeof(msg),
- CONFIG_WM8776_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *)&msg, sizeof(msg),
+ CONFIG_WM8776_MSG_PRIO);
if (ret < 0)
{
- auderr("ERROR: mq_send failed: %d\n", get_errno());
+ auderr("ERROR: file_mq_send failed: %d\n", get_errno());
}
}
@@ -756,8 +756,9 @@ static int wm8776_start(FAR struct audio_lowerhalf_s *dev)
attr.mq_curmsgs = 0;
attr.mq_flags = 0;
- priv->mq = mq_open(priv->mqname, O_RDWR | O_CREAT, 0644, &attr);
- if (priv->mq == NULL)
+ ret = file_mq_open(&priv->mq, priv->mqname,
+ O_RDWR | O_CREAT, 0644, &attr);
+ if (ret < 0)
{
/* Error creating message queue! */
@@ -819,8 +820,8 @@ static int wm8776_stop(FAR struct audio_lowerhalf_s *dev)
term_msg.msg_id = AUDIO_MSG_STOP;
term_msg.u.data = 0;
- mq_send(priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
- CONFIG_WM8776_MSG_PRIO);
+ file_mq_send(&priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
+ CONFIG_WM8776_MSG_PRIO);
/* Join the worker thread */
@@ -929,19 +930,19 @@ static int wm8776_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
*/
ret = OK;
- if (priv->mq != NULL)
+ if (priv->mq.f_inode != NULL)
{
term_msg.msg_id = AUDIO_MSG_ENQUEUE;
term_msg.u.data = 0;
- ret = mq_send(priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
- CONFIG_WM8776_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *)&term_msg,
+ sizeof(term_msg), CONFIG_WM8776_MSG_PRIO);
if (ret < 0)
{
int errcode = get_errno();
DEBUGASSERT(errcode > 0);
- auderr("ERROR: mq_send failed: %d\n", errcode);
+ auderr("ERROR: file_mq_send failed: %d\n", errcode);
UNUSED(errcode);
}
}
@@ -1225,7 +1226,8 @@ repeat:
/* Wait for messages from our message queue */
- msglen = mq_receive(priv->mq, (FAR char *)&msg, sizeof(msg), &prio);
+ msglen = file_mq_receive(&priv->mq, (FAR char *)&msg,
+ sizeof(msg), &prio);
/* Handle the case when we return with no message */
@@ -1279,7 +1281,7 @@ repeat:
break;
}
- mq_getattr(priv->mq, &attr);
+ file_mq_getattr(&priv->mq, &attr);
/* If there is a message in the queue, process it */
@@ -1319,9 +1321,8 @@ repeat:
/* Close the message queue */
- mq_close(priv->mq);
- mq_unlink(priv->mqname);
- priv->mq = NULL;
+ file_mq_close(&priv->mq);
+ file_mq_unlink(priv->mqname);
/* Send an AUDIO_MSG_COMPLETE message to the client */
diff --git a/drivers/audio/wm8776.h b/drivers/audio/wm8776.h
index 6fdf478..b4e178e 100644
--- a/drivers/audio/wm8776.h
+++ b/drivers/audio/wm8776.h
@@ -29,8 +29,8 @@
#include <nuttx/compiler.h>
#include <pthread.h>
-#include <mqueue.h>
+#include <nuttx/mqueue.h>
#include <nuttx/wqueue.h>
#include <nuttx/fs/ioctl.h>
@@ -81,7 +81,7 @@ struct wm8776_dev_s
FAR struct i2s_dev_s *i2s; /* I2S driver to use */
struct dq_queue_s pendq; /* Queue of pending buffers to be sent */
struct dq_queue_s doneq; /* Queue of sent buffers to be returned */
- mqd_t mq; /* Message queue for receiving messages */
+ struct file mq; /* Message queue for receiving messages */
char mqname[16]; /* Our message queue name */
pthread_t threadid; /* ID of our thread */
uint32_t bitrate; /* Actual programmed bit rate */
diff --git a/drivers/audio/wm8904.c b/drivers/audio/wm8904.c
index 1ddb4e1..bdd8dea 100644
--- a/drivers/audio/wm8904.c
+++ b/drivers/audio/wm8904.c
@@ -1406,11 +1406,11 @@ static void wm8904_senddone(FAR struct i2s_dev_s *i2s,
*/
msg.msg_id = AUDIO_MSG_COMPLETE;
- ret = nxmq_send(priv->mq, (FAR const char *)&msg, sizeof(msg),
- CONFIG_WM8904_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *)&msg, sizeof(msg),
+ CONFIG_WM8904_MSG_PRIO);
if (ret < 0)
{
- auderr("ERROR: nxmq_send failed: %d\n", ret);
+ auderr("ERROR: file_mq_send failed: %d\n", ret);
}
}
@@ -1612,13 +1612,14 @@ static int wm8904_start(FAR struct audio_lowerhalf_s *dev)
attr.mq_curmsgs = 0;
attr.mq_flags = 0;
- priv->mq = mq_open(priv->mqname, O_RDWR | O_CREAT, 0644, &attr);
- if (priv->mq == NULL)
+ ret = file_mq_open(&priv->mq, priv->mqname,
+ O_RDWR | O_CREAT, 0644, &attr);
+ if (ret < 0)
{
/* Error creating message queue! */
auderr("ERROR: Couldn't allocate message queue\n");
- return -ENOMEM;
+ return ret;
}
/* Join any old worker thread we had created to prevent a memory leak */
@@ -1675,8 +1676,8 @@ static int wm8904_stop(FAR struct audio_lowerhalf_s *dev)
term_msg.msg_id = AUDIO_MSG_STOP;
term_msg.u.data = 0;
- nxmq_send(priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
- CONFIG_WM8904_MSG_PRIO);
+ file_mq_send(&priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
+ CONFIG_WM8904_MSG_PRIO);
/* Join the worker thread */
@@ -1794,16 +1795,16 @@ static int wm8904_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
*/
ret = OK;
- if (priv->mq != NULL)
+ if (priv->mq.f_inode != NULL)
{
term_msg.msg_id = AUDIO_MSG_ENQUEUE;
term_msg.u.data = 0;
- ret = nxmq_send(priv->mq, (FAR const char *)&term_msg,
- sizeof(term_msg), CONFIG_WM8904_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *)&term_msg,
+ sizeof(term_msg), CONFIG_WM8904_MSG_PRIO);
if (ret < 0)
{
- auderr("ERROR: nxmq_send failed: %d\n", ret);
+ auderr("ERROR: file_mq_send failed: %d\n", ret);
}
}
@@ -2120,7 +2121,8 @@ static void *wm8904_workerthread(pthread_addr_t pvarg)
/* Wait for messages from our message queue */
- msglen = nxmq_receive(priv->mq, (FAR char *)&msg, sizeof(msg), &prio);
+ msglen = file_mq_receive(&priv->mq, (FAR char *)&msg,
+ sizeof(msg), &prio);
/* Handle the case when we return with no message */
@@ -2205,9 +2207,8 @@ static void *wm8904_workerthread(pthread_addr_t pvarg)
/* Close the message queue */
- mq_close(priv->mq);
- mq_unlink(priv->mqname);
- priv->mq = NULL;
+ file_mq_close(&priv->mq);
+ file_mq_unlink(priv->mqname);
/* Send an AUDIO_MSG_COMPLETE message to the client */
diff --git a/drivers/audio/wm8904.h b/drivers/audio/wm8904.h
index 1fe6f26..596df4b 100644
--- a/drivers/audio/wm8904.h
+++ b/drivers/audio/wm8904.h
@@ -1101,7 +1101,7 @@ struct wm8904_dev_s
FAR struct i2s_dev_s *i2s; /* I2S driver to use */
struct dq_queue_s pendq; /* Queue of pending buffers to be sent */
struct dq_queue_s doneq; /* Queue of sent buffers to be returned */
- mqd_t mq; /* Message queue for receiving messages */
+ struct file mq; /* Message queue for receiving messages */
char mqname[16]; /* Our message queue name */
pthread_t threadid; /* ID of our thread */
uint32_t bitrate; /* Actual programmed bit rate */
diff --git a/drivers/audio/wm8994.c b/drivers/audio/wm8994.c
index 1a95723..9e9c0aa 100644
--- a/drivers/audio/wm8994.c
+++ b/drivers/audio/wm8994.c
@@ -578,11 +578,11 @@ static void wm8994_senddone(FAR struct i2s_dev_s *i2s,
*/
msg.msg_id = AUDIO_MSG_COMPLETE;
- ret = nxmq_send(priv->mq, (FAR const char *)&msg, sizeof(msg),
- CONFIG_WM8994_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *)&msg, sizeof(msg),
+ CONFIG_WM8994_MSG_PRIO);
if (ret < 0)
{
- auderr("ERROR: nxmq_send failed: %d\n", ret);
+ auderr("ERROR: file_mq_send failed: %d\n", ret);
}
}
@@ -775,13 +775,13 @@ static int wm8994_start(FAR struct audio_lowerhalf_s *dev)
attr.mq_curmsgs = 0;
attr.mq_flags = 0;
- priv->mq = mq_open(priv->mqname, O_RDWR | O_CREAT, 0644, &attr);
- if (priv->mq == NULL)
+ ret = file_mq_open(&priv->mq, priv->mqname, O_RDWR | O_CREAT, 0644, &attr);
+ if (ret < 0)
{
/* Error creating message queue! */
auderr("ERROR: Couldn't allocate message queue\n");
- return -ENOMEM;
+ return ret;
}
/* Join any old worker thread we had created to prevent a memory leak */
@@ -837,8 +837,8 @@ static int wm8994_stop(FAR struct audio_lowerhalf_s *dev)
term_msg.msg_id = AUDIO_MSG_STOP;
term_msg.u.data = 0;
- (void)nxmq_send(priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
- CONFIG_WM8994_MSG_PRIO);
+ (void)file_mq_send(&priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
+ CONFIG_WM8994_MSG_PRIO);
/* Join the worker thread */
@@ -945,16 +945,16 @@ static int wm8994_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
*/
ret = OK;
- if (priv->mq != NULL)
+ if (priv->mq.f_inode != NULL)
{
term_msg.msg_id = AUDIO_MSG_ENQUEUE;
term_msg.u.data = 0;
- ret = nxmq_send(priv->mq, (FAR const char *)&term_msg,
- sizeof(term_msg), CONFIG_WM8994_MSG_PRIO);
+ ret = file_mq_send(&priv->mq, (FAR const char *)&term_msg,
+ sizeof(term_msg), CONFIG_WM8994_MSG_PRIO);
if (ret < 0)
{
- auderr("ERROR: nxmq_send failed: %d\n", ret);
+ auderr("ERROR: file_mq_send failed: %d\n", ret);
}
}
@@ -1256,7 +1256,7 @@ static void *wm8994_workerthread(pthread_addr_t pvarg)
/* Wait for messages from our message queue */
- msglen = nxmq_receive(priv->mq, (FAR char *)&msg, sizeof(msg), &prio);
+ msglen = file_mq_receive(&priv->mq, (FAR char *)&msg, sizeof(msg), &prio);
/* Handle the case when we return with no message */
@@ -1341,9 +1341,8 @@ static void *wm8994_workerthread(pthread_addr_t pvarg)
/* Close the message queue */
- mq_close(priv->mq);
- mq_unlink(priv->mqname);
- priv->mq = NULL;
+ file_mq_close(&priv->mq);
+ file_mq_unlink(priv->mqname);
/* Send an AUDIO_MSG_COMPLETE message to the client */
diff --git a/drivers/audio/wm8994.h b/drivers/audio/wm8994.h
index fc9539f..25c9289 100644
--- a/drivers/audio/wm8994.h
+++ b/drivers/audio/wm8994.h
@@ -29,8 +29,8 @@
#include <nuttx/compiler.h>
#include <pthread.h>
-#include <mqueue.h>
+#include <nuttx/mqueue.h>
#include <nuttx/wqueue.h>
#include <nuttx/fs/ioctl.h>
@@ -1573,7 +1573,7 @@ struct wm8994_dev_s
FAR struct i2s_dev_s *i2s; /* I2S driver to use */
struct dq_queue_s pendq; /* Queue of pending buffers to be sent */
struct dq_queue_s doneq; /* Queue of sent buffers to be returned */
- mqd_t mq; /* Message queue for receiving messages */
+ struct file mq; /* Message queue for receiving messages */
char mqname[16]; /* Our message queue name */
pthread_t threadid; /* ID of our thread */
uint32_t bitrate; /* Actual programmed bit rate */
diff --git a/drivers/lcd/ssd1306_base.c b/drivers/lcd/ssd1306_base.c
index 9f8360c..463bfa6 100644
--- a/drivers/lcd/ssd1306_base.c
+++ b/drivers/lcd/ssd1306_base.c
@@ -138,6 +138,7 @@
#include <nuttx/spi/spi.h>
#include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/ssd1306.h>
+#include <nuttx/signal.h>
#include <arch/irq.h>
diff --git a/drivers/sensors/mpu60x0.c b/drivers/sensors/mpu60x0.c
index 72ade27..35d622f 100644
--- a/drivers/sensors/mpu60x0.c
+++ b/drivers/sensors/mpu60x0.c
@@ -51,6 +51,7 @@
#include <string.h>
#include <limits.h>
#include <nuttx/mutex.h>
+#include <nuttx/signal.h>
#include <nuttx/compiler.h>
#include <nuttx/kmalloc.h>
diff --git a/fs/mqueue/mq_close.c b/fs/mqueue/mq_close.c
index 185f892..2affeda 100644
--- a/fs/mqueue/mq_close.c
+++ b/fs/mqueue/mq_close.c
@@ -41,6 +41,34 @@
****************************************************************************/
/****************************************************************************
+ * Name: file_mq_close
+ *
+ * Description:
+ * This is an internal OS interface. It is functionally equivalent to
+ * mq_close() except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_close() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mq - Message queue descriptor.
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ *
+ ****************************************************************************/
+
+int file_mq_close(FAR struct file *mq)
+{
+ return file_close(mq);
+}
+
+/****************************************************************************
* Name: nxmq_close
*
* Description:
diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c
index 949c2b7..ab703df 100644
--- a/fs/mqueue/mq_open.c
+++ b/fs/mqueue/mq_open.c
@@ -84,61 +84,37 @@ static int nxmq_file_close(FAR struct file *filep)
return 0;
}
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxmq_open
- *
- * Description:
- * This function establish a connection between a named message queue and
- * the calling task. This is an internal OS interface. It is functionally
- * equivalent to mq_open() except that:
- *
- * - It is not a cancellation point, and
- * - It does not modify the errno value.
- *
- * See comments with mq_open() for a more complete description of the
- * behavior of this function
- *
- * Input Parameters:
- * mq_name - Name of the queue to open
- * oflags - open flags
- * Optional parameters. When the O_CREAT flag is specified, two optional
- * parameters are expected:
- *
- * 1. mode_t mode (ignored), and
- * 2. struct mq_attr *attr. The mq_maxmsg attribute
- * is used at the time that the message queue is
- * created to determine the maximum number of
- * messages that may be placed in the message queue.
- *
- * Returned Value:
- * This is an internal OS interface and should not be used by applications.
- * It follows the NuttX internal error return policy: Zero (OK) is
- * returned on success, mqdes point to the new message queue descriptor.
- * A negated errno value is returned on failure.
- *
- ****************************************************************************/
-
-int nxmq_open(FAR const char *mq_name, int oflags, mode_t mode,
- FAR struct mq_attr *attr, FAR mqd_t *mqdes)
+static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name,
+ int oflags, va_list ap, int *created)
{
FAR struct inode *inode;
FAR struct mqueue_inode_s *msgq;
+ FAR struct mq_attr *attr = NULL;
struct inode_search_s desc;
char fullpath[MAX_MQUEUE_PATH];
+ mode_t mode = 0;
int ret;
/* Make sure that a non-NULL name is supplied */
- if (mq_name == NULL || *mq_name == '\0')
+ if (!mq || !mq_name || *mq_name == '\0')
{
ret = -EINVAL;
goto errout;
}
+ /* Were we asked to create it? */
+
+ if ((oflags & O_CREAT) != 0)
+ {
+ /* We have to extract the additional
+ * parameters from the variable argument list.
+ */
+
+ mode = va_arg(ap, mode_t);
+ attr = va_arg(ap, FAR struct mq_attr *);
+ }
+
/* Skip over any leading '/'. All message queue paths are relative to
* CONFIG_FS_MQUEUE_MPATH.
*/
@@ -195,11 +171,14 @@ int nxmq_open(FAR const char *mq_name, int oflags, mode_t mode,
/* Associate the inode with a file structure */
- *mqdes = files_allocate(inode, oflags, 0, 0);
- if (*mqdes < 0)
+ mq->f_oflags = oflags;
+ mq->f_pos = 0;
+ mq->f_inode = inode;
+ mq->f_priv = NULL;
+
+ if (created)
{
- ret = *mqdes;
- goto errout_with_msgq;
+ *created = 1;
}
}
else
@@ -243,12 +222,10 @@ int nxmq_open(FAR const char *mq_name, int oflags, mode_t mode,
/* Associate the inode with a file structure */
- *mqdes = files_allocate(inode, oflags, 0, 0);
- if (*mqdes < 0)
- {
- ret = *mqdes;
- goto errout_with_msgq;
- }
+ mq->f_oflags = oflags;
+ mq->f_pos = 0;
+ mq->f_inode = inode;
+ mq->f_priv = NULL;
INODE_SET_MQUEUE(inode);
inode->u.i_ops = &g_nxmq_fileops;
@@ -258,15 +235,17 @@ int nxmq_open(FAR const char *mq_name, int oflags, mode_t mode,
/* Set the initial reference count on this inode to one */
inode->i_crefs = 1;
+
+ if (created)
+ {
+ *created = 0;
+ }
}
RELEASE_SEARCH(&desc);
sched_unlock();
return OK;
-errout_with_msgq:
- nxmq_free_msgq(msgq);
-
errout_with_inode:
inode_release(inode);
@@ -278,6 +257,129 @@ errout:
return ret;
}
+static mqd_t nxmq_vopen(FAR const char *mq_name, int oflags, va_list ap)
+{
+ struct file mq;
+ int created;
+ int ret;
+
+ ret = file_mq_vopen(&mq, mq_name, oflags, ap, &created);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ ret = files_allocate(mq.f_inode, mq.f_oflags, mq.f_pos, 0);
+ if (ret < 0)
+ {
+ file_mq_close(&mq);
+
+ if (created)
+ {
+ file_mq_unlink(mq_name);
+ }
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: file_mq_open
+ *
+ * Description:
+ * This function establish a connection between a named message queue and
+ * the calling task. This is an internal OS interface. It is functionally
+ * equivalent to mq_open() except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_open() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mq_name - Name of the queue to open
+ * oflags - open flags
+ * Optional parameters. When the O_CREAT flag is specified, two optional
+ * parameters are expected:
+ *
+ * 1. mode_t mode (ignored), and
+ * 2. struct mq_attr *attr. The mq_maxmsg attribute
+ * is used at the time that the message queue is
+ * created to determine the maximum number of
+ * messages that may be placed in the message queue.
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success, mqdes point to the new message queue descriptor.
+ * A negated errno value is returned on failure.
+ *
+ ****************************************************************************/
+
+int file_mq_open(FAR struct file *mq,
+ FAR const char *mq_name, int oflags, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, oflags);
+ ret = file_mq_vopen(mq, mq_name, oflags, ap, NULL);
+ va_end(ap);
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: nxmq_open
+ *
+ * Description:
+ * This function establish a connection between a named message queue and
+ * the calling task. This is an internal OS interface. It is functionally
+ * equivalent to mq_open() except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_open() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mq_name - Name of the queue to open
+ * oflags - open flags
+ * Optional parameters. When the O_CREAT flag is specified, two optional
+ * parameters are expected:
+ *
+ * 1. mode_t mode (ignored), and
+ * 2. struct mq_attr *attr. The mq_maxmsg attribute
+ * is used at the time that the message queue is
+ * created to determine the maximum number of
+ * messages that may be placed in the message queue.
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success, mqdes point to the new message queue descriptor.
+ * A negated errno value is returned on failure.
+ *
+ ****************************************************************************/
+
+mqd_t nxmq_open(FAR const char *mq_name, int oflags, ...)
+{
+ va_list ap;
+ mqd_t ret;
+
+ va_start(ap, oflags);
+ ret = nxmq_vopen(mq_name, oflags, ap);
+ va_end(ap);
+
+ return ret;
+}
+
/****************************************************************************
* Name: mq_open
*
@@ -309,32 +411,17 @@ errout:
mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
{
- FAR struct mq_attr *attr = NULL;
- mode_t mode = 0;
- mqd_t mqdes;
va_list ap;
- int ret;
-
- /* Were we asked to create it? */
+ mqd_t ret;
- if ((oflags & O_CREAT) != 0)
- {
- /* We have to extract the additional
- * parameters from the variable argument list.
- */
-
- va_start(ap, oflags);
- mode = va_arg(ap, mode_t);
- attr = va_arg(ap, FAR struct mq_attr *);
- va_end(ap);
- }
-
- ret = nxmq_open(mq_name, oflags, mode, attr, &mqdes);
+ va_start(ap, oflags);
+ ret = nxmq_vopen(mq_name, oflags, ap);
+ va_end(ap);
if (ret < 0)
{
set_errno(-ret);
- mqdes = (mqd_t)ERROR;
+ return ERROR;
}
- return mqdes;
+ return ret;
}
diff --git a/fs/mqueue/mq_unlink.c b/fs/mqueue/mq_unlink.c
index 19da8f6..679b47e 100644
--- a/fs/mqueue/mq_unlink.c
+++ b/fs/mqueue/mq_unlink.c
@@ -72,7 +72,7 @@ static void mq_inode_release(FAR struct inode *inode)
****************************************************************************/
/****************************************************************************
- * Name: nxmq_unlink
+ * Name: file_mq_unlink
*
* Description:
* This is an internal OS interface. It is functionally equivalent to
@@ -94,7 +94,7 @@ static void mq_inode_release(FAR struct inode *inode)
*
****************************************************************************/
-int nxmq_unlink(FAR const char *mq_name)
+int file_mq_unlink(FAR const char *mq_name)
{
FAR struct inode *inode;
struct inode_search_s desc;
@@ -188,6 +188,34 @@ errout_with_search:
}
/****************************************************************************
+ * Name: nxmq_unlink
+ *
+ * Description:
+ * This is an internal OS interface. It is functionally equivalent to
+ * mq_unlink() except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_unlink() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mq_name - Name of the message queue
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ *
+ ****************************************************************************/
+
+int nxmq_unlink(FAR const char *mq_name)
+{
+ return file_mq_unlink(mq_name);
+}
+
+/****************************************************************************
* Name: mq_unlink
*
* Description:
diff --git a/include/nuttx/mqueue.h b/include/nuttx/mqueue.h
index 57ba019..14abdeb 100644
--- a/include/nuttx/mqueue.h
+++ b/include/nuttx/mqueue.h
@@ -43,6 +43,7 @@
#include <nuttx/config.h>
#include <nuttx/compiler.h>
+#include <nuttx/fs/fs.h>
#include <nuttx/signal.h>
#include <sys/types.h>
@@ -171,8 +172,7 @@ struct task_group_s; /* Forward reference */
*
****************************************************************************/
-int nxmq_open(FAR const char *mq_name, int oflags, mode_t mode,
- FAR struct mq_attr *attr, FAR mqd_t *mqdes);
+mqd_t nxmq_open(FAR const char *mq_name, int oflags, ...);
/****************************************************************************
* Name: nxmq_close
@@ -410,6 +410,287 @@ void nxmq_free_msgq(FAR struct mqueue_inode_s *msgq);
FAR struct mqueue_inode_s *nxmq_alloc_msgq(mode_t mode,
FAR struct mq_attr *attr);
+/****************************************************************************
+ * Name: file_mq_open
+ *
+ * Description:
+ * This function establish a connection between a named message queue and
+ * the calling task. This is an internal OS interface. It is functionally
+ * equivalent to mq_open() except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_open() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mq_name - Name of the queue to open
+ * oflags - open flags
+ * Optional parameters. When the O_CREAT flag is specified, two optional
+ * parameters are expected:
+ *
+ * 1. mode_t mode (ignored), and
+ * 2. struct mq_attr *attr. The mq_maxmsg attribute
+ * is used at the time that the message queue is
+ * created to determine the maximum number of
+ * messages that may be placed in the message queue.
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * NOT NULL Message queue descriptor, NULL failed.
+ *
+ ****************************************************************************/
+
+int file_mq_open(FAR struct file *mq,
+ FAR const char *mq_name, int oflags, ...);
+
+/****************************************************************************
+ * Name: file_mq_close
+ *
+ * Description:
+ * This is an internal OS interface. It is functionally equivalent to
+ * mq_close() except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_close() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mq - Message queue descriptor.
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ *
+ ****************************************************************************/
+
+int file_mq_close(FAR struct file *mq);
+
+/****************************************************************************
+ * Name: file_mq_unlink
+ *
+ * Description:
+ * This is an internal OS interface. It is functionally equivalent to
+ * mq_unlink() except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_unlink() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mq_name - Name of the message queue
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ *
+ ****************************************************************************/
+
+int file_mq_unlink(FAR const char *mq_name);
+
+/****************************************************************************
+ * Name: file_mq_send
+ *
+ * Description:
+ * This function adds the specified message (msg) to the message queue
+ * (mq). This is an internal OS interface. It is functionally
+ * equivalent to mq_send() except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_send() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mq - Message queue descriptor
+ * msg - Message to send
+ * msglen - The length of the message in bytes
+ * prio - The priority of the message
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ * (see mq_send() for the list list valid return values).
+ *
+ ****************************************************************************/
+
+int file_mq_send(FAR struct file *mq, FAR const char *msg, size_t msglen,
+ unsigned int prio);
+
+/****************************************************************************
+ * Name: file_mq_timedsend
+ *
+ * Description:
+ * This function adds the specified message (msg) to the message queue
+ * (mq). file_mq_timedsend() behaves just like mq_send(), except that if
+ * the queue is full and the O_NONBLOCK flag is not enabled for the
+ * message queue description, then abstime points to a structure which
+ * specifies a ceiling on the time for which the call will block.
+ *
+ * file_mq_timedsend() is functionally equivalent to mq_timedsend() except
+ * that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_timedsend() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mq - Message queue descriptor
+ * msg - Message to send
+ * msglen - The length of the message in bytes
+ * prio - The priority of the message
+ * abstime - the absolute time to wait until a timeout is decleared
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ * (see mq_timedsend() for the list list valid return values).
+ *
+ * EAGAIN The queue was empty, and the O_NONBLOCK flag was set for the
+ * message queue description referred to by mq.
+ * EINVAL Either msg or mq is NULL or the value of prio is invalid.
+ * EPERM Message queue opened not opened for writing.
+ * EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the
+ * message queue.
+ * EINTR The call was interrupted by a signal handler.
+ *
+ ****************************************************************************/
+
+int file_mq_timedsend(FAR struct file *mq, FAR const char *msg,
+ size_t msglen, unsigned int prio,
+ FAR const struct timespec *abstime);
+
+/****************************************************************************
+ * Name: file_mq_receive
+ *
+ * Description:
+ * This function receives the oldest of the highest priority messages
+ * from the message queue specified by "mq." This is an internal OS
+ * interface. It is functionally equivalent to mq_receive except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_receive() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mq - Message Queue Descriptor
+ * msg - Buffer to receive the message
+ * msglen - Size of the buffer in bytes
+ * prio - If not NULL, the location to store message priority.
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ * (see mq_receive() for the list list valid return values).
+ *
+ ****************************************************************************/
+
+ssize_t file_mq_receive(FAR struct file *mq, FAR char *msg, size_t msglen,
+ FAR unsigned int *prio);
+
+/****************************************************************************
+ * Name: file_mq_timedreceive
+ *
+ * Description:
+ * This function receives the oldest of the highest priority messages from
+ * the message queue specified by "mq." If the message queue is empty
+ * and O_NONBLOCK was not set, file_mq_timedreceive() will block until a
+ * message is added to the message queue (or until a timeout occurs).
+ *
+ * file_mq_timedreceive() is an internal OS interface. It is functionally
+ * equivalent to mq_timedreceive() except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_timedreceive() for a more complete description of
+ * the behavior of this function
+ *
+ * Input Parameters:
+ * mq - Message Queue Descriptor
+ * msg - Buffer to receive the message
+ * msglen - Size of the buffer in bytes
+ * prio - If not NULL, the location to store message priority.
+ * abstime - the absolute time to wait until a timeout is declared.
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ * (see mq_timedreceive() for the list list valid return values).
+ *
+ ****************************************************************************/
+
+ssize_t file_mq_timedreceive(FAR struct file *mq, FAR char *msg,
+ size_t msglen, FAR unsigned int *prio,
+ FAR const struct timespec *abstime);
+
+/****************************************************************************
+ * Name: file_mq_setattr
+ *
+ * Description:
+ * This function sets the attributes associated with the
+ * specified message queue "mq". Only the "O_NONBLOCK"
+ * bit of the "mq_flags" can be changed.
+ *
+ * If "oldstat" is non-null, mq_setattr() will store the
+ * previous message queue attributes at that location (just
+ * as would have been returned by file_mq_getattr()).
+ *
+ * Input Parameters:
+ * mqdes - Message queue descriptor
+ * mq_stat - New attributes
+ * oldstate - Old attributes
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+int file_mq_setattr(FAR struct file *mq, FAR const struct mq_attr *mq_stat,
+ FAR struct mq_attr *oldstat);
+
+/****************************************************************************
+ * Name: file_mq_getattr
+ *
+ * Description:
+ * This functions gets status information and attributes
+ * associated with the specified message queue.
+ *
+ * Input Parameters:
+ * mq - Message queue descriptor
+ * mq_stat - Buffer in which to return attributes
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+int file_mq_getattr(FAR struct file *mq, FAR struct mq_attr *mq_stat);
+
#undef EXTERN
#ifdef __cplusplus
}
diff --git a/sched/mqueue/mq_getattr.c b/sched/mqueue/mq_getattr.c
index b839749..d5ad129 100644
--- a/sched/mqueue/mq_getattr.c
+++ b/sched/mqueue/mq_getattr.c
@@ -24,6 +24,7 @@
#include <nuttx/config.h>
+#include <errno.h>
#include <mqueue.h>
#include <nuttx/fs/fs.h>
@@ -34,6 +35,52 @@
****************************************************************************/
/****************************************************************************
+ * Name: file_mq_getattr
+ *
+ * Description:
+ * This functions gets status information and attributes
+ * associated with the specified message queue.
+ *
+ * Input Parameters:
+ * mq - Message queue descriptor
+ * mq_stat - Buffer in which to return attributes
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+int file_mq_getattr(FAR struct file *mq, FAR struct mq_attr *mq_stat)
+{
+ FAR struct mqueue_inode_s *msgq;
+ FAR struct inode *inode;
+
+ if (!mq || !mq_stat)
+ {
+ return -EINVAL;
+ }
+
+ inode = mq->f_inode;
+ if (!inode)
+ {
+ return -EBADF;
+ }
+
+ msgq = inode->i_private;
+
+ mq_stat->mq_maxmsg = msgq->maxmsgs;
+ mq_stat->mq_msgsize = msgq->maxmsgsize;
+ mq_stat->mq_flags = mq->f_oflags;
+ mq_stat->mq_curmsgs = msgq->nmsgs;
+
+ return 0;
+}
+
+/****************************************************************************
* Name: mq_getattr
*
* Description:
@@ -53,31 +100,22 @@
int mq_getattr(mqd_t mqdes, struct mq_attr *mq_stat)
{
- FAR struct mqueue_inode_s *msgq;
FAR struct file *filep;
- FAR struct inode *inode;
int ret;
- if (!mq_stat)
+ ret = fs_getfilep(mqdes, &filep);
+ if (ret < 0)
{
- set_errno(EINVAL);
+ set_errno(-ret);
return ERROR;
}
- ret = fs_getfilep(mqdes, &filep);
+ ret = file_mq_getattr(filep, mq_stat);
if (ret < 0)
{
set_errno(-ret);
return ERROR;
}
- inode = filep->f_inode;
- msgq = inode->i_private;
-
- mq_stat->mq_maxmsg = msgq->maxmsgs;
- mq_stat->mq_msgsize = msgq->maxmsgsize;
- mq_stat->mq_flags = filep->f_oflags;
- mq_stat->mq_curmsgs = msgq->nmsgs;
-
return OK;
}
diff --git a/sched/mqueue/mq_receive.c b/sched/mqueue/mq_receive.c
index 86efde1..7661dc3 100644
--- a/sched/mqueue/mq_receive.c
+++ b/sched/mqueue/mq_receive.c
@@ -42,11 +42,11 @@
****************************************************************************/
/****************************************************************************
- * Name: nxmq_receive
+ * Name: file_mq_receive
*
* Description:
* This function receives the oldest of the highest priority messages
- * from the message queue specified by "mqdes." This is an internal OS
+ * from the message queue specified by "mq." This is an internal OS
* interface. It is functionally equivalent to mq_receive except that:
*
* - It is not a cancellation point, and
@@ -56,7 +56,7 @@
* behavior of this function
*
* Input Parameters:
- * mqdes - Message Queue Descriptor
+ * mq - Message Queue Descriptor
* msg - Buffer to receive the message
* msglen - Size of the buffer in bytes
* prio - If not NULL, the location to store message priority.
@@ -69,26 +69,22 @@
*
****************************************************************************/
-ssize_t nxmq_receive(mqd_t mqdes, FAR char *msg, size_t msglen,
- FAR unsigned int *prio)
+ssize_t file_mq_receive(FAR struct file *mq, FAR char *msg, size_t msglen,
+ FAR unsigned int *prio)
{
+ FAR struct inode *inode = mq->f_inode;
FAR struct mqueue_inode_s *msgq;
FAR struct mqueue_msg_s *mqmsg;
- FAR struct file *filep;
- FAR struct inode *inode;
irqstate_t flags;
ssize_t ret;
- /* Convert fd to msgq */
-
- ret = fs_getfilep(mqdes, &filep);
- if (ret < 0)
+ inode = mq->f_inode;
+ if (!inode)
{
- return ret;
+ return -EBADF;
}
- inode = filep->f_inode;
- msgq = inode->i_private;
+ msgq = inode->i_private;
DEBUGASSERT(up_interrupt_context() == false);
@@ -96,7 +92,7 @@ ssize_t nxmq_receive(mqd_t mqdes, FAR char *msg, size_t msglen,
* errno appropriately.
*/
- ret = nxmq_verify_receive(msgq, filep->f_oflags, msg, msglen);
+ ret = nxmq_verify_receive(msgq, mq->f_oflags, msg, msglen);
if (ret < 0)
{
return ret;
@@ -119,13 +115,13 @@ ssize_t nxmq_receive(mqd_t mqdes, FAR char *msg, size_t msglen,
/* Get the message from the message queue */
- ret = nxmq_wait_receive(msgq, filep->f_oflags, &mqmsg);
+ ret = nxmq_wait_receive(msgq, mq->f_oflags, &mqmsg);
leave_critical_section(flags);
/* Check if we got a message from the message queue. We might
* not have a message if:
*
- * - The message queue is empty and O_NONBLOCK is set in the filep
+ * - The message queue is empty and O_NONBLOCK is set in the mq
* - The wait was interrupted by a signal
*/
@@ -140,6 +136,49 @@ ssize_t nxmq_receive(mqd_t mqdes, FAR char *msg, size_t msglen,
}
/****************************************************************************
+ * Name: nxmq_receive
+ *
+ * Description:
+ * This function receives the oldest of the highest priority messages
+ * from the message queue specified by "mqdes." This is an internal OS
+ * interface. It is functionally equivalent to mq_receive except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_receive() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mqdes - Message Queue Descriptor
+ * msg - Buffer to receive the message
+ * msglen - Size of the buffer in bytes
+ * prio - If not NULL, the location to store message priority.
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ * (see mq_receive() for the list list valid return values).
+ *
+ ****************************************************************************/
+
+ssize_t nxmq_receive(mqd_t mqdes, FAR char *msg, size_t msglen,
+ FAR unsigned int *prio)
+{
+ FAR struct file *filep;
+ int ret;
+
+ ret = fs_getfilep(mqdes, &filep);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ return file_mq_receive(filep, msg, msglen, prio);
+}
+
+/****************************************************************************
* Name: mq_receive
*
* Description:
diff --git a/sched/mqueue/mq_send.c b/sched/mqueue/mq_send.c
index 9811c81..d65c09a 100644
--- a/sched/mqueue/mq_send.c
+++ b/sched/mqueue/mq_send.c
@@ -40,11 +40,11 @@
****************************************************************************/
/****************************************************************************
- * Name: nxmq_send
+ * Name: file_mq_send
*
* Description:
* This function adds the specified message (msg) to the message queue
- * (mqdes). This is an internal OS interface. It is functionally
+ * (mq). This is an internal OS interface. It is functionally
* equivalent to mq_send() except that:
*
* - It is not a cancellation point, and
@@ -54,7 +54,7 @@
* behavior of this function
*
* Input Parameters:
- * mqdes - Message queue descriptor
+ * mq - Message queue descriptor
* msg - Message to send
* msglen - The length of the message in bytes
* prio - The priority of the message
@@ -67,32 +67,28 @@
*
****************************************************************************/
-int nxmq_send(mqd_t mqdes, FAR const char *msg, size_t msglen,
- unsigned int prio)
+int file_mq_send(FAR struct file *mq, FAR const char *msg, size_t msglen,
+ unsigned int prio)
{
FAR struct mqueue_msg_s *mqmsg = NULL;
+ FAR struct inode *inode = mq->f_inode;
FAR struct mqueue_inode_s *msgq;
- FAR struct file *filep;
- FAR struct inode *inode;
irqstate_t flags;
int ret;
- /* Convert fd to msgq */
-
- ret = fs_getfilep(mqdes, &filep);
- if (ret < 0)
+ inode = mq->f_inode;
+ if (!inode)
{
- return ret;
+ return -EBADF;
}
- inode = filep->f_inode;
- msgq = inode->i_private;
+ msgq = inode->i_private;
/* Verify the input parameters -- setting errno appropriately
* on any failures to verify.
*/
- ret = nxmq_verify_send(msgq, filep->f_oflags, msg, msglen, prio);
+ ret = nxmq_verify_send(msgq, mq->f_oflags, msg, msglen, prio);
if (ret < 0)
{
return ret;
@@ -123,7 +119,7 @@ int nxmq_send(mqd_t mqdes, FAR const char *msg, size_t msglen,
* available in the message queue.
*/
- ret = nxmq_wait_send(msgq, filep->f_oflags);
+ ret = nxmq_wait_send(msgq, mq->f_oflags);
}
}
@@ -165,6 +161,49 @@ int nxmq_send(mqd_t mqdes, FAR const char *msg, size_t msglen,
}
/****************************************************************************
+ * Name: nxmq_send
+ *
+ * Description:
+ * This function adds the specified message (msg) to the message queue
+ * (mqdes). This is an internal OS interface. It is functionally
+ * equivalent to mq_send() except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_send() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mqdes - Message queue descriptor
+ * msg - Message to send
+ * msglen - The length of the message in bytes
+ * prio - The priority of the message
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ * (see mq_send() for the list list valid return values).
+ *
+ ****************************************************************************/
+
+int nxmq_send(mqd_t mqdes, FAR const char *msg, size_t msglen,
+ unsigned int prio)
+{
+ FAR struct file *filep;
+ int ret;
+
+ ret = fs_getfilep(mqdes, &filep);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ return file_mq_send(filep, msg, msglen, prio);
+}
+
+/****************************************************************************
* Name: mq_send
*
* Description:
diff --git a/sched/mqueue/mq_setattr.c b/sched/mqueue/mq_setattr.c
index 24c5cba..9ae3636 100644
--- a/sched/mqueue/mq_setattr.c
+++ b/sched/mqueue/mq_setattr.c
@@ -24,6 +24,7 @@
#include <nuttx/config.h>
+#include <errno.h>
#include <fcntl.h> /* O_NONBLOCK */
#include <mqueue.h>
@@ -35,6 +36,55 @@
****************************************************************************/
/****************************************************************************
+ * Name: file_mq_setattr
+ *
+ * Description:
+ * This function sets the attributes associated with the
+ * specified message queue "mq". Only the "O_NONBLOCK"
+ * bit of the "mq_flags" can be changed.
+ *
+ * If "oldstat" is non-null, mq_setattr() will store the
+ * previous message queue attributes at that location (just
+ * as would have been returned by file_mq_getattr()).
+ *
+ * Input Parameters:
+ * mq - Message queue descriptor
+ * mq_stat - New attributes
+ * oldstate - Old attributes
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+int file_mq_setattr(FAR struct file *mq, FAR const struct mq_attr *mq_stat,
+ FAR struct mq_attr *oldstat)
+{
+ if (!mq || !mq_stat)
+ {
+ return -EINVAL;
+ }
+
+ /* Return the attributes if so requested */
+
+ if (oldstat)
+ {
+ file_mq_getattr(mq, oldstat);
+ }
+
+ /* Set the new value of the O_NONBLOCK flag. */
+
+ mq->f_oflags = ((mq_stat->mq_flags & O_NONBLOCK) |
+ (mq->f_oflags & (~O_NONBLOCK)));
+
+ return 0;
+}
+
+/****************************************************************************
* Name: mq_setattr
*
* Description:
@@ -65,12 +115,6 @@ int mq_setattr(mqd_t mqdes, const struct mq_attr *mq_stat,
FAR struct file *filep;
int ret;
- if (!mq_stat)
- {
- set_errno(EINVAL);
- return ERROR;
- }
-
ret = fs_getfilep(mqdes, &filep);
if (ret < 0)
{
@@ -78,17 +122,12 @@ int mq_setattr(mqd_t mqdes, const struct mq_attr *mq_stat,
return ERROR;
}
- /* Return the attributes if so requested */
-
- if (oldstat)
+ ret = file_mq_setattr(filep, mq_stat, oldstat);
+ if (ret < 0)
{
- mq_getattr(mqdes, oldstat);
+ set_errno(-ret);
+ return ERROR;
}
- /* Set the new value of the O_NONBLOCK flag. */
-
- filep->f_oflags = ((mq_stat->mq_flags & O_NONBLOCK) |
- (filep->f_oflags & (~O_NONBLOCK)));
-
return OK;
}
diff --git a/sched/mqueue/mq_timedreceive.c b/sched/mqueue/mq_timedreceive.c
index a07669b..c0f67cb 100644
--- a/sched/mqueue/mq_timedreceive.c
+++ b/sched/mqueue/mq_timedreceive.c
@@ -101,15 +101,15 @@ static void nxmq_rcvtimeout(wdparm_t pid)
****************************************************************************/
/****************************************************************************
- * Name: nxmq_timedreceive
+ * Name: file_mq_timedreceive
*
* Description:
* This function receives the oldest of the highest priority messages from
- * the message queue specified by "mqdes." If the message queue is empty
- * and O_NONBLOCK was not set, nxmq_timedreceive() will block until a
+ * the message queue specified by "mq." If the message queue is empty
+ * and O_NONBLOCK was not set, file_mq_timedreceive() will block until a
* message is added to the message queue (or until a timeout occurs).
*
- * nxmq_timedreceive() is an internal OS interface. It is functionally
+ * file_mq_timedreceive() is an internal OS interface. It is functionally
* equivalent to mq_timedreceive() except that:
*
* - It is not a cancellation point, and
@@ -119,7 +119,7 @@ static void nxmq_rcvtimeout(wdparm_t pid)
* the behavior of this function
*
* Input Parameters:
- * mqdes - Message Queue Descriptor
+ * mq - Message Queue Descriptor
* msg - Buffer to receive the message
* msglen - Size of the buffer in bytes
* prio - If not NULL, the location to store message priority.
@@ -133,28 +133,24 @@ static void nxmq_rcvtimeout(wdparm_t pid)
*
****************************************************************************/
-ssize_t nxmq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen,
- FAR unsigned int *prio,
- FAR const struct timespec *abstime)
+ssize_t file_mq_timedreceive(FAR struct file *mq, FAR char *msg,
+ size_t msglen, FAR unsigned int *prio,
+ FAR const struct timespec *abstime)
{
+ FAR struct inode *inode = mq->f_inode;
FAR struct tcb_s *rtcb = this_task();
FAR struct mqueue_inode_s *msgq;
FAR struct mqueue_msg_s *mqmsg;
- FAR struct file *filep;
- FAR struct inode *inode;
irqstate_t flags;
int ret;
- /* Convert fd to msgq */
-
- ret = fs_getfilep(mqdes, &filep);
- if (ret < 0)
+ inode = mq->f_inode;
+ if (!inode)
{
- return ret;
+ return -EBADF;
}
- inode = filep->f_inode;
- msgq = inode->i_private;
+ msgq = inode->i_private;
DEBUGASSERT(up_interrupt_context() == false);
@@ -162,7 +158,7 @@ ssize_t nxmq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen,
* errno appropriately.
*/
- ret = nxmq_verify_receive(msgq, filep->f_oflags, msg, msglen);
+ ret = nxmq_verify_receive(msgq, mq->f_oflags, msg, msglen);
if (ret < 0)
{
return ret;
@@ -227,7 +223,7 @@ ssize_t nxmq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen,
/* Get the message from the message queue */
- ret = nxmq_wait_receive(msgq, filep->f_oflags, &mqmsg);
+ ret = nxmq_wait_receive(msgq, mq->f_oflags, &mqmsg);
/* Stop the watchdog timer (this is not harmful in the case where
* it was never started)
@@ -258,6 +254,55 @@ ssize_t nxmq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen,
}
/****************************************************************************
+ * Name: nxmq_timedreceive
+ *
+ * Description:
+ * This function receives the oldest of the highest priority messages from
+ * the message queue specified by "mqdes." If the message queue is empty
+ * and O_NONBLOCK was not set, nxmq_timedreceive() will block until a
+ * message is added to the message queue (or until a timeout occurs).
+ *
+ * nxmq_timedreceive() is an internal OS interface. It is functionally
+ * equivalent to mq_timedreceive() except that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_timedreceive() for a more complete description of
+ * the behavior of this function
+ *
+ * Input Parameters:
+ * mqdes - Message Queue Descriptor
+ * msg - Buffer to receive the message
+ * msglen - Size of the buffer in bytes
+ * prio - If not NULL, the location to store message priority.
+ * abstime - the absolute time to wait until a timeout is declared.
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ * (see mq_timedreceive() for the list list valid return values).
+ *
+ ****************************************************************************/
+
+ssize_t nxmq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen,
+ FAR unsigned int *prio,
+ FAR const struct timespec *abstime)
+{
+ FAR struct file *filep;
+ int ret;
+
+ ret = fs_getfilep(mqdes, &filep);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ return file_mq_timedreceive(filep, msg, msglen, prio, abstime);
+}
+
+/****************************************************************************
* Name: mq_timedreceive
*
* Description:
diff --git a/sched/mqueue/mq_timedsend.c b/sched/mqueue/mq_timedsend.c
index 096a92a..8e63de3 100644
--- a/sched/mqueue/mq_timedsend.c
+++ b/sched/mqueue/mq_timedsend.c
@@ -100,16 +100,16 @@ static void nxmq_sndtimeout(wdparm_t pid)
****************************************************************************/
/****************************************************************************
- * Name: nxmq_timedsend
+ * Name: file_mq_timedsend
*
* Description:
* This function adds the specified message (msg) to the message queue
- * (mqdes). nxmq_timedsend() behaves just like mq_send(), except
- * that if the queue is full and the O_NONBLOCK flag is not enabled for
- * the message queue description, then abstime points to a structure which
+ * (mq). file_mq_timedsend() behaves just like mq_send(), except that if
+ * the queue is full and the O_NONBLOCK flag is not enabled for the
+ * message queue description, then abstime points to a structure which
* specifies a ceiling on the time for which the call will block.
*
- * nxmq_timedsend() is functionally equivalent to mq_timedsend() except
+ * file_mq_timedsend() is functionally equivalent to mq_timedsend() except
* that:
*
* - It is not a cancellation point, and
@@ -119,7 +119,7 @@ static void nxmq_sndtimeout(wdparm_t pid)
* behavior of this function
*
* Input Parameters:
- * mqdes - Message queue descriptor
+ * mq - Message queue descriptor
* msg - Message to send
* msglen - The length of the message in bytes
* prio - The priority of the message
@@ -132,8 +132,8 @@ static void nxmq_sndtimeout(wdparm_t pid)
* (see mq_timedsend() for the list list valid return values).
*
* EAGAIN The queue was empty, and the O_NONBLOCK flag was set for the
- * message queue description referred to by mqdes.
- * EINVAL Either msg or mqdes is NULL or the value of prio is invalid.
+ * message queue description referred to by mq.
+ * EINVAL Either msg or mq is NULL or the value of prio is invalid.
* EPERM Message queue opened not opened for writing.
* EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the
* message queue.
@@ -141,35 +141,32 @@ static void nxmq_sndtimeout(wdparm_t pid)
*
****************************************************************************/
-int nxmq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen,
- unsigned int prio, FAR const struct timespec *abstime)
+int file_mq_timedsend(FAR struct file *mq, FAR const char *msg,
+ size_t msglen, unsigned int prio,
+ FAR const struct timespec *abstime)
{
FAR struct tcb_s *rtcb = this_task();
+ FAR struct inode *inode = mq->f_inode;
FAR struct mqueue_msg_s *mqmsg = NULL;
FAR struct mqueue_inode_s *msgq;
- FAR struct file *filep;
- FAR struct inode *inode;
irqstate_t flags;
sclock_t ticks;
int result;
int ret;
- /* Convert fd to msgq */
-
- ret = fs_getfilep(mqdes, &filep);
- if (ret < 0)
+ inode = mq->f_inode;
+ if (!inode)
{
- return ret;
+ return -EBADF;
}
- inode = filep->f_inode;
- msgq = inode->i_private;
+ msgq = inode->i_private;
DEBUGASSERT(up_interrupt_context() == false);
/* Verify the input parameters on any failures to verify. */
- ret = nxmq_verify_send(msgq, filep->f_oflags, msg, msglen, prio);
+ ret = nxmq_verify_send(msgq, mq->f_oflags, msg, msglen, prio);
if (ret < 0)
{
return ret;
@@ -259,7 +256,7 @@ int nxmq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen,
/* And wait for the message queue to be non-empty */
- ret = nxmq_wait_send(msgq, filep->f_oflags);
+ ret = nxmq_wait_send(msgq, mq->f_oflags);
/* This may return with an error and errno set to either EINTR
* or ETIMEOUT. Cancel the watchdog timer in any event.
@@ -311,6 +308,63 @@ errout_with_mqmsg:
}
/****************************************************************************
+ * Name: nxmq_timedsend
+ *
+ * Description:
+ * This function adds the specified message (msg) to the message queue
+ * (mqdes). nxmq_timedsend() behaves just like mq_send(), except
+ * that if the queue is full and the O_NONBLOCK flag is not enabled for
+ * the message queue description, then abstime points to a structure which
+ * specifies a ceiling on the time for which the call will block.
+ *
+ * nxmq_timedsend() is functionally equivalent to mq_timedsend() except
+ * that:
+ *
+ * - It is not a cancellation point, and
+ * - It does not modify the errno value.
+ *
+ * See comments with mq_timedsend() for a more complete description of the
+ * behavior of this function
+ *
+ * Input Parameters:
+ * mqdes - Message queue descriptor
+ * msg - Message to send
+ * msglen - The length of the message in bytes
+ * prio - The priority of the message
+ * abstime - the absolute time to wait until a timeout is decleared
+ *
+ * Returned Value:
+ * This is an internal OS interface and should not be used by applications.
+ * It follows the NuttX internal error return policy: Zero (OK) is
+ * returned on success. A negated errno value is returned on failure.
+ * (see mq_timedsend() for the list list valid return values).
+ *
+ * EAGAIN The queue was empty, and the O_NONBLOCK flag was set for the
+ * message queue description referred to by mqdes.
+ * EINVAL Either msg or mqdes is NULL or the value of prio is invalid.
+ * EPERM Message queue opened not opened for writing.
+ * EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the
+ * message queue.
+ * EINTR The call was interrupted by a signal handler.
+ *
+ ****************************************************************************/
+
+int nxmq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen,
+ unsigned int prio, FAR const struct timespec *abstime)
+{
+ FAR struct file *filep;
+ int ret;
+
+ ret = fs_getfilep(mqdes, &filep);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ return file_mq_timedsend(filep, msg, msglen, prio, abstime);
+}
+
+/****************************************************************************
* Name: mq_timedsend
*
* Description:
diff --git a/wireless/bluetooth/bt_conn.c b/wireless/bluetooth/bt_conn.c
index 4ad6b37..590c9b5 100644
--- a/wireless/bluetooth/bt_conn.c
+++ b/wireless/bluetooth/bt_conn.c
@@ -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);
}
diff --git a/wireless/bluetooth/bt_conn.h b/wireless/bluetooth/bt_conn.h
index 36d506f..fe30394 100644
--- a/wireless/bluetooth/bt_conn.h
+++ b/wireless/bluetooth/bt_conn.h
@@ -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;
diff --git a/wireless/bluetooth/bt_hcicore.c b/wireless/bluetooth/bt_hcicore.c
index 97d3781..787a568 100644
--- a/wireless/bluetooth/bt_hcicore.c
+++ b/wireless/bluetooth/bt_hcicore.c
@@ -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);
diff --git a/wireless/bluetooth/bt_hcicore.h b/wireless/bluetooth/bt_hcicore.h
index 5d36488..987009f 100644
--- a/wireless/bluetooth/bt_hcicore.h
+++ b/wireless/bluetooth/bt_hcicore.h
@@ -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 */
diff --git a/wireless/bluetooth/bt_queue.c b/wireless/bluetooth/bt_queue.c
index 6e8f77f..8d584cc 100644
--- a/wireless/bluetooth/bt_queue.c
+++ b/wireless/bluetooth/bt_queue.c
@@ -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;
diff --git a/wireless/bluetooth/bt_queue.h b/wireless/bluetooth/bt_queue.h
index 7c72557..98a7dbe 100644
--- a/wireless/bluetooth/bt_queue.h
+++ b/wireless/bluetooth/bt_queue.h
@@ -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);