/ base / include / rtai_bits.h
rtai_bits.h
  1  /*
  2   * Copyright (C) 1999-2003 Paolo Mantegazza <mantegazza@aero.polimi.it>
  3   *
  4   * This program is free software; you can redistribute it and/or
  5   * modify it under the terms of the GNU General Public License as
  6   * published by the Free Software Foundation; either version 2 of the
  7   * License, or (at your option) any later version.
  8   *
  9   * This program is distributed in the hope that it will be useful,
 10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12   * GNU General Public License for more details.
 13   *
 14   * You should have received a copy of the GNU General Public License
 15   * along with this program; if not, write to the Free Software
 16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 17   */
 18  
 19  #ifndef _RTAI_BITS_H
 20  #define _RTAI_BITS_H
 21  
 22  #include <rtai_types.h>
 23  
 24  #define RT_BITS_MAGIC 0x9ac24448  // nam2num("rtbits")
 25  
 26  #define ALL_SET               0
 27  #define ANY_SET               1
 28  #define ALL_CLR               2
 29  #define ANY_CLR               3
 30  
 31  #define ALL_SET_AND_ANY_SET   4
 32  #define ALL_SET_AND_ALL_CLR   5
 33  #define ALL_SET_AND_ANY_CLR   6
 34  #define ANY_SET_AND_ALL_CLR   7
 35  #define ANY_SET_AND_ANY_CLR   8
 36  #define ALL_CLR_AND_ANY_CLR   9
 37  
 38  #define ALL_SET_OR_ANY_SET   10
 39  #define ALL_SET_OR_ALL_CLR   11
 40  #define ALL_SET_OR_ANY_CLR   12
 41  #define ANY_SET_OR_ALL_CLR   13
 42  #define ANY_SET_OR_ANY_CLR   14
 43  #define ALL_CLR_OR_ANY_CLR   15
 44  
 45  #define SET_BITS              0
 46  #define CLR_BITS              1
 47  #define SET_CLR_BITS          2
 48  #define NOP_BITS              3
 49  
 50  #define BITS_ERR     (RTE_OBJINV)  // same as semaphores
 51  #define BITS_TIMOUT  (RTE_TIMOUT)  // same as semaphores
 52  
 53  struct rt_bits_struct;
 54  
 55  #ifdef __KERNEL__
 56  
 57  #ifndef __cplusplus
 58  
 59  typedef struct rt_bits_struct {
 60  
 61      struct rt_queue queue;  /* <= Must be first in struct. */
 62      int magic;
 63      int type;  // to align mask to semaphore count, for easier uspace init
 64      unsigned long mask;
 65  
 66  } BITS;
 67  
 68  #else /* __cplusplus */
 69  extern "C" {
 70  #endif /* !__cplusplus */
 71  
 72  int __rtai_bits_init(void);
 73  
 74  void __rtai_bits_exit(void);
 75  
 76  void rt_bits_init(struct rt_bits_struct *bits, unsigned long mask);
 77  
 78  int rt_bits_delete(struct rt_bits_struct *bits);
 79  
 80  RTAI_SYSCALL_MODE unsigned long rt_get_bits(struct rt_bits_struct *bits);
 81  
 82  RTAI_SYSCALL_MODE unsigned long rt_bits_reset(struct rt_bits_struct *bits, unsigned long mask);
 83  
 84  RTAI_SYSCALL_MODE unsigned long rt_bits_signal(struct rt_bits_struct *bits, int setfun, unsigned long masks);
 85  
 86  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);
 87  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)
 88  {
 89  	return  _rt_bits_wait(bits, testfun, testmasks, exitfun, exitmasks, resulting_mask, 1);
 90  }
 91  
 92  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);
 93  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)
 94  {
 95  	return  _rt_bits_wait_if(bits, testfun, testmasks, exitfun, exitmasks, resulting_mask, 1);
 96  }
 97  
 98  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);
 99  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)
100  {
101  	return  _rt_bits_wait_until(bits, testfun, testmasks, exitfun, exitmasks, time, resulting_mask, 1);
102  }
103  
104  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);
105  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)
106  {
107  	return  _rt_bits_wait_timed(bits, testfun, testmasks, exitfun, exitmasks, delay, resulting_mask, 1);
108  }
109  
110  #ifdef __cplusplus
111  }
112  #endif /* __cplusplus */
113  
114  #else /* !__KERNEL__ */
115  
116  #include <rtai_lxrt.h>
117  
118  #define BITSIDX 0
119  
120  #ifdef __cplusplus
121  extern "C" {
122  #endif /* __cplusplus */
123  
124  RTAI_PROTO(struct rt_bits_struct *,rt_bits_init,(unsigned long name, unsigned long mask))
125  {
126  	struct { unsigned long name, mask; } arg = { name, mask };
127  	return (struct rt_bits_struct *)rtai_lxrt(BITSIDX, SIZARG, BITS_INIT, &arg).v[LOW];
128  }
129  
130  RTAI_PROTO(int, rt_bits_delete,(struct rt_bits_struct *bits))
131  {
132  	struct { struct rt_bits_struct *bits; } arg = { bits };
133  	return rtai_lxrt(BITSIDX, SIZARG, BITS_DELETE, &arg).i[LOW];
134  }
135  
136  RTAI_PROTO(unsigned long, rt_get_bits,(struct rt_bits_struct *bits))
137  {
138  	struct { struct rt_bits_struct *bits; } arg = { bits };
139  	return rtai_lxrt(BITSIDX, SIZARG, BITS_GET, &arg).i[LOW];
140  }
141  
142  RTAI_PROTO(unsigned long, rt_bits_reset,(struct rt_bits_struct *bits, unsigned long mask))
143  {
144  	struct { struct rt_bits_struct *bits; unsigned long mask; } arg = { bits, mask };
145  	return (unsigned long)rtai_lxrt(BITSIDX, SIZARG, BITS_RESET, &arg).i[LOW];
146  }
147  
148  RTAI_PROTO(unsigned long, rt_bits_signal,(struct rt_bits_struct *bits, int setfun, unsigned long masks))
149  {
150  	struct { struct rt_bits_struct *bits; long setfun; unsigned long masks; } arg = { bits, setfun, masks };
151  	return rtai_lxrt(BITSIDX, SIZARG, BITS_SIGNAL, &arg).i[LOW];
152  }
153  
154  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))
155  {
156  	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 };
157  	return rtai_lxrt(BITSIDX, SIZARG, BITS_WAIT, &arg).i[LOW];
158  }
159  
160  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))
161  {
162  	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 };
163  	return rtai_lxrt(BITSIDX, SIZARG, BITS_WAIT_IF, &arg).i[LOW];
164  }
165  
166  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))
167  {
168  	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 };
169  	return rtai_lxrt(BITSIDX, SIZARG, BITS_WAIT_UNTIL, &arg).i[LOW];
170  }
171  
172  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))
173  {
174  	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 };
175  	return rtai_lxrt(BITSIDX, SIZARG, BITS_WAIT_TIMED, &arg).i[LOW];
176  }
177  
178  #ifdef __cplusplus
179  }
180  #endif /* __cplusplus */
181  
182  #endif /* __KERNEL__ */
183  
184  #if !defined(__KERNEL__) || defined(__cplusplus)
185  
186  typedef struct rt_bits_struct {
187      int opaque;
188  } BITS;
189  
190  #endif /* !__KERNEL__ || __cplusplus */
191  
192  #endif /* !_RTAI_BITS_H */