00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
#ifndef _RTAI_MQ_H
00029
#define _RTAI_MQ_H
00030
00031
#include <linux/version.h>
00032
#include <rtai_sem.h>
00033
00034 #define MQ_OPEN_MAX 8
00035 #define MQ_PRIO_MAX 32
00036 #define MQ_BLOCK 0
00037 #define MQ_NONBLOCK 1
00038 #define MQ_NAME_MAX 80
00039
00040 #define MQ_MIN_MSG_PRIORITY 0
00041 #define MQ_MAX_MSG_PRIORITY MQ_PRIO_MAX
00042
00043 #define MAX_PQUEUES 4
00044 #define MAX_MSGSIZE 50
00045 #define MAX_MSGS 10
00046
00047 typedef struct mq_attr {
00048 long mq_maxmsg;
00049 long mq_msgsize;
00050 long mq_flags;
00051 long mq_curmsgs;
00052 }
MQ_ATTR;
00053
00054 #define INVALID_PQUEUE 0
00055
00056
#ifdef __KERNEL__
00057
00058
#include <linux/types.h>
00059
00060
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,6)
00061
typedef int mqd_t;
00062
#endif
00063
00064
#ifndef __cplusplus
00065
00066
typedef int mq_bool_t;
00067
00068
#ifndef TRUE
00069
#define TRUE 1
00070
#define FALSE 0
00071
#endif
00072
00073
typedef struct msg_hdr {
00074 size_t size;
00075 uint priority;
00076
void *next;
00077 } MSG_HDR;
00078
00079
#define MSG_HDR_SIZE (sizeof(MSG_HDR))
00080
00081
typedef struct queue_control {
00082
int nodind;
00083
void **nodes;
00084
void *base;
00085
void *head;
00086
void *tail;
00087
MQ_ATTR attrs;
00088 } Q_CTRL;
00089
00090
typedef struct msg {
00091 MSG_HDR hdr;
00092
char data;
00093 } MQMSG;
00094
00095
struct notify {
00096
RT_TASK *
task;
00097
struct sigevent data;
00098 };
00099
00100
typedef struct _pqueue_descr_struct {
00101
RT_TASK *owner;
00102
int open_count;
00103
00104
char q_name[
MQ_NAME_MAX];
00105 uint q_id;
00106 mq_bool_t marked_for_deletion;
00107
00108 Q_CTRL data;
00109 mode_t permissions;
00110
struct notify notify;
00111
SEM emp_cond;
00112
SEM full_cond;
00113
SEM mutex;
00114 } MSG_QUEUE;
00115
00116
struct _pqueue_access_data {
00117
int q_id;
00118
int oflags;
00119 };
00120
00121
typedef struct _pqueue_access_struct {
00122
RT_TASK *this_task;
00123
int n_open_pqueues;
00124
struct _pqueue_access_data q_access[
MQ_OPEN_MAX];
00125 } *QUEUE_CTRL;
00126
00127
typedef enum {
00128 FOR_READ,
00129 FOR_WRITE
00130 } Q_ACCESS;
00131
00132
#else
00133
extern "C" {
00134
#endif
00135
00136
int __rtai_mq_init(
void);
00137
00138
void __rtai_mq_exit(
void);
00139
00140
mqd_t mq_open(
char *mq_name,
int oflags, mode_t permissions,
struct mq_attr *
mq_attr);
00141
00142 size_t
_mq_receive(mqd_t mq,
char *msg_buffer, size_t buflen,
unsigned int *msgprio,
int space);
00143
static inline size_t
mq_receive(mqd_t mq,
char *msg_buffer, size_t buflen,
unsigned int *msgprio)
00144 {
00145
return _mq_receive(mq, msg_buffer, buflen, msgprio, 1);
00146 }
00147
00148
int _mq_send(mqd_t mq,
const char *msg, size_t msglen,
unsigned int msgprio,
int space);
00149
static inline int mq_send(mqd_t mq,
const char *msg, size_t msglen,
unsigned int msgprio)
00150 {
00151
return _mq_send(mq, msg, msglen, msgprio, 1);
00152 }
00153
00154
int mq_close(mqd_t mq);
00155
00156
int mq_getattr(mqd_t mq,
struct mq_attr *attrbuf);
00157
00158
int mq_setattr(mqd_t mq,
const struct mq_attr *new_attrs,
struct mq_attr *old_attrs);
00159
00160
int mq_notify(mqd_t mq,
const struct sigevent *notification);
00161
00162
int mq_unlink(
char *mq_name);
00163
00164 size_t
_mq_timedreceive(mqd_t mq,
char *msg_buffer, size_t buflen,
unsigned int *msgprio,
const struct timespec *abstime,
int space);
00165
static inline size_t
mq_timedreceive(mqd_t mq,
char *msg_buffer, size_t buflen,
unsigned int *msgprio,
const struct timespec *abstime)
00166 {
00167
return _mq_timedreceive(mq, msg_buffer, buflen, msgprio, abstime, 1);
00168 }
00169
00170
int _mq_timedsend(mqd_t mq,
const char *msg, size_t msglen,
unsigned int msgprio,
const struct timespec *abstime,
int space);
00171
static inline int mq_timedsend(mqd_t mq,
const char *msg, size_t msglen,
unsigned int msgprio,
const struct timespec *abstime)
00172 {
00173
return _mq_timedsend(mq, msg, msglen, msgprio, abstime, 1);
00174 }
00175
00176
#ifdef __cplusplus
00177
}
00178
#endif
00179
00180
#else
00181
00182
#include <signal.h>
00183
#include <rtai_lxrt.h>
00184
00185 #define MQIDX 0
00186
00187 typedef int mqd_t;
00188
00189
#ifdef __cplusplus
00190
extern "C" {
00191
#endif
00192
00193 RTAI_PROTO(mqd_t, mq_open,(
char *mq_name,
int oflags, mode_t permissions,
struct mq_attr *
mq_attr))
00194 {
00195
struct {
char *mq_name;
int oflags; mode_t permissions;
struct mq_attr *mq_attr;
int namesize, attrsize; } arg = { mq_name, oflags, permissions, mq_attr, strlen(mq_name) + 1,
sizeof(
struct mq_attr) };
00196
return (
mqd_t)
rtai_lxrt(
MQIDX,
SIZARG,
MQ_OPEN, &arg).
i[
LOW];
00197 }
00198
00199 RTAI_PROTO(size_t, mq_receive,(mqd_t mq,
char *msg_buffer, size_t buflen,
unsigned int *msgprio))
00200 {
00201
struct {
mqd_t mq;
char *msg_buffer; size_t buflen;
unsigned int *msgprio;
int space; } arg = { mq, msg_buffer, buflen, msgprio, 0 };
00202
return (size_t)
rtai_lxrt(
MQIDX,
SIZARG,
MQ_RECEIVE, &arg).
i[
LOW];
00203 }
00204
00205 RTAI_PROTO(
int, mq_send,(mqd_t mq,
const char *msg, size_t msglen,
unsigned int msgprio))
00206 {
00207
struct {
mqd_t mq;
const char *msg; size_t msglen;
unsigned int msgprio;
int space; } arg = { mq, msg, msglen, msgprio, 0 };
00208
return rtai_lxrt(
MQIDX,
SIZARG,
MQ_SEND, &arg).
i[
LOW];
00209 }
00210
00211 RTAI_PROTO(
int, mq_close,(mqd_t mq))
00212 {
00213
struct {
mqd_t mq; } arg = { mq };
00214
return rtai_lxrt(
MQIDX,
SIZARG,
MQ_CLOSE, &arg).
i[
LOW];
00215 }
00216
00217 RTAI_PROTO(
int, mq_getattr,(mqd_t mq,
struct mq_attr *attrbuf))
00218 {
00219
struct {
mqd_t mq;
struct mq_attr *attrbuf;
int attrsize; } arg = { mq, attrbuf,
sizeof(
struct mq_attr) };
00220
return rtai_lxrt(
MQIDX,
SIZARG,
MQ_GETATTR, &arg).
i[
LOW];
00221 }
00222
00223 RTAI_PROTO(
int, mq_setattr,(mqd_t mq,
const struct mq_attr *new_attrs,
struct mq_attr *old_attrs))
00224 {
00225
struct {
mqd_t mq;
const struct mq_attr *new_attrs;
struct mq_attr *old_attrs;
int attrsize; } arg = { mq, new_attrs, old_attrs,
sizeof(
struct mq_attr) };
00226
return rtai_lxrt(
MQIDX,
SIZARG,
MQ_SETATTR, &arg).
i[
LOW];
00227 }
00228
00229 RTAI_PROTO(
int, mq_notify,(mqd_t mq,
const struct sigevent *notification))
00230 {
00231
struct {
mqd_t mq;
const struct sigevent *notification;
int size; } arg = { mq, notification,
sizeof(
struct sigevent) };
00232
return rtai_lxrt(
MQIDX,
SIZARG,
MQ_NOTIFY, &arg).
i[
LOW];
00233 }
00234
00235 RTAI_PROTO(
int, mq_unlink,(
char *mq_name))
00236 {
00237
struct {
char *mq_name;
int size; } arg = { mq_name, strlen(mq_name) + 1};
00238
return rtai_lxrt(
MQIDX,
SIZARG,
MQ_UNLINK, &arg).
i[
LOW];
00239 }
00240
00241 RTAI_PROTO(size_t, mq_timedreceive,(mqd_t mq,
char *msg_buffer, size_t buflen,
unsigned int *msgprio,
const struct timespec *abstime))
00242 {
00243
struct {
mqd_t mq;
char *msg_buffer; size_t buflen;
unsigned int *msgprio;
const struct timespec *abstime;
int space; } arg = { mq, msg_buffer, buflen, msgprio, abstime, 0 };
00244
return (size_t)
rtai_lxrt(
MQIDX,
SIZARG,
MQ_TIMEDRECEIVE, &arg).
i[
LOW];
00245 }
00246
00247 RTAI_PROTO(
int, mq_timedsend,(mqd_t mq,
const char *msg, size_t msglen,
unsigned int msgprio,
const struct timespec *abstime))
00248 {
00249
struct {
mqd_t mq;
const char *msg; size_t msglen;
unsigned int msgprio;
const struct timespec *abstime;
int space; } arg = { mq, msg, msglen, msgprio, abstime, 0 };
00250
return rtai_lxrt(
MQIDX,
SIZARG,
MQ_TIMEDSEND, &arg).
i[
LOW];
00251 }
00252
00253
#ifdef __cplusplus
00254
}
00255
#endif
00256
00257
#endif
00258
00259
#endif