2007-03-29 15:25:18 +02:00
|
|
|
/****************************************************************************
|
2014-08-08 20:31:23 +02:00
|
|
|
* sched/mqueue/mqueue.h
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2014-08-08 20:31:23 +02:00
|
|
|
* Copyright (C) 2007, 2009, 2011, 2013-2014 Gregory Nutt. All rights reserved.
|
2012-07-14 21:30:31 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2009-12-14 20:30:18 +01:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-18 00:21:28 +01:00
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2007-03-29 15:25:18 +02: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
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2007-03-29 15:25:18 +02: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>
|
2007-02-21 00:51:56 +01:00
|
|
|
#include <signal.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
|
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
|
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Definitions
|
2007-03-29 15:25:18 +02: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."
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define NUM_MSG_DESCRIPTORS 24
|
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/* This defines the number of messages to set aside for exclusive use by
|
|
|
|
* interrupt handlers
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define NUM_INTERRUPT_MSGS 8
|
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Global Type Declarations
|
2007-03-29 15:25:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
enum mqalloc_e
|
|
|
|
{
|
|
|
|
MQ_ALLOC_FIXED = 0, /* pre-allocated; never freed */
|
|
|
|
MQ_ALLOC_DYN, /* dynamically allocated; free when unused */
|
|
|
|
MQ_ALLOC_IRQ /* Preallocated, reserved for interrupt handling */
|
|
|
|
};
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
typedef enum mqalloc_e mqalloc_t;
|
|
|
|
|
|
|
|
/* This structure describes one buffered POSIX message. */
|
|
|
|
|
|
|
|
struct mqmsg
|
|
|
|
{
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR struct mqmsg *next; /* Forward link to next message */
|
2009-12-14 19:39:29 +01:00
|
|
|
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
|
2009-12-14 19:39:29 +01:00
|
|
|
uint8_t msglen; /* Message data length */
|
2007-03-29 15:25:18 +02:00
|
|
|
#else
|
2009-12-14 19:39:29 +01:00
|
|
|
uint16_t msglen; /* Message data length */
|
2007-03-29 15:25:18 +02:00
|
|
|
#endif
|
2009-12-14 19:39:29 +01:00
|
|
|
uint8_t mail[MQ_MAX_BYTES]; /* Message data */
|
2007-02-18 00:21:28 +01:00
|
|
|
};
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
typedef struct mqmsg mqmsg_t;
|
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Global Variables
|
2007-03-29 15:25:18 +02: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
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* This is a list of all opened message queues */
|
|
|
|
|
2013-02-04 17:55:38 +01:00
|
|
|
EXTERN sq_queue_t g_msgqueues;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
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.
|
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.
|
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.
|
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
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Global Function Prototypes
|
2007-03-29 15:25:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/* Functions defined in mq_initialize.c ************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-04 17:55:38 +01:00
|
|
|
void weak_function mq_initialize(void);
|
|
|
|
void mq_desblockalloc(void);
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2013-02-04 19:46:28 +01:00
|
|
|
mqd_t mq_descreate(FAR struct tcb_s* mtcb, FAR msgq_t* msgq, int oflags);
|
2013-02-04 17:55:38 +01:00
|
|
|
FAR msgq_t *mq_findnamed(const char *mq_name);
|
|
|
|
void mq_msgfree(FAR mqmsg_t *mqmsg);
|
|
|
|
void mq_msgqfree(FAR msgq_t *msgq);
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/* mq_waitirq.c ************************************************************/
|
|
|
|
|
2013-02-04 19:46:28 +01:00
|
|
|
void mq_waitirq(FAR struct tcb_s *wtcb, int errcode);
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/* mq_rcvinternal.c ********************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-02-04 17:55:38 +01:00
|
|
|
int mq_verifyreceive(mqd_t mqdes, void *msg, size_t msglen);
|
|
|
|
FAR mqmsg_t *mq_waitreceive(mqd_t mqdes);
|
|
|
|
ssize_t mq_doreceive(mqd_t mqdes, mqmsg_t *mqmsg, void *ubuffer, int *prio);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/* mq_sndinternal.c ********************************************************/
|
2007-03-28 16:48:42 +02:00
|
|
|
|
2013-02-04 17:55:38 +01:00
|
|
|
int mq_verifysend(mqd_t mqdes, const void *msg, size_t msglen, int prio);
|
|
|
|
FAR mqmsg_t *mq_msgalloc(void);
|
|
|
|
int mq_waitsend(mqd_t mqdes);
|
|
|
|
int mq_dosend(mqd_t mqdes, FAR mqmsg_t *mqmsg, const void *msg,
|
|
|
|
size_t msglen, int prio);
|
|
|
|
|
|
|
|
/* mq_release.c ************************************************************/
|
|
|
|
|
|
|
|
struct task_group_s; /* Forward reference */
|
|
|
|
void mq_release(FAR struct task_group_s *group);
|
2007-03-28 16:48:42 +02:00
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/* mq_recover.c ************************************************************/
|
|
|
|
|
|
|
|
void mq_recover(FAR struct tcb_s *tcb);
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-07 21:54:27 +01:00
|
|
|
#endif /* CONFIG_MQ_MAXMSGSIZE > 0 */
|
2014-08-08 20:31:23 +02:00
|
|
|
#endif /* __SCHED_MQUEUE_MQUEUE_H */
|
2007-02-18 00:21:28 +01:00
|
|
|
|