base/include/rtai_mbx.h

Go to the documentation of this file.
00001 /**
00002  * @ingroup lxrt
00003  * @file
00004  *
00005  * @author Paolo Mantegazza
00006  *
00007  * @note Copyright &copy; 1999-2003 Paolo Mantegazza <mantegazza@aero.polimi.it>
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public License as
00011  * published by the Free Software Foundation; either version 2 of the
00012  * License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 /* __cplusplus */
00052 extern "C" {
00053 #endif /* !__cplusplus */
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 /* __cplusplus */
00150 
00151 #else /* !__KERNEL__ */
00152 
00153 #include <rtai_lxrt.h>
00154 
00155 #ifdef __cplusplus
00156 extern "C" {
00157 #endif /* __cplusplus */
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  * @ingroup lxrt
00167  * Initialize mailbox.
00168  * 
00169  * Initializes a mailbox referred to by @a name of size @a size.
00170  * 
00171  * It is important to remark that the returned task pointer cannot be used
00172  * directly, they are for kernel space data, but just passed as arguments when
00173  * needed.
00174  *
00175  * @return On success a pointer to the mail box to be used in related calls.
00176  * @return A 0 value is returned if it was not possible to setup the semaphore
00177  * or something using the same name was found.
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 /* __cplusplus */
00277 
00278 #endif /* __KERNEL__ */
00279 
00280 #if !defined(__KERNEL__) || defined(__cplusplus)
00281 
00282 typedef struct rt_mailbox {
00283     int opaque;
00284 } MBX;
00285 
00286 #endif /* !__KERNEL__ || __cplusplus */
00287 
00288 #endif /* !_RTAI_MBX_H */

Generated on Tue Feb 2 17:46:05 2010 for RTAI API by  doxygen 1.4.7