2020-03-08 13:12:08 +01:00
|
|
|
/********************************************************************************
|
2014-08-08 20:31:23 +02:00
|
|
|
* sched/mqueue/mqueue.h
|
2020-03-10 16:26:30 +01: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.
|
|
|
|
*
|
2020-03-08 13:12:08 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-08 20:31:23 +02:00
|
|
|
#ifndef __SCHED_MQUEUE_MQUEUE_H
|
|
|
|
#define __SCHED_MQUEUE_MQUEUE_H
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-03-08 13:12:08 +01:00
|
|
|
/********************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2020-03-08 13:12:08 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-12-14 20:30:18 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <sys/types.h>
|
2009-12-14 20:30:18 +01:00
|
|
|
#include <stdint.h>
|
2009-12-14 22:15:18 +01:00
|
|
|
#include <stdbool.h>
|
2007-03-20 17:51:12 +01:00
|
|
|
#include <limits.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <mqueue.h>
|
|
|
|
#include <sched.h>
|
|
|
|
|
2011-04-02 03:23:08 +02:00
|
|
|
#include <nuttx/mqueue.h>
|
|
|
|
|
2008-11-07 21:54:27 +01:00
|
|
|
#if CONFIG_MQ_MAXMSGSIZE > 0
|
|
|
|
|
2020-03-08 13:12:08 +01:00
|
|
|
/********************************************************************************
|
2014-09-29 21:19:11 +02:00
|
|
|
* Pre-processor Definitions
|
2020-03-08 13:12:08 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#define MQ_MAX_BYTES CONFIG_MQ_MAXMSGSIZE
|
|
|
|
#define MQ_MAX_MSGS 16
|
2007-03-20 17:51:12 +01:00
|
|
|
#define MQ_PRIO_MAX _POSIX_MQ_PRIO_MAX
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/* This defines the number of messages descriptors to allocate at each
|
|
|
|
* "gulp."
|
2020-03-10 18:30:24 +01:00
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-08-04 11:34:37 +02:00
|
|
|
#define NUM_MSG_DESCRIPTORS 4
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/* This defines the number of messages to set aside for exclusive use by
|
|
|
|
* interrupt handlers
|
2020-03-10 18:30:24 +01:00
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#define NUM_INTERRUPT_MSGS 8
|
|
|
|
|
2020-03-08 13:12:08 +01:00
|
|
|
/********************************************************************************
|
2014-09-30 00:22:21 +02:00
|
|
|
* Public Type Definitions
|
2020-03-08 13:12:08 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
enum mqalloc_e
|
|
|
|
{
|
2020-03-10 18:30:24 +01: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 00:21:28 +01:00
|
|
|
};
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2020-03-10 18:30:24 +01:00
|
|
|
/* This structure describes one buffered POSIX message. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-09-29 21:35:32 +02:00
|
|
|
struct mqueue_msg_s
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2020-03-10 18:30:24 +01:00
|
|
|
FAR struct mqueue_msg_s *next; /* Forward link to next message */
|
|
|
|
uint8_t type; /* (Used to manage allocations) */
|
|
|
|
uint8_t priority; /* priority of message */
|
2007-03-29 15:25:18 +02:00
|
|
|
#if MQ_MAX_BYTES < 256
|
2020-03-10 18:30:24 +01:00
|
|
|
uint8_t msglen; /* Message data length */
|
2007-03-29 15:25:18 +02:00
|
|
|
#else
|
2020-03-10 18:30:24 +01:00
|
|
|
uint16_t msglen; /* Message data length */
|
2007-03-29 15:25:18 +02:00
|
|
|
#endif
|
2020-03-10 18:30:24 +01:00
|
|
|
char mail[MQ_MAX_BYTES]; /* Message data */
|
2007-02-18 00:21:28 +01:00
|
|
|
};
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2020-03-08 13:12:08 +01:00
|
|
|
/********************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Data
|
2020-03-08 13:12:08 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-04 17:55:38 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2012-07-14 21:30:31 +02: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-10 18:30:24 +01:00
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-04 17:55:38 +01:00
|
|
|
EXTERN sq_queue_t g_msgfree;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/* The g_msgfreeInt is a list of messages that are reserved for use by
|
|
|
|
* interrupt handlers.
|
2020-03-10 18:30:24 +01:00
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-04 17:55:38 +01:00
|
|
|
EXTERN sq_queue_t g_msgfreeirq;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/* The g_desfree data structure is a list of message descriptors available
|
|
|
|
* to the operating system for general use. The number of messages in the
|
|
|
|
* pool is a constant.
|
2020-03-10 18:30:24 +01:00
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-04 17:55:38 +01:00
|
|
|
EXTERN sq_queue_t g_desfree;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-03-08 13:12:08 +01:00
|
|
|
/********************************************************************************
|
2014-09-30 00:22:21 +02:00
|
|
|
* Public Function Prototypes
|
2020-03-08 13:12:08 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-03-10 18:30:24 +01:00
|
|
|
struct tcb_s; /* Forward reference */
|
|
|
|
struct task_group_s; /* Forward reference */
|
2016-04-11 19:14:18 +02:00
|
|
|
|
2020-03-08 13:12:08 +01:00
|
|
|
/* Functions defined in mq_initialize.c *****************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
void weak_function nxmq_initialize(void);
|
|
|
|
void nxmq_alloc_desblock(void);
|
|
|
|
void nxmq_free_msg(FAR struct mqueue_msg_s *mqmsg);
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2020-03-08 13:12:08 +01:00
|
|
|
/* mq_waitirq.c *****************************************************************/
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode);
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2020-03-08 13:12:08 +01:00
|
|
|
/* mq_rcvinternal.c *************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
int nxmq_verify_receive(mqd_t mqdes, FAR char *msg, size_t msglen);
|
2017-10-10 17:57:40 +02:00
|
|
|
int nxmq_wait_receive(mqd_t mqdes, FAR struct mqueue_msg_s **rcvmsg);
|
2017-10-09 17:06:46 +02:00
|
|
|
ssize_t nxmq_do_receive(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg,
|
2019-02-16 02:18:55 +01:00
|
|
|
FAR char *ubuffer, FAR unsigned int *prio);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-03-08 13:12:08 +01:00
|
|
|
/* mq_sndinternal.c *************************************************************/
|
2007-03-28 16:48:42 +02:00
|
|
|
|
2019-02-16 02:18:55 +01:00
|
|
|
int nxmq_verify_send(mqd_t mqdes, FAR const char *msg, size_t msglen,
|
|
|
|
unsigned int prio);
|
2017-10-09 17:06:46 +02:00
|
|
|
FAR struct mqueue_msg_s *nxmq_alloc_msg(void);
|
|
|
|
int nxmq_wait_send(mqd_t mqdes);
|
|
|
|
int nxmq_do_send(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg,
|
2019-02-16 02:18:55 +01:00
|
|
|
FAR const char *msg, size_t msglen, unsigned int prio);
|
2013-02-04 17:55:38 +01:00
|
|
|
|
2020-03-08 13:12:08 +01:00
|
|
|
/* mq_release.c *****************************************************************/
|
2013-02-04 17:55:38 +01:00
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
void nxmq_release(FAR struct task_group_s *group);
|
2007-03-28 16:48:42 +02:00
|
|
|
|
2020-03-08 13:12:08 +01:00
|
|
|
/* mq_recover.c *****************************************************************/
|
2013-02-05 20:50:37 +01:00
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
void nxmq_recover(FAR struct tcb_s *tcb);
|
2013-02-05 20:50:37 +01:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-03-10 18:30:24 +01:00
|
|
|
#endif /* CONFIG_MQ_MAXMSGSIZE > 0 */
|
|
|
|
#endif /* __SCHED_MQUEUE_MQUEUE_H */
|