00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _RTAI_MBX_H
00025 #define _RTAI_MBX_H
00026
00027 #include <rtai_sem.h>
00028
00029 #define RT_MBX_MAGIC 0x3f81aab // nam2num("rtmbx")
00030
00031 struct rt_task_struct;
00032 struct rt_mailbox;
00033
00034 #ifdef __KERNEL__
00035
00036 #ifndef __cplusplus
00037
00038 typedef struct rt_mailbox {
00039 int magic;
00040 SEM sndsem, rcvsem;
00041 struct rt_task_struct *waiting_task, *owndby;
00042 char *bufadr;
00043 int size, fbyte, lbyte, avbs, frbs;
00044 spinlock_t lock;
00045 #ifdef CONFIG_RTAI_RT_POLL
00046 struct rt_poll_ql poll_recv;
00047 struct rt_poll_ql poll_send;
00048 #endif
00049 } MBX;
00050
00051 #else
00052 extern "C" {
00053 #endif
00054
00055 int __rtai_mbx_init(void);
00056
00057 void __rtai_mbx_exit(void);
00058
00059 RTAI_SYSCALL_MODE int rt_typed_mbx_init(struct rt_mailbox *mbx, int size, int qtype);
00060
00061 int rt_mbx_init(struct rt_mailbox *mbx, int size);
00062
00063 RTAI_SYSCALL_MODE int rt_mbx_delete(struct rt_mailbox *mbx);
00064
00065 RTAI_SYSCALL_MODE int _rt_mbx_send(struct rt_mailbox *mbx, void *msg, int msg_size, int space);
00066 static inline int rt_mbx_send(struct rt_mailbox *mbx, void *msg, int msg_size)
00067 {
00068 return _rt_mbx_send(mbx, msg, msg_size, 1);
00069 }
00070
00071 RTAI_SYSCALL_MODE int _rt_mbx_send_wp(struct rt_mailbox *mbx, void *msg, int msg_size, int space);
00072 static inline int rt_mbx_send_wp(struct rt_mailbox *mbx, void *msg, int msg_size)
00073 {
00074 return _rt_mbx_send_wp(mbx, msg, msg_size, 1);
00075 }
00076
00077 RTAI_SYSCALL_MODE int _rt_mbx_send_if(struct rt_mailbox *mbx, void *msg, int msg_size, int space);
00078 static inline int rt_mbx_send_if(struct rt_mailbox *mbx, void *msg, int msg_size)
00079 {
00080 return _rt_mbx_send_if(mbx, msg, msg_size, 1);
00081 }
00082
00083 RTAI_SYSCALL_MODE int _rt_mbx_send_until(struct rt_mailbox *mbx, void *msg, int msg_size, RTIME timei, int space);
00084 static inline int rt_mbx_send_until(struct rt_mailbox *mbx, void *msg, int msg_size, RTIME time)
00085 {
00086 return _rt_mbx_send_until(mbx, msg, msg_size, time, 1);
00087 }
00088
00089 RTAI_SYSCALL_MODE int _rt_mbx_send_timed(struct rt_mailbox *mbx, void *msg, int msg_size, RTIME delay, int space);
00090 static inline int rt_mbx_send_timed(struct rt_mailbox *mbx, void *msg, int msg_size, RTIME delay)
00091 {
00092 return _rt_mbx_send_timed(mbx, msg, msg_size, delay, 1);
00093 }
00094
00095 RTAI_SYSCALL_MODE int _rt_mbx_ovrwr_send(struct rt_mailbox *mbx, void *msg, int msg_size, int space);
00096 static inline int rt_mbx_ovrwr_send(struct rt_mailbox *mbx, void *msg, int msg_size)
00097 {
00098 return _rt_mbx_ovrwr_send(mbx, msg, msg_size, 1);
00099 }
00100
00101 RTAI_SYSCALL_MODE int _rt_mbx_evdrp(struct rt_mailbox *mbx, void *msg, int msg_size, int space);
00102 static inline int rt_mbx_evdrp(struct rt_mailbox *mbx, void *msg, int msg_size)
00103 {
00104 return _rt_mbx_evdrp(mbx, msg, msg_size, 1);
00105 }
00106
00107 RTAI_SYSCALL_MODE int _rt_mbx_receive(struct rt_mailbox *mbx, void *msg, int msg_size, int space);
00108 static inline int rt_mbx_receive(struct rt_mailbox *mbx, void *msg, int msg_size)
00109 {
00110 return _rt_mbx_receive(mbx, msg, msg_size, 1);
00111 }
00112
00113 RTAI_SYSCALL_MODE int _rt_mbx_receive_wp(struct rt_mailbox *mbx, void *msg, int msg_size, int space);
00114 static inline int rt_mbx_receive_wp(struct rt_mailbox *mbx, void *msg, int msg_size)
00115 {
00116 return _rt_mbx_receive_wp(mbx, msg, msg_size, 1);
00117 }
00118
00119 RTAI_SYSCALL_MODE int _rt_mbx_receive_if(struct rt_mailbox *mbx, void *msg, int msg_size, int space);
00120 static inline int rt_mbx_receive_if(struct rt_mailbox *mbx, void *msg, int msg_size)
00121 {
00122 return _rt_mbx_receive_if(mbx, msg, msg_size, 1);
00123 }
00124
00125 RTAI_SYSCALL_MODE int _rt_mbx_receive_until(struct rt_mailbox *mbx, void *msg, int msg_size, RTIME time, int space);
00126 static inline int rt_mbx_receive_until(struct rt_mailbox *mbx, void *msg, int msg_size, RTIME time)
00127 {
00128 return _rt_mbx_receive_until(mbx, msg, msg_size, time, 1);
00129 }
00130
00131 RTAI_SYSCALL_MODE int _rt_mbx_receive_timed(struct rt_mailbox *mbx, void *msg, int msg_size, RTIME delay, int space);
00132 static inline int rt_mbx_receive_timed(struct rt_mailbox *mbx, void *msg, int msg_size, RTIME delay)
00133 {
00134 return _rt_mbx_receive_timed(mbx, msg, msg_size, delay, 1);
00135 }
00136
00137 RTAI_SYSCALL_MODE struct rt_mailbox *_rt_typed_named_mbx_init(unsigned long mbx_name, int size, int qtype);
00138 static inline struct rt_mailbox *rt_typed_named_mbx_init(const char *mbx_name, int size, int qtype)
00139 {
00140 return _rt_typed_named_mbx_init(nam2num(mbx_name), size, qtype);
00141 }
00142
00143 RTAI_SYSCALL_MODE int rt_named_mbx_delete(struct rt_mailbox *mbx);
00144
00145 #define rt_named_mbx_init(mbx_name, size) rt_typed_named_mbx_init(mbx_name, size, FIFO_Q)
00146
00147 #ifdef __cplusplus
00148 }
00149 #endif
00150
00151 #else
00152
00153 #include <rtai_lxrt.h>
00154
00155 #ifdef __cplusplus
00156 extern "C" {
00157 #endif
00158
00159 RTAI_PROTO(struct rt_mailbox *, rt_typed_mbx_init, (unsigned long name, int size, int qtype))
00160 {
00161 struct { unsigned long name; long size; long qtype; } arg = { name, size, qtype };
00162 return (struct rt_mailbox *)rtai_lxrt(BIDX, SIZARG, LXRT_MBX_INIT, &arg).v[LOW];
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 #define rt_mbx_init(name, size) rt_typed_mbx_init(name, size, FIFO_Q)
00180
00181 RTAI_PROTO(int, rt_mbx_delete, (struct rt_mailbox *mbx))
00182 {
00183 void *arg = mbx;
00184 return rtai_lxrt(BIDX, SIZARG, LXRT_MBX_DELETE, &arg).i[LOW];
00185 }
00186
00187 RTAI_PROTO(struct rt_mailbox *, rt_typed_named_mbx_init, (const char *name, int size, int type))
00188 {
00189 struct { unsigned long name; long size, type; } arg = { nam2num(name), size, type };
00190 return (struct rt_mailbox *)rtai_lxrt(BIDX, SIZARG, NAMED_MBX_INIT, &arg).v[LOW];
00191 }
00192
00193 RTAI_PROTO(int, rt_named_mbx_delete, (struct rt_mailbox *mbx))
00194 {
00195 struct { struct rt_mailbox *mbx; } arg = { mbx };
00196 return rtai_lxrt(BIDX, SIZARG, NAMED_MBX_DELETE, &arg).i[LOW];
00197 }
00198
00199 #define rt_named_mbx_init(mbx_name, size) \
00200 rt_typed_named_mbx_init(mbx_name, size, FIFO_Q)
00201
00202 RTAI_PROTO(int, rt_mbx_send, (struct rt_mailbox *mbx, void *msg, int msg_size))
00203 {
00204 struct { struct rt_mailbox *mbx; char *msg; long msg_size; long space; } arg = { mbx, (char *)msg, msg_size, 0 };
00205 return (int)rtai_lxrt(BIDX, SIZARG, MBX_SEND, &arg).i[LOW];
00206 }
00207
00208 RTAI_PROTO(int, rt_mbx_send_wp, (struct rt_mailbox *mbx, void *msg, int msg_size))
00209 {
00210 struct { struct rt_mailbox *mbx; char *msg; long msg_size; long space; } arg = { mbx, (char *)msg, msg_size, 0 };
00211 return (int)rtai_lxrt(BIDX, SIZARG, MBX_SEND_WP, &arg).i[LOW];
00212 }
00213
00214 RTAI_PROTO(int, rt_mbx_send_if, (struct rt_mailbox *mbx, void *msg, int msg_size))
00215 {
00216 struct { struct rt_mailbox *mbx; char *msg; long msg_size; long space; } arg = { mbx, (char *)msg, msg_size, 0 };
00217 return (int)rtai_lxrt(BIDX, SIZARG, MBX_SEND_IF, &arg).i[LOW];
00218 }
00219
00220 RTAI_PROTO(int, rt_mbx_send_until, (struct rt_mailbox *mbx, void *msg, int msg_size, RTIME time))
00221 {
00222 struct { struct rt_mailbox *mbx; char *msg; long msg_size; RTIME time; long space; } arg = { mbx, (char *)msg, msg_size, time, 0 };
00223 return (int)rtai_lxrt(BIDX, SIZARG, MBX_SEND_UNTIL, &arg).i[LOW];
00224 }
00225
00226 RTAI_PROTO(int, rt_mbx_send_timed, (struct rt_mailbox *mbx, void *msg, int msg_size, RTIME delay))
00227 {
00228 struct { struct rt_mailbox *mbx; char *msg; long msg_size; RTIME delay; long space; } arg = { mbx, (char *)msg, msg_size, delay, 0 };
00229 return (int)rtai_lxrt(BIDX, SIZARG, MBX_SEND_TIMED, &arg).i[LOW];
00230 }
00231
00232 RTAI_PROTO(int, rt_mbx_ovrwr_send, (struct rt_mailbox *mbx, void *msg, int msg_size))
00233 {
00234 struct { struct rt_mailbox *mbx; char *msg; long msg_size; long space; } arg = { mbx, (char *)msg, msg_size, 0 };
00235 return (int)rtai_lxrt(BIDX, SIZARG, MBX_OVRWR_SEND, &arg).i[LOW];
00236 }
00237
00238 RTAI_PROTO(int, rt_mbx_evdrp, (struct rt_mailbox *mbx, void *msg, int msg_size))
00239 {
00240 struct { struct rt_mailbox *mbx; char *msg; long msg_size; long space; } arg = { mbx, (char *)msg, msg_size, 0 };
00241 return (int)rtai_lxrt(BIDX, SIZARG, MBX_EVDRP, &arg).i[LOW];
00242 }
00243
00244 RTAI_PROTO(int, rt_mbx_receive, (struct rt_mailbox *mbx, void *msg, int msg_size))
00245 {
00246 struct { struct rt_mailbox *mbx; char *msg; long msg_size; long space; } arg = { mbx, (char *)msg, msg_size, 0 };
00247 return (int)rtai_lxrt(BIDX, SIZARG, MBX_RECEIVE, &arg).i[LOW];
00248 }
00249
00250 RTAI_PROTO(int, rt_mbx_receive_wp, (struct rt_mailbox *mbx, void *msg, int msg_size))
00251 {
00252 struct { struct rt_mailbox *mbx; char *msg; long msg_size; long space; } arg = { mbx, (char *)msg, msg_size, 0 };
00253 return (int)rtai_lxrt(BIDX, SIZARG, MBX_RECEIVE_WP, &arg).i[LOW];
00254 }
00255
00256 RTAI_PROTO(int, rt_mbx_receive_if, (struct rt_mailbox *mbx, void *msg, int msg_size))
00257 {
00258 struct { struct rt_mailbox *mbx; char *msg; long msg_size; long space; } arg = { mbx, (char *)msg, msg_size, 0 };
00259 return (int)rtai_lxrt(BIDX, SIZARG, MBX_RECEIVE_IF, &arg).i[LOW];
00260 }
00261
00262 RTAI_PROTO(int, rt_mbx_receive_until, (struct rt_mailbox *mbx, void *msg, int msg_size, RTIME time))
00263 {
00264 struct { struct rt_mailbox *mbx; void *msg; long msg_size; RTIME time; long space; } arg = { mbx, (char *)msg, msg_size, time, 0 };
00265 return (int)rtai_lxrt(BIDX, SIZARG, MBX_RECEIVE_UNTIL, &arg).i[LOW];
00266 }
00267
00268 RTAI_PROTO(int, rt_mbx_receive_timed, (struct rt_mailbox *mbx, void *msg, int msg_size, RTIME delay))
00269 {
00270 struct { struct rt_mailbox *mbx; char *msg; long msg_size; RTIME delay; long space; } arg = { mbx, (char *)msg, msg_size, delay, 0 };
00271 return (int)rtai_lxrt(BIDX, SIZARG, MBX_RECEIVE_TIMED, &arg).i[LOW];
00272 }
00273
00274 #ifdef __cplusplus
00275 }
00276 #endif
00277
00278 #endif
00279
00280 #if !defined(__KERNEL__) || defined(__cplusplus)
00281
00282 typedef struct rt_mailbox {
00283 int opaque;
00284 } MBX;
00285
00286 #endif
00287
00288 #endif