base/include/rtai_mq.h

Go to the documentation of this file.
00001 /* 00002 * pqueues interface for Real Time Linux. 00003 * 00004 * Copyright (©) 1999 Zentropic Computing, All rights reserved 00005 * 00006 * Authors: Trevor Woolven (trevw@zentropix.com) 00007 * 00008 * Original date: Thu 15 Jul 1999 00009 * 00010 * This program is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU General Public License as 00012 * published by the Free Software Foundation; either version 2 of the 00013 * License, or (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00023 * 00024 * 2005, cleaned and revised Paolo Mantegazza <mantegazza@aero.polimi.it>. 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 /* Maximum number of message queues per process */ 00035 #define MQ_PRIO_MAX 32 /* Maximum number of message priorities */ 00036 #define MQ_BLOCK 0 /* Flag to set queue into blocking mode */ 00037 #define MQ_NONBLOCK 1 /* Flag to set queue into non-blocking mode */ 00038 #define MQ_NAME_MAX 80 /* Maximum length of a queue name string */ 00039 00040 #define MQ_MIN_MSG_PRIORITY 0 /* Lowest priority message */ 00041 #define MQ_MAX_MSG_PRIORITY MQ_PRIO_MAX /* Highest priority message */ 00042 00043 #define MAX_PQUEUES 4 /* Maximum number of message queues in module */ 00044 #define MAX_MSGSIZE 50 /* Maximum message size per queue (bytes) */ 00045 #define MAX_MSGS 10 /* Maximum number of messages per queue */ 00046 00047 typedef struct mq_attr { 00048 long mq_maxmsg; /* Maximum number of messages in queue */ 00049 long mq_msgsize; /* Maximum size of a message (in bytes) */ 00050 long mq_flags; /* Blocking/Non-blocking behaviour specifier */ 00051 long mq_curmsgs; /* Number of messages currently in queue */ 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; /* Actual message size */ 00075 uint priority; /* Usage priority (message/task) */ 00076 void *next; /* Pointer to next message on queue */ 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; /* Pointer to the base of the queue in memory */ 00085 void *head; /* Pointer to the element at the front of the queue */ 00086 void *tail; /* Pointer to the element at the back of the queue */ 00087 MQ_ATTR attrs; /* Queue attributes */ 00088 } Q_CTRL; 00089 00090 typedef struct msg { 00091 MSG_HDR hdr; 00092 char data; /* Anchor point for message 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; /* Task that created the queue */ 00102 int open_count; /* Count of the number of tasks that have */ 00103 /* 'opened' the queue for access */ 00104 char q_name[MQ_NAME_MAX]; /* Name supplied for queue */ 00105 uint q_id; /* Queue Id (index into static list of queues) */ 00106 mq_bool_t marked_for_deletion; /* Queue can be deleted once all tasks have */ 00107 /* closed it */ 00108 Q_CTRL data; /* Data queue (real messages) */ 00109 mode_t permissions; /* Permissions granted by creator (ugo, rwx) */ 00110 struct notify notify; /* Notification data (empty -> !empty) */ 00111 SEM emp_cond; /* For blocking on empty queue */ 00112 SEM full_cond; /* For blocking on full queue */ 00113 SEM mutex; /* For synchronisation of queue */ 00114 } MSG_QUEUE; 00115 00116 struct _pqueue_access_data { 00117 int q_id; 00118 int oflags; /* Queue access permissions & blocking spec */ 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 /* __cplusplus */ 00133 extern "C" { 00134 #endif /* !__cplusplus */ 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 /* __cplusplus */ 00179 00180 #else /* !__KERNEL__ */ 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 /* __cplusplus */ 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 /* __cplusplus */ 00256 00257 #endif /* __KERNEL__ */ 00258 00259 #endif /* !_RTAI_MQ_H */

Generated on Thu Nov 20 11:49:49 2008 for RTAI API by doxygen 1.3.8