# rtai_tbx.h

    00001 /*
    00002  * Copyright (C) 2001  G.M. Bertani <gmbertani@yahoo.it>
    00003  * Copyright (C) 2002  P. Mantegazza <mantegazza@aero.polimi.it>
    00004  *                       (LXRT extensions).
    00005  *
    00006  * This program is free software; you can redistribute it and/or
    00007  * modify it under the terms of the GNU General Public License as
    00008  * published by the Free Software Foundation; either version 2 of the
    00009  * License, or (at your option) any later version.
    00010  *
    00011  * This program is distributed in the hope that it will be useful,
    00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014  * GNU General Public License for more details.
    00015  *
    00016  * You should have received a copy of the GNU General Public License
    00017  * along with this program; if not, write to the Free Software
    00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00019  */
    00020
    00021 #ifndef _RTAI_TBX_H
    00022 #define _RTAI_TBX_H
    00023
    00024 #include <rtai_types.h>
    00025
    00026 /* TYPED MAILBOXES */
    00027
    00028 #define RT_TBX_MAGIC 0x6e93ad4b
    00029
    00030 #define TYPE_NONE      0x00
    00031 #define TYPE_NORMAL    0x01
    00032 #define TYPE_BROADCAST 0x02
    00033 #define TYPE_URGENT    0x04
    00034
    00035 #ifdef __KERNEL__
    00036
    00037 struct rt_typed_mailbox;
    00038
    00039 #ifndef __cplusplus
    00040
    00041 #include <rtai_sem.h>
    00042
    00043 typedef struct rt_typed_mailbox {
    00044
    00045     int magic;
    00046     int waiting_nr;   /* number of tasks waiting for a broadcast */
    00047     SEM sndsmx, rcvsmx;
    00048     SEM bcbsmx;       /* binary sem needed to wakeup the sleeping tasks
    00049                       when the broadcasting of a message is terminated */
    00050     RT_TASK *waiting_task;
    00051     char *bufadr;     /* mailbox buffer */
    00052     char *bcbadr;     /* broadcasting buffer */
    00053     int size;         /* mailbox size */
    00054     int fbyte;        /* circular buffer read pointer */
    00055     int avbs;         /* bytes occupied */
    00056     int frbs;         /* bytes free */
    00057     spinlock_t buflock;
    00058
    00059 } TBX;
    00060
    00061 #else /* __cplusplus */
    00062 extern "C" {
    00063 #endif /* !__cplusplus */
    00064
    00065 int __rtai_tbx_init(void);
    00066
    00067 void __rtai_tbx_exit(void);
    00068
    00069 /*
    00070  * send_wp and receive_wp are not implemented because
    00071  * the packed message must be sent/received atomically
    00072  */
    00073
    00074 int rt_tbx_init(struct rt_typed_mailbox *tbx,
    00075                 int size,
    00076                 int flags);
    00077
    00078 int rt_tbx_delete(struct rt_typed_mailbox *tbx);
    00079
    00080 int rt_tbx_send(struct rt_typed_mailbox *tbx,
    00081                 void *msg,
    00082                 int msg_size);
    00083
    00084 int rt_tbx_send_if(struct rt_typed_mailbox *tbx,
    00085                    void *msg,
    00086                    int msg_size);
    00087
    00088 int rt_tbx_send_until(struct rt_typed_mailbox *tbx,
    00089                       void *msg,
    00090                       int msg_size,
    00091                       RTIME time);
    00092
    00093 int rt_tbx_send_timed(struct rt_typed_mailbox *tbx,
    00094                       void *msg,
    00095                       int msg_size,
    00096                       RTIME delay);
    00097
    00098 int rt_tbx_receive(struct rt_typed_mailbox *tbx,
    00099                    void *msg,
    00100                    int msg_size);
    00101
    00102 int rt_tbx_receive_if(struct rt_typed_mailbox *tbx,
    00103                       void *msg,
    00104                       int msg_size);
    00105
    00106 int rt_tbx_receive_until(struct rt_typed_mailbox *tbx,
    00107                          void *msg,
    00108                          int msg_size,
    00109                          RTIME time);
    00110
    00111 int rt_tbx_receive_timed(struct rt_typed_mailbox *tbx,
    00112                          void *msg,
    00113                          int msg_size,
    00114                          RTIME delay);
    00115
    00116 int rt_tbx_broadcast(struct rt_typed_mailbox *tbx,
    00117                      void *msg,
    00118                      int msg_size);
    00119
    00120 int rt_tbx_broadcast_if(struct rt_typed_mailbox *tbx,
    00121                         void *msg,
    00122                         int msg_size);
    00123
    00124 int rt_tbx_broadcast_until(struct rt_typed_mailbox *tbx,
    00125                            void *msg,
    00126                            int msg_size,
    00127                            RTIME time);
    00128
    00129 int rt_tbx_broadcast_timed(struct rt_typed_mailbox *tbx,
    00130                            void *msg,
    00131                            int msg_size,
    00132                            RTIME delay);
    00133
    00134 int rt_tbx_urgent(struct rt_typed_mailbox *tbx,
    00135                   void *msg,
    00136                   int msg_size);
    00137
    00138 int rt_tbx_urgent_if(struct rt_typed_mailbox *tbx,
    00139                      void *msg,
    00140                      int msg_size);
    00141
    00142 int rt_tbx_urgent_until(struct rt_typed_mailbox *tbx,
    00143                         void *msg,
    00144                         int msg_size,
    00145                         RTIME time);
    00146
    00147 int rt_tbx_urgent_timed(struct rt_typed_mailbox *tbx,
    00148                         void *msg,
    00149                         int msg_size,
    00150                         RTIME delay);
    00151
    00152 #ifdef __cplusplus
    00153 }
    00154 #endif /* __cplusplus */
    00155
    00156 #else /* !__KERNEL__ */
    00157
    00158 #include <rtai_lxrt.h>
    00159
    00160 #define TBXIDX 0
    00161
    00162 #ifdef __cplusplus
    00163 extern "C" {
    00164 #endif /* __cplusplus */
    00165
    00166 RTAI_PROTO(struct rt_typed_mailbox *, rt_tbx_init,(unsigned long name, int size, int flags))
    00167 {
    00168         struct { unsigned long name; int size; int flags; } arg = { name, size, flags };
    00169         return (struct rt_typed_mailbox *)rtai_lxrt(TBXIDX, SIZARG, TBX_INIT, &arg).v[LOW];
    00170 }
    00171
    00172 RTAI_PROTO(int, rt_tbx_delete,(struct rt_typed_mailbox *tbx))
    00173 {
    00174         struct { struct rt_typed_mailbox *tbx; } arg = { tbx };
    00175         return rtai_lxrt(TBXIDX, SIZARG, TBX_DELETE, &arg).i[LOW];
    00176 }
    00177
    00178 RTAI_PROTO(int, rt_tbx_send,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
    00179 {
    00180         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
    00181         return rtai_lxrt(TBXIDX, SIZARG, TBX_SEND, &arg).i[LOW];
    00182 }
    00183
    00184 RTAI_PROTO(int, rt_tbx_send_if,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
    00185 {
    00186         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
    00187         return rtai_lxrt(TBXIDX, SIZARG, TBX_SEND_IF, &arg).i[LOW];
    00188 }
    00189
    00190 RTAI_PROTO(int, rt_tbx_send_until,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME time))
    00191 {
    00192         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME time; } arg = { tbx, msg, msg_size, time };
    00193         return rtai_lxrt(TBXIDX, SIZARG, TBX_SEND_UNTIL, &arg).i[LOW];
    00194 }
    00195
    00196 RTAI_PROTO(int, rt_tbx_send_timed,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME delay))
    00197 {
    00198         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME delay; } arg = { tbx, msg, msg_size, delay };
    00199         return rtai_lxrt(TBXIDX, SIZARG, TBX_SEND_TIMED, &arg).i[LOW];
    00200 }
    00201
    00202 RTAI_PROTO(int, rt_tbx_receive,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
    00203 {
    00204         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
    00205         return rtai_lxrt(TBXIDX, SIZARG, TBX_RECEIVE, &arg).i[LOW];
    00206 }
    00207
    00208 RTAI_PROTO(int, rt_tbx_receive_if,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
    00209 {
    00210         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
    00211         return rtai_lxrt(TBXIDX, SIZARG, TBX_RECEIVE_IF, &arg).i[LOW];
    00212 }
    00213
    00214 RTAI_PROTO(int, rt_tbx_receive_until,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME time))
    00215 {
    00216         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME time; } arg = { tbx, msg, msg_size, time };
    00217         return rtai_lxrt(TBXIDX, SIZARG, TBX_RECEIVE_UNTIL, &arg).i[LOW];
    00218 }
    00219
    00220 RTAI_PROTO(int, rt_tbx_receive_timed,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME delay))
    00221 {
    00222         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME delay; } arg = { tbx, msg, msg_size, delay };
    00223         return rtai_lxrt(TBXIDX, SIZARG, TBX_RECEIVE_TIMED, &arg).i[LOW];
    00224 }
    00225
    00226 RTAI_PROTO(int, rt_tbx_broadcast,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
    00227 {
    00228         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
    00229         return rtai_lxrt(TBXIDX, SIZARG, TBX_BROADCAST, &arg).i[LOW];
    00230 }
    00231
    00232 RTAI_PROTO(int, rt_tbx_broadcast_if,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
    00233 {
    00234         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
    00235         return rtai_lxrt(TBXIDX, SIZARG, TBX_BROADCAST_IF, &arg).i[LOW];
    00236 }
    00237
    00238 RTAI_PROTO(int, rt_tbx_broadcast_until,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME time))
    00239 {
    00240         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME time; } arg = { tbx, msg, msg_size, time };
    00241         return rtai_lxrt(TBXIDX, SIZARG, TBX_BROADCAST_UNTIL, &arg).i[LOW];
    00242 }
    00243
    00244 RTAI_PROTO(int, rt_tbx_broadcast_timed,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME delay))
    00245 {
    00246         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME delay; } arg = { tbx, msg, msg_size, delay };
    00247         return rtai_lxrt(TBXIDX, SIZARG, TBX_BROADCAST_TIMED, &arg).i[LOW];
    00248 }
    00249
    00250 RTAI_PROTO(int, rt_tbx_urgent,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
    00251 {
    00252         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
    00253         return rtai_lxrt(TBXIDX, SIZARG, TBX_URGENT, &arg).i[LOW];
    00254 }
    00255
    00256 RTAI_PROTO(int, rt_tbx_urgent_if,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
    00257 {
    00258         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
    00259         return rtai_lxrt(TBXIDX, SIZARG, TBX_URGENT_IF, &arg).i[LOW];
    00260 }
    00261
    00262 RTAI_PROTO(int, rt_tbx_urgent_until,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME time))
    00263 {
    00264         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME time; } arg = { tbx, msg, msg_size, time };
    00265         return rtai_lxrt(TBXIDX, SIZARG, TBX_URGENT_UNTIL, &arg).i[LOW];
    00266 }
    00267
    00268 RTAI_PROTO(int, rt_tbx_urgent_timed,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME delay))
    00269 {
    00270         struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME delay; } arg = { tbx, msg, msg_size, delay };
    00271         return rtai_lxrt(TBXIDX, SIZARG, TBX_URGENT_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_typed_mailbox {
    00283     int opaque;
    00284 } TBX;
    00285
    00286 #endif /* !__KERNEL__ || __cplusplus */
    00287
    00288 #endif /* !_RTAI_TBX_H */