base/include/rtai_tbx.h

Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2005 Paolo Mantegazza <mantegazza@aero.polimi.it> 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License as 00006 * published by the Free Software Foundation; either version 2 of the 00007 * License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 * 00018 */ 00019 00020 00021 #ifndef _RTAI_RT_MSGQ_H 00022 #define _RTAI_RT_MSGQ_H 00023 00024 #include <linux/version.h> 00025 #include <rtai_sem.h> 00026 00027 #define MSGQ_INIT TBX_INIT 00028 #define MSGQ_DELETE TBX_DELETE 00029 #define NAMED_MSGQ_INIT NAMED_TBX_INIT 00030 #define NAMED_MSGQ_DELETE NAMED_TBX_DELETE 00031 #define MSG_SEND TBX_SEND 00032 #define MSG_SEND_IF TBX_SEND_IF 00033 #define MSG_SEND_UNTIL TBX_SEND_UNTIL 00034 #define MSG_SEND_TIMED TBX_SEND_TIMED 00035 #define MSG_RECEIVE TBX_RECEIVE 00036 #define MSG_RECEIVE_IF TBX_RECEIVE_IF 00037 #define MSG_RECEIVE_UNTIL TBX_RECEIVE_UNTIL 00038 #define MSG_RECEIVE_TIMED TBX_RECEIVE_TIMED 00039 #define MSG_BROADCAST TBX_BROADCAST 00040 #define MSG_BROADCAST_IF TBX_BROADCAST_IF 00041 #define MSG_BROADCAST_UNTIL TBX_BROADCAST_UNTIL 00042 #define MSG_BROADCAST_TIMED TBX_BROADCAST_TIMED 00043 #define MSG_EVDRP TBX_URGENT 00044 00045 #define TBX RT_MSGQ 00046 00047 #ifdef __KERNEL__ 00048 00049 typedef struct rt_msgh { 00050 void *malloc; 00051 int broadcast; 00052 int size; 00053 int priority; 00054 void *next; 00055 } RT_MSGH; 00056 00057 #define RT_MSGH_SIZE (sizeof(RT_MSGH)) 00058 00059 typedef struct rt_msg { 00060 RT_MSGH hdr; 00061 char msg[1]; 00062 } RT_MSG; 00063 00064 typedef struct rt_msgq { 00065 int nmsg; 00066 int fastsize; 00067 int slot; 00068 void **slots; 00069 void *firstmsg; 00070 SEM receivers, senders; 00071 SEM received, freslots; 00072 SEM broadcast; 00073 spinlock_t lock; 00074 } RT_MSGQ; 00075 00076 #include <linux/types.h> 00077 00078 #ifdef __cplusplus 00079 extern "C" { 00080 #endif /* !__cplusplus */ 00081 00082 int __rtai_msg_queue_init(void); 00083 00084 void __rtai_msg_queue_exit(void); 00085 00086 int rt_msgq_init(RT_MSGQ *msgq, int nmsg, int msg_size); 00087 00088 int rt_msgq_delete(RT_MSGQ *msgq); 00089 00090 RT_MSGQ *_rt_named_msgq_init(unsigned long msgq_name, int nmsg, int size); 00091 static inline RT_MSGQ *rt_named_msgq_init(const char *msgq_name, int nmsg, int size) 00092 { 00093 return _rt_named_msgq_init(nam2num(msgq_name), nmsg, size); 00094 } 00095 00096 int rt_named_msgq_delete(RT_MSGQ *msgq); 00097 00098 int _rt_msg_send(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri, int space); 00099 static inline int rt_msg_send(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri) 00100 { 00101 return _rt_msg_send(msgq, msg, msg_size, msgpri, 1); 00102 } 00103 00104 int _rt_msg_send_if(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri, int space); 00105 static inline int rt_msg_send_if(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri) 00106 { 00107 return _rt_msg_send_if(msgq, msg, msg_size, msgpri, 1); 00108 } 00109 00110 int _rt_msg_send_until(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri, RTIME until, int space); 00111 static inline int rt_msg_send_until(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri, RTIME until) 00112 { 00113 return _rt_msg_send_until(msgq, msg, msg_size, msgpri, until, 1); 00114 } 00115 00116 int _rt_msg_send_timed(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri, RTIME delay, int space); 00117 static inline int rt_msg_send_timed(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri, RTIME delay) 00118 { 00119 return _rt_msg_send_timed(msgq, msg, msg_size, msgpri, delay, 1); 00120 } 00121 00122 int _rt_msg_receive(RT_MSGQ *msgq, void *msg, int msg_size, int *msgpri, int space); 00123 static inline int rt_msg_receive(RT_MSGQ *msgq, void *msg, int msg_size, int *msgpri) 00124 { 00125 return _rt_msg_receive(msgq, msg, msg_size, msgpri, 1); 00126 } 00127 00128 int _rt_msg_receive_if(RT_MSGQ *msgq, void *msg, int msg_size, int *msgpri, int space); 00129 static inline int rt_msg_receive_if(RT_MSGQ *msgq, void *msg, int msg_size, int *msgpri) 00130 { 00131 return _rt_msg_receive_if(msgq, msg, msg_size, msgpri, 1); 00132 } 00133 00134 int _rt_msg_receive_until(RT_MSGQ *msgq, void *msg, int msg_size, int *msgpri, RTIME until, int space); 00135 static inline int rt_msg_receive_until(RT_MSGQ *msgq, void *msg, int msg_size, int *msgpri, RTIME until) 00136 { 00137 return _rt_msg_receive_until(msgq, msg, msg_size, msgpri, until, 1); 00138 } 00139 00140 int _rt_msg_receive_timed(RT_MSGQ *msgq, void *msg, int msg_size, int *msgpri, RTIME delay, int space); 00141 static inline int rt_msg_receive_timed(RT_MSGQ *msgq, void *msg, int msg_size, int *msgpri, RTIME delay) 00142 { 00143 return _rt_msg_receive_timed(msgq, msg, msg_size, msgpri, delay, 1); 00144 } 00145 00146 int _rt_msg_evdrp(RT_MSGQ *msgq, void *msg, int msg_size, int *msgpri, int space); 00147 static inline int rt_msg_evdrp(RT_MSGQ *msgq, void *msg, int msg_size, int *msgpri) 00148 { 00149 return _rt_msg_evdrp(msgq, msg, msg_size, msgpri, 1); 00150 } 00151 00152 int _rt_msg_broadcast(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri, int space); 00153 static inline int rt_msg_broadcast(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri) 00154 { 00155 return _rt_msg_broadcast(msgq, msg, msg_size, msgpri, 1); 00156 } 00157 00158 int _rt_msg_broadcast_if(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri, int space); 00159 static inline int rt_msg_broadcast_if(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri) 00160 { 00161 return _rt_msg_broadcast_if(msgq, msg, msg_size, msgpri, 1); 00162 } 00163 00164 int _rt_msg_broadcast_until(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri, RTIME until, int space); 00165 static inline int rt_msg_broadcast_until(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri, RTIME until) 00166 { 00167 return _rt_msg_broadcast_until(msgq, msg, msg_size, msgpri, until, 1); 00168 } 00169 00170 int _rt_msg_broadcast_timed(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri, RTIME delay, int space); 00171 static inline int rt_msg_broadcast_delay(RT_MSGQ *msgq, void *msg, int msg_size, int msgpri, RTIME delay) 00172 { 00173 return _rt_msg_broadcast_until(msgq, msg, msg_size, msgpri, delay, 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 struct rt_msgh; 00186 00187 #ifdef __cplusplus 00188 extern "C" { 00189 #endif /* __cplusplus */ 00190 00191 typedef struct rt_msgq { 00192 int dummy; 00193 } RT_MSGQ; 00194 00195 RTAI_PROTO(RT_MSGQ *, rt_msgq_init, (unsigned long msgq, int nmsg, int msg_size)) 00196 { 00197 struct { unsigned long msgq; long nmsg; long msg_size; } arg = { msgq, nmsg, msg_size }; 00198 return rtai_lxrt(BIDX, SIZARG, NAMED_MSGQ_INIT, &arg).v[LOW]; 00199 } 00200 00201 RTAI_PROTO(int, rt_msgq_delete, (RT_MSGQ *msgq)) 00202 { 00203 struct { RT_MSGQ *msgq; } arg = { msgq }; 00204 return rtai_lxrt(BIDX, SIZARG, NAMED_MSGQ_DELETE, &arg).i[LOW]; 00205 } 00206 00207 RTAI_PROTO(RT_MSGQ *, rt_named_msgq_init,(const char *name, int nmsg, int size)) 00208 { 00209 struct { unsigned long name; long nmsg; long size; } arg = { nam2num(name), nmsg, size }; 00210 return rtai_lxrt(BIDX, SIZARG, NAMED_MSGQ_INIT, &arg).v[LOW]; 00211 } 00212 00213 RTAI_PROTO(int, rt_named_msgq_delete, (RT_MSGQ *msgq)) 00214 { 00215 struct { RT_MSGQ *msgq; } arg = { msgq }; 00216 return rtai_lxrt(BIDX, SIZARG, NAMED_MSGQ_DELETE, &arg).i[LOW]; 00217 } 00218 00219 RTAI_PROTO(int, rt_msg_send, (RT_MSGQ *msgq, void *msg, int msg_size, int msgprio)) 00220 { 00221 struct { RT_MSGQ *msgq; void *msg; long msg_size; long msgprio; long space; } arg = { msgq, msg, msg_size, msgprio, 0 }; 00222 return rtai_lxrt(BIDX, SIZARG, MSG_SEND, &arg).i[LOW]; 00223 } 00224 00225 RTAI_PROTO(int, rt_msg_send_if, (RT_MSGQ *msgq, void *msg, int msg_size, int msgprio)) 00226 { 00227 struct { RT_MSGQ *msgq; void *msg; long msg_size; long msgprio; long space; } arg = { msgq, msg, msg_size, msgprio, 0 }; 00228 return rtai_lxrt(BIDX, SIZARG, MSG_SEND_IF, &arg).i[LOW]; 00229 } 00230 00231 RTAI_PROTO(int, rt_msg_send_until, (RT_MSGQ *msgq, void *msg, int msg_size, int msgprio, RTIME until)) 00232 { 00233 struct { RT_MSGQ *msgq; void *msg; long msg_size; long msgprio; RTIME until; long space; } arg = { msgq, msg, msg_size, msgprio, until, 0 }; 00234 return rtai_lxrt(BIDX, SIZARG, MSG_SEND_UNTIL, &arg).i[LOW]; 00235 } 00236 00237 RTAI_PROTO(int, rt_msg_send_timed, (RT_MSGQ *msgq, void *msg, int msg_size, int msgprio, RTIME delay)) 00238 { 00239 struct { RT_MSGQ *msgq; void *msg; long msg_size; long msgprio; RTIME delay; long space; } arg = { msgq, msg, msg_size, msgprio, delay, 0 }; 00240 return rtai_lxrt(BIDX, SIZARG, MSG_SEND_TIMED, &arg).i[LOW]; 00241 } 00242 00243 RTAI_PROTO(int, rt_msg_receive, (RT_MSGQ *msgq, void *msg, int msg_size, int *msgprio)) 00244 { 00245 struct { RT_MSGQ *msgq; void *msg; long msg_size; int *msgprio; long space; } arg = { msgq, msg, msg_size, msgprio, 0 }; 00246 return rtai_lxrt(BIDX, SIZARG, MSG_RECEIVE, &arg).i[LOW]; 00247 } 00248 00249 RTAI_PROTO(int, rt_msg_receive_if, (RT_MSGQ *msgq, void *msg, int msg_size, int *msgprio)) 00250 { 00251 struct { RT_MSGQ *msgq; void *msg; long msg_size; int *msgprio; long space; } arg = { msgq, msg, msg_size, msgprio, 0 }; 00252 return rtai_lxrt(BIDX, SIZARG, MSG_RECEIVE_IF, &arg).i[LOW]; 00253 } 00254 00255 RTAI_PROTO(int, rt_msg_receive_until, (RT_MSGQ *msgq, void *msg, int msg_size, int *msgprio, RTIME until)) 00256 { 00257 struct { RT_MSGQ *msgq; void *msg; long msg_size; int *msgprio; RTIME until; long space; } arg = { msgq, msg, msg_size, msgprio, until, 0 }; 00258 return rtai_lxrt(BIDX, SIZARG, MSG_RECEIVE_UNTIL, &arg).i[LOW]; 00259 } 00260 00261 RTAI_PROTO(int, rt_msg_receive_timed, (RT_MSGQ *msgq, void *msg, int msg_size, int *msgprio, RTIME delay)) 00262 { 00263 struct { RT_MSGQ *msgq; void *msg; long msg_size; int *msgprio; RTIME delay; long space; } arg = { msgq, msg, msg_size, msgprio, delay, 0 }; 00264 return rtai_lxrt(BIDX, SIZARG, MSG_RECEIVE_TIMED, &arg).i[LOW]; 00265 } 00266 00267 RTAI_PROTO(int, rt_msg_evdrp, (RT_MSGQ *msgq, void *msg, int msg_size, int *msgprio)) 00268 { 00269 struct { RT_MSGQ *msgq; void *msg; long msg_size; int *msgprio; long space; } arg = { msgq, msg, msg_size, msgprio, 0 }; 00270 return rtai_lxrt(BIDX, SIZARG, MSG_EVDRP, &arg).i[LOW]; 00271 } 00272 00273 RTAI_PROTO(int, rt_msg_broadcast, (RT_MSGQ *msgq, void *msg, int msg_size, int msgprio)) 00274 { 00275 struct { RT_MSGQ *msgq; void *msg; long msg_size; long msgprio; long space; } arg = { msgq, msg, msg_size, msgprio, 0 }; 00276 return rtai_lxrt(BIDX, SIZARG, MSG_BROADCAST, &arg).i[LOW]; 00277 } 00278 00279 RTAI_PROTO(int, rt_msg_broadcast_if, (RT_MSGQ *msgq, void *msg, int msg_size, int msgprio)) 00280 { 00281 struct { RT_MSGQ *msgq; void *msg; long msg_size; long msgprio; long space; } arg = { msgq, msg, msg_size, msgprio, 0 }; 00282 return rtai_lxrt(BIDX, SIZARG, MSG_BROADCAST_IF, &arg).i[LOW]; 00283 } 00284 00285 RTAI_PROTO(int, rt_msg_broadcast_until, (RT_MSGQ *msgq, void *msg, int msg_size, int msgprio, RTIME until)) 00286 { 00287 struct { RT_MSGQ *msgq; void *msg; long msg_size; long msgprio; RTIME until; long space; } arg = { msgq, msg, msg_size, msgprio, until, 0 }; 00288 return rtai_lxrt(BIDX, SIZARG, MSG_BROADCAST_UNTIL, &arg).i[LOW]; 00289 } 00290 00291 RTAI_PROTO(int, rt_msg_broadcast_timed, (RT_MSGQ *msgq, void *msg, int msg_size, int msgprio, RTIME delay)) 00292 { 00293 struct { RT_MSGQ *msgq; void *msg; long msg_size; long msgprio; RTIME delay; long space; } arg = { msgq, msg, msg_size, msgprio, delay, 0 }; 00294 return rtai_lxrt(BIDX, SIZARG, MSG_BROADCAST_TIMED, &arg).i[LOW]; 00295 } 00296 00297 #ifdef __cplusplus 00298 } 00299 #endif /* __cplusplus */ 00300 00301 #endif /* __KERNEL__ */ 00302 00303 #define rt_tbx_init(tbx, size, flags) rt_msgq_init(tbx, size, 0) 00304 #define rt_tbx_delete(tbx) rt_msgq_delete(tbx) 00305 00306 #define rt_tbx_send(tbx, msg, msg_size) rt_msg_send(tbx, msg, msg_size, 1) 00307 #define rt_tbx_send_if(tbx, msg, msg_size) rt_msg_send_if(tbx, msg, msg_size, 1) 00308 #define rt_tbx_send_until(tbx, msg, msg_size, until) rt_msg_send_until(tbx, msg, msg_size, 1, until) 00309 #define rt_tbx_send_timed(tbx, msg, msg_size, delay) rt_msg_send_timed(tbx, msg, msg_size, 1, delay) 00310 00311 #define rt_tbx_receive(tbx, msg, msg_size) rt_msg_receive(tbx, msg, msg_size, 0) 00312 #define rt_tbx_receive_if(tbx, msg, msg_size) rt_msg_receive_if(tbx, msg, msg_size, 0) 00313 #define rt_tbx_receive_until(tbx, msg, msg_size, until) rt_msg_receive_until(tbx, msg, msg_size, 0, until) 00314 #define rt_tbx_receive_timed(tbx, msg, msg_size, delay) rt_msg_receive_timed(tbx, msg, msg_size, 0, delay) 00315 00316 #define rt_tbx_broadcast(tbx, msg, msg_size) rt_msg_broadcast(tbx, msg, msg_size, 0) 00317 #define rt_tbx_broadcast_if(tbx, msg, msg_size) rt_msg_broadcast_if(tbx, msg, msg_size, 0) 00318 #define rt_tbx_broadcast_until(tbx, msg, msg_size, until) rt_msg_broadcast_until(tbx, msg, msg_size, 0, until) 00319 #define rt_tbx_broadcast_timed(tbx, msg, msg_size, delay) rt_msg_broadcast_timed(tbx, msg, msg_size, 0, delay) 00320 00321 #define rt_tbx_urgent(tbx, msg, msg_size) rt_msg_send(tbx, msg, msg_size, 0) 00322 #define rt_tbx_urgent_if(tbx, msg, msg_size) rt_msg_send_if(tbx, msg, msg_size, 0) 00323 #define rt_tbx_urgent_until(tbx, msg, msg_size, until) rt_msg_send_until(tbx, msg, msg_size, 0, until) 00324 #define rt_tbx_urgent_timed(tbx, msg, msg_size, delay) rt_msg_send_timed(tbx, msg, msg_size, 0, delay) 00325 00326 #endif /* !_RTAI_RT_MSGQ_H */

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