base/include/rtai_bits.h

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

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