rtai-core/include/rtai_bits.h

00001 /*
00002  * Copyright (C) 1999-2003 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 #ifndef _RTAI_BITS_H
00020 #define _RTAI_BITS_H
00021 
00022 #include <rtai_types.h>
00023 
00024 #define ALL_SET               0
00025 #define ANY_SET               1
00026 #define ALL_CLR               2
00027 #define ANY_CLR               3
00028 
00029 #define ALL_SET_AND_ANY_SET   4
00030 #define ALL_SET_AND_ALL_CLR   5
00031 #define ALL_SET_AND_ANY_CLR   6
00032 #define ANY_SET_AND_ALL_CLR   7
00033 #define ANY_SET_AND_ANY_CLR   8
00034 #define ALL_CLR_AND_ANY_CLR   9
00035 
00036 #define ALL_SET_OR_ANY_SET   10
00037 #define ALL_SET_OR_ALL_CLR   11
00038 #define ALL_SET_OR_ANY_CLR   12
00039 #define ANY_SET_OR_ALL_CLR   13
00040 #define ANY_SET_OR_ANY_CLR   14
00041 #define ALL_CLR_OR_ANY_CLR   15
00042 
00043 #define SET_BITS              0
00044 #define CLR_BITS              1
00045 #define SET_CLR_BITS          2
00046 #define NOP_BITS              3
00047 
00048 #define BITS_ERR     0xFfff  // same as semaphores
00049 #define BITS_TIMOUT  0xFffe  // same as semaphores
00050 
00051 struct rt_bits_struct;
00052 
00053 #ifdef __KERNEL__
00054 
00055 #ifndef __cplusplus
00056 
00057 typedef struct rt_bits_struct {
00058 
00059     struct rt_queue queue;  /* <= Must be first in struct. */
00060     int magic;
00061     int type;  // to align mask to semaphore count, for easier uspace init
00062     unsigned long mask;
00063 
00064 } BITS;
00065 
00066 #else /* __cplusplus */
00067 extern "C" {
00068 #endif /* !__cplusplus */
00069 
00070 int __rtai_bits_init(void);
00071 
00072 void __rtai_bits_exit(void);
00073 
00074 void rt_bits_init(struct rt_bits_struct *bits,
00075                   unsigned long mask);
00076 
00077 int rt_bits_delete(struct rt_bits_struct *bits);
00078 
00079 unsigned long rt_get_bits(struct rt_bits_struct *bits);
00080 
00081 int rt_bits_reset(struct rt_bits_struct *bits,
00082                   unsigned long mask);
00083 
00084 unsigned long rt_bits_signal(struct rt_bits_struct *bits,
00085                              int setfun,
00086                              unsigned long masks);
00087 
00088 int _rt_bits_wait(struct rt_bits_struct *bits, int testfun, unsigned long testmasks, int exitfun, unsigned long exitmasks, unsigned long *resulting_mask, int space);
00089 static inline int rt_bits_wait(struct rt_bits_struct *bits, int testfun, unsigned long testmasks, int exitfun, unsigned long exitmasks, unsigned long *resulting_mask)
00090 {
00091         return  _rt_bits_wait(bits, testfun, testmasks, exitfun, exitmasks, resulting_mask, 1);
00092 }
00093 
00094 int _rt_bits_wait_if(struct rt_bits_struct *bits, int testfun, unsigned long testmasks, int exitfun, unsigned long exitmasks, unsigned long *resulting_mask, int space);
00095 static inline int rt_bits_wait_if(struct rt_bits_struct *bits, int testfun, unsigned long testmasks, int exitfun, unsigned long exitmasks, unsigned long *resulting_mask)
00096 {
00097         return  _rt_bits_wait_if(bits, testfun, testmasks, exitfun, exitmasks, resulting_mask, 1);
00098 }
00099 
00100 int _rt_bits_wait_until(struct rt_bits_struct *bits, int testfun, unsigned long testmasks, int exitfun, unsigned long exitmasks, RTIME time, unsigned long *resulting_mask, int space);
00101 static inline int rt_bits_wait_until(struct rt_bits_struct *bits, int testfun, unsigned long testmasks, int exitfun, unsigned long exitmasks, RTIME time, unsigned long *resulting_mask)
00102 {
00103         return  _rt_bits_wait_until(bits, testfun, testmasks, exitfun, exitmasks, time, resulting_mask, 1);
00104 }
00105 
00106 int _rt_bits_wait_timed(struct rt_bits_struct *bits, int testfun, unsigned long testmasks, int exitfun, unsigned long exitmasks, RTIME delay, unsigned long *resulting_mask, int space);
00107 static inline int rt_bits_wait_timed(struct rt_bits_struct *bits, int testfun, unsigned long testmasks, int exitfun, unsigned long exitmasks, RTIME delay, unsigned long *resulting_mask)
00108 {
00109         return  _rt_bits_wait_timed(bits, testfun, testmasks, exitfun, exitmasks, delay, resulting_mask, 1);
00110 }
00111 
00112 
00113 #ifdef __cplusplus
00114 }
00115 #endif /* __cplusplus */
00116 
00117 #else /* !__KERNEL__ */
00118 
00119 #include <rtai_lxrt.h>
00120 
00121 #define BITSIDX 0
00122 
00123 #ifdef __cplusplus
00124 extern "C" {
00125 #endif /* __cplusplus */
00126 
00127 RTAI_PROTO(struct rt_bits_struct *,rt_bits_init,(unsigned long name, unsigned long mask))
00128 {
00129         struct { unsigned long name, mask; } arg = { name, mask };
00130         return (struct rt_bits_struct *)rtai_lxrt(BITSIDX, SIZARG, BITS_INIT, &arg).v[LOW];
00131 }
00132 
00133 RTAI_PROTO(int, rt_bits_delete,(struct rt_bits_struct *bits))
00134 {
00135         struct { struct rt_bits_struct *bits; } arg = { bits };
00136         return rtai_lxrt(BITSIDX, SIZARG, BITS_DELETE, &arg).i[LOW];
00137 }
00138 
00139 RTAI_PROTO(unsigned long, rt_get_bits,(struct rt_bits_struct *bits))
00140 {
00141         struct { struct rt_bits_struct *bits; } arg = { bits };
00142         return rtai_lxrt(BITSIDX, SIZARG, BITS_GET, &arg).i[LOW];
00143 }
00144 
00145 RTAI_PROTO(int, rt_bits_reset,(struct rt_bits_struct *bits, unsigned long mask))
00146 {
00147         struct { struct rt_bits_struct *bits; unsigned long mask; } arg = { bits, mask };
00148         return rtai_lxrt(BITSIDX, SIZARG, BITS_RESET, &arg).i[LOW];
00149 }
00150 
00151 RTAI_PROTO(unsigned long, rt_bits_signal,(struct rt_bits_struct *bits, int setfun, unsigned long masks))
00152 {
00153         struct { struct rt_bits_struct *bits; int setfun; unsigned long masks; } arg = { bits, setfun, masks };
00154         return rtai_lxrt(BITSIDX, SIZARG, BITS_SIGNAL, &arg).i[LOW];
00155 }
00156 
00157 RTAI_PROTO(int, rt_bits_wait,(struct rt_bits_struct *bits, int testfun, unsigned long testmasks, int exitfun,
00158                               unsigned long exitmasks, unsigned long *resulting_mask))
00159 {
00160         struct { struct rt_bits_struct *bits; int testfun; unsigned long testmasks; int exitfun;
00161             unsigned long exitmasks; unsigned long *resulting_mask; int space; } arg =
00162                 { bits, testfun, testmasks, exitfun, exitmasks, resulting_mask, 0 };
00163         return rtai_lxrt(BITSIDX, SIZARG, BITS_WAIT, &arg).i[LOW];
00164 }
00165 
00166 RTAI_PROTO(int, rt_bits_wait_if,(struct rt_bits_struct *bits, int testfun, unsigned long testmasks, int exitfun,
00167                                  unsigned long exitmasks, unsigned long *resulting_mask))
00168 {
00169         struct { struct rt_bits_struct *bits; int testfun; unsigned long testmasks; int exitfun;
00170             unsigned long exitmasks; unsigned long *resulting_mask; int space; } arg =
00171                 { bits, testfun, testmasks, exitfun, exitmasks, resulting_mask, 0 };
00172         return rtai_lxrt(BITSIDX, SIZARG, BITS_WAIT_IF, &arg).i[LOW];
00173 }
00174 
00175 RTAI_PROTO(int, rt_bits_wait_until,(struct rt_bits_struct *bits, int testfun, unsigned long testmasks, int exitfun,
00176                                     unsigned long exitmasks, RTIME time, unsigned long *resulting_mask))
00177 {
00178         struct { struct rt_bits_struct *bits; int testfun; unsigned long testmasks; int exitfun;
00179             unsigned long exitmasks; RTIME time; unsigned long *resulting_mask; int space; } arg =
00180                 { bits, testfun, testmasks, exitfun, exitmasks, time, resulting_mask, 0 };
00181         return rtai_lxrt(BITSIDX, SIZARG, BITS_WAIT_UNTIL, &arg).i[LOW];
00182 }
00183 
00184 RTAI_PROTO(int, rt_bits_wait_timed,(struct rt_bits_struct *bits, int testfun, unsigned long testmasks, int exitfun,
00185                                     unsigned long exitmasks, RTIME delay, unsigned long *resulting_mask))
00186 {
00187         struct { struct rt_bits_struct *bits; int testfun; unsigned long testmasks; int exitfun;
00188             unsigned long exitmasks; RTIME delay; unsigned long *resulting_mask; int space; } arg =
00189                 { bits, testfun, testmasks, exitfun, exitmasks, delay, resulting_mask, 0 };
00190         return rtai_lxrt(BITSIDX, SIZARG, BITS_WAIT_TIMED, &arg).i[LOW];
00191 }
00192 
00193 #ifdef __cplusplus
00194 }
00195 #endif /* __cplusplus */
00196 
00197 #endif /* __KERNEL__ */
00198 
00199 #if !defined(__KERNEL__) || defined(__cplusplus)
00200 
00201 typedef struct rt_bits_struct {
00202     int opaque;
00203 } BITS;
00204 
00205 #endif /* !__KERNEL__ || __cplusplus */
00206 
00207 #endif /* !_RTAI_BITS_H */

Generated on Sat Jul 24 19:36:02 2004 for RTAI API by doxygen 1.3.4