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     (RTE_OBJINV)  // same as semaphores
00051 #define BITS_TIMOUT  (RTE_TIMOUT)  // 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, unsigned long mask);
00077 
00078 int rt_bits_delete(struct rt_bits_struct *bits);
00079 
00080 RTAI_SYSCALL_MODE unsigned long rt_get_bits(struct rt_bits_struct *bits);
00081 
00082 RTAI_SYSCALL_MODE unsigned long rt_bits_reset(struct rt_bits_struct *bits, unsigned long mask);
00083 
00084 RTAI_SYSCALL_MODE unsigned long rt_bits_signal(struct rt_bits_struct *bits, int setfun, unsigned long masks);
00085 
00086 RTAI_SYSCALL_MODE 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);
00087 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)
00088 {
00089     return  _rt_bits_wait(bits, testfun, testmasks, exitfun, exitmasks, resulting_mask, 1);
00090 }
00091 
00092 RTAI_SYSCALL_MODE 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);
00093 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)
00094 {
00095     return  _rt_bits_wait_if(bits, testfun, testmasks, exitfun, exitmasks, resulting_mask, 1);
00096 }
00097 
00098 RTAI_SYSCALL_MODE 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);
00099 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)
00100 {
00101     return  _rt_bits_wait_until(bits, testfun, testmasks, exitfun, exitmasks, time, resulting_mask, 1);
00102 }
00103 
00104 RTAI_SYSCALL_MODE 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);
00105 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)
00106 {
00107     return  _rt_bits_wait_timed(bits, testfun, testmasks, exitfun, exitmasks, delay, resulting_mask, 1);
00108 }
00109 
00110 #ifdef __cplusplus
00111 }
00112 #endif /* __cplusplus */
00113 
00114 #else /* !__KERNEL__ */
00115 
00116 #include <rtai_lxrt.h>
00117 
00118 #define BITSIDX 0
00119 
00120 #ifdef __cplusplus
00121 extern "C" {
00122 #endif /* __cplusplus */
00123 
00124 RTAI_PROTO(struct rt_bits_struct *,rt_bits_init,(unsigned long name, unsigned long mask))
00125 {
00126     struct { unsigned long name, mask; } arg = { name, mask };
00127     return (struct rt_bits_struct *)rtai_lxrt(BITSIDX, SIZARG, BITS_INIT, &arg).v[LOW];
00128 }
00129 
00130 RTAI_PROTO(int, rt_bits_delete,(struct rt_bits_struct *bits))
00131 {
00132     struct { struct rt_bits_struct *bits; } arg = { bits };
00133     return rtai_lxrt(BITSIDX, SIZARG, BITS_DELETE, &arg).i[LOW];
00134 }
00135 
00136 RTAI_PROTO(unsigned long, rt_get_bits,(struct rt_bits_struct *bits))
00137 {
00138     struct { struct rt_bits_struct *bits; } arg = { bits };
00139     return rtai_lxrt(BITSIDX, SIZARG, BITS_GET, &arg).i[LOW];
00140 }
00141 
00142 RTAI_PROTO(unsigned long, rt_bits_reset,(struct rt_bits_struct *bits, unsigned long mask))
00143 {
00144     struct { struct rt_bits_struct *bits; unsigned long mask; } arg = { bits, mask };
00145     return (unsigned long)rtai_lxrt(BITSIDX, SIZARG, BITS_RESET, &arg).i[LOW];
00146 }
00147 
00148 RTAI_PROTO(unsigned long, rt_bits_signal,(struct rt_bits_struct *bits, int setfun, unsigned long masks))
00149 {
00150     struct { struct rt_bits_struct *bits; long setfun; unsigned long masks; } arg = { bits, setfun, masks };
00151     return rtai_lxrt(BITSIDX, SIZARG, BITS_SIGNAL, &arg).i[LOW];
00152 }
00153 
00154 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))
00155 {
00156     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 };
00157     return rtai_lxrt(BITSIDX, SIZARG, BITS_WAIT, &arg).i[LOW];
00158 }
00159 
00160 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))
00161 {
00162     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 };
00163     return rtai_lxrt(BITSIDX, SIZARG, BITS_WAIT_IF, &arg).i[LOW];
00164 }
00165 
00166 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))
00167 {
00168     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 };
00169     return rtai_lxrt(BITSIDX, SIZARG, BITS_WAIT_UNTIL, &arg).i[LOW];
00170 }
00171 
00172 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))
00173 {
00174     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 };
00175     return rtai_lxrt(BITSIDX, SIZARG, BITS_WAIT_TIMED, &arg).i[LOW];
00176 }
00177 
00178 #ifdef __cplusplus
00179 }
00180 #endif /* __cplusplus */
00181 
00182 #endif /* __KERNEL__ */
00183 
00184 #if !defined(__KERNEL__) || defined(__cplusplus)
00185 
00186 typedef struct rt_bits_struct {
00187     int opaque;
00188 } BITS;
00189 
00190 #endif /* !__KERNEL__ || __cplusplus */
00191 
00192 #endif /* !_RTAI_BITS_H */

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