2023-05-11 16:36:08 +08:00
|
|
|
/****************************************************************************
|
2021-03-09 05:39:04 +08:00
|
|
|
* sched/mqueue/mqueue.h
|
2020-03-10 23:26:30 +08:00
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
2023-05-11 16:36:08 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2014-08-09 02:31:23 +08:00
|
|
|
#ifndef __SCHED_MQUEUE_MQUEUE_H
|
|
|
|
#define __SCHED_MQUEUE_MQUEUE_H
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2023-05-11 16:36:08 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Included Files
|
2023-05-11 16:36:08 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2009-12-15 03:30:18 +08:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
|
2007-02-18 07:21:28 +08:00
|
|
|
#include <sys/types.h>
|
2009-12-15 03:30:18 +08:00
|
|
|
#include <stdint.h>
|
2009-12-15 05:15:18 +08:00
|
|
|
#include <stdbool.h>
|
2007-03-21 00:51:12 +08:00
|
|
|
#include <limits.h>
|
2007-02-18 07:21:28 +08:00
|
|
|
#include <mqueue.h>
|
|
|
|
#include <sched.h>
|
|
|
|
|
2011-04-02 09:23:08 +08:00
|
|
|
#include <nuttx/mqueue.h>
|
|
|
|
|
2022-02-03 03:38:38 +08:00
|
|
|
#if defined(CONFIG_MQ_MAXMSGSIZE) && CONFIG_MQ_MAXMSGSIZE > 0
|
2008-11-08 04:54:27 +08:00
|
|
|
|
2023-05-11 16:36:08 +08:00
|
|
|
/****************************************************************************
|
2014-09-30 03:19:11 +08:00
|
|
|
* Pre-processor Definitions
|
2023-05-11 16:36:08 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
|
|
|
#define MQ_MAX_BYTES CONFIG_MQ_MAXMSGSIZE
|
|
|
|
#define MQ_MAX_MSGS 16
|
2007-03-21 00:51:12 +08:00
|
|
|
#define MQ_PRIO_MAX _POSIX_MQ_PRIO_MAX
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2023-05-11 16:36:08 +08:00
|
|
|
/****************************************************************************
|
2014-09-30 06:22:21 +08:00
|
|
|
* Public Type Definitions
|
2023-05-11 16:36:08 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
|
|
|
enum mqalloc_e
|
|
|
|
{
|
2020-03-11 01:30:24 +08:00
|
|
|
MQ_ALLOC_FIXED = 0, /* Pre-allocated; never freed */
|
|
|
|
MQ_ALLOC_DYN, /* Dynamically allocated; free when unused */
|
|
|
|
MQ_ALLOC_IRQ /* Preallocated, reserved for interrupt handling */
|
2007-02-18 07:21:28 +08:00
|
|
|
};
|
2012-07-15 03:30:31 +08:00
|
|
|
|
2020-03-11 01:30:24 +08:00
|
|
|
/* This structure describes one buffered POSIX message. */
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2014-09-30 03:35:32 +08:00
|
|
|
struct mqueue_msg_s
|
2007-02-18 07:21:28 +08:00
|
|
|
{
|
2022-06-08 22:42:01 +08:00
|
|
|
struct list_node node; /* Link node to message */
|
|
|
|
uint8_t type; /* (Used to manage allocations) */
|
|
|
|
uint8_t priority; /* Priority of message */
|
2007-03-29 21:25:18 +08:00
|
|
|
#if MQ_MAX_BYTES < 256
|
2022-06-08 22:42:01 +08:00
|
|
|
uint8_t msglen; /* Message data length */
|
2007-03-29 21:25:18 +08:00
|
|
|
#else
|
2022-06-08 22:42:01 +08:00
|
|
|
uint16_t msglen; /* Message data length */
|
2007-03-29 21:25:18 +08:00
|
|
|
#endif
|
2022-06-08 22:42:01 +08:00
|
|
|
char mail[MQ_MAX_BYTES]; /* Message data */
|
2007-02-18 07:21:28 +08:00
|
|
|
};
|
2012-07-15 03:30:31 +08:00
|
|
|
|
2023-05-11 16:36:08 +08:00
|
|
|
/****************************************************************************
|
2015-10-03 06:30:35 +08:00
|
|
|
* Public Data
|
2023-05-11 16:36:08 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2013-02-05 00:55:38 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2012-07-15 03:30:31 +08:00
|
|
|
/* The g_msgfree is a list of messages that are available for general use.
|
|
|
|
* The number of messages in this list is a system configuration item.
|
2020-03-11 01:30:24 +08:00
|
|
|
*/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2022-06-08 22:42:01 +08:00
|
|
|
EXTERN struct list_node g_msgfree;
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2022-06-08 22:42:01 +08:00
|
|
|
/* The g_msgfreeirq is a list of messages that are reserved for use by
|
2012-07-15 03:30:31 +08:00
|
|
|
* interrupt handlers.
|
2020-03-11 01:30:24 +08:00
|
|
|
*/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2022-06-08 22:42:01 +08:00
|
|
|
EXTERN struct list_node g_msgfreeirq;
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2023-05-11 16:36:08 +08:00
|
|
|
/****************************************************************************
|
2014-09-30 06:22:21 +08:00
|
|
|
* Public Function Prototypes
|
2023-05-11 16:36:08 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2020-03-11 01:30:24 +08:00
|
|
|
struct tcb_s; /* Forward reference */
|
|
|
|
struct task_group_s; /* Forward reference */
|
2016-04-12 01:14:18 +08:00
|
|
|
|
2023-05-11 16:36:08 +08:00
|
|
|
/* Functions defined in mq_initialize.c *************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2022-08-16 12:20:39 +08:00
|
|
|
void nxmq_initialize(void);
|
2017-10-09 23:06:46 +08:00
|
|
|
void nxmq_free_msg(FAR struct mqueue_msg_s *mqmsg);
|
2007-03-29 21:25:18 +08:00
|
|
|
|
2023-05-11 16:36:08 +08:00
|
|
|
/* mq_waitirq.c *************************************************************/
|
2007-03-29 21:25:18 +08:00
|
|
|
|
2017-10-09 23:06:46 +08:00
|
|
|
void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode);
|
2007-03-29 21:25:18 +08:00
|
|
|
|
2023-05-11 16:36:08 +08:00
|
|
|
/* mq_rcvinternal.c *********************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2022-06-09 13:37:11 +08:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
|
|
|
int nxmq_verify_receive(FAR struct file *mq, FAR char *msg, size_t msglen);
|
|
|
|
#else
|
2023-05-20 06:32:34 +08:00
|
|
|
# define nxmq_verify_receive(msgq, msg, msglen) OK
|
2022-06-09 13:37:11 +08:00
|
|
|
#endif
|
2020-12-22 22:02:48 +08:00
|
|
|
int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,
|
|
|
|
int oflags, FAR struct mqueue_msg_s **rcvmsg);
|
|
|
|
ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
|
|
|
|
FAR struct mqueue_msg_s *mqmsg,
|
2022-08-16 12:20:39 +08:00
|
|
|
FAR char *ubuffer, FAR unsigned int *prio);
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2023-05-11 16:36:08 +08:00
|
|
|
/* mq_sndinternal.c *********************************************************/
|
2007-03-28 22:48:42 +08:00
|
|
|
|
2022-06-09 13:37:11 +08:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
|
|
|
int nxmq_verify_send(FAR struct file *mq, FAR const char *msg,
|
|
|
|
size_t msglen, unsigned int prio);
|
|
|
|
#else
|
2023-05-20 06:32:34 +08:00
|
|
|
# define nxmq_verify_send(mq, msg, msglen, prio) OK
|
2022-06-09 13:37:11 +08:00
|
|
|
#endif
|
2017-10-09 23:06:46 +08:00
|
|
|
FAR struct mqueue_msg_s *nxmq_alloc_msg(void);
|
2020-12-22 22:02:48 +08:00
|
|
|
int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags);
|
|
|
|
int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
|
|
|
|
FAR struct mqueue_msg_s *mqmsg,
|
2019-02-16 09:18:55 +08:00
|
|
|
FAR const char *msg, size_t msglen, unsigned int prio);
|
2013-02-05 00:55:38 +08:00
|
|
|
|
2023-05-11 16:36:08 +08:00
|
|
|
/* mq_recover.c *************************************************************/
|
2013-02-06 03:50:37 +08:00
|
|
|
|
2017-10-09 23:06:46 +08:00
|
|
|
void nxmq_recover(FAR struct tcb_s *tcb);
|
2013-02-06 03:50:37 +08:00
|
|
|
|
2007-02-18 07:21:28 +08:00
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-02-03 03:38:38 +08:00
|
|
|
#endif /* defined(CONFIG_MQ_MAXMSGSIZE) && CONFIG_MQ_MAXMSGSIZE > 0 */
|
2020-03-11 01:30:24 +08:00
|
|
|
#endif /* __SCHED_MQUEUE_MQUEUE_H */
|