File: rtai_tbx.h

package info (click to toggle)
rtai 3.1.0-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 23,560 kB
  • ctags: 19,698
  • sloc: ansic: 88,861; cpp: 31,340; tcl: 14,684; sh: 10,652; xml: 760; yacc: 575; lex: 537; makefile: 394; asm: 310; php: 300; perl: 108
file content (288 lines) | stat: -rw-r--r-- 9,002 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
 * Copyright (C) 2001  G.M. Bertani <gmbertani@yahoo.it>
 * Copyright (C) 2002  P. Mantegazza <mantegazza@aero.polimi.it>
 *		         (LXRT extensions).
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef _RTAI_TBX_H
#define _RTAI_TBX_H

#include <rtai_types.h>

/* TYPED MAILBOXES */

#define RT_TBX_MAGIC 0x6e93ad4b

#define TYPE_NONE      0x00
#define TYPE_NORMAL    0x01
#define TYPE_BROADCAST 0x02
#define TYPE_URGENT    0x04

#ifdef __KERNEL__

struct rt_typed_mailbox;

#ifndef __cplusplus

#include <rtai_sem.h>

typedef struct rt_typed_mailbox {

    int magic;
    int waiting_nr;   /* number of tasks waiting for a broadcast */
    SEM sndsmx, rcvsmx;
    SEM bcbsmx;       /* binary sem needed to wakeup the sleeping tasks 
                      when the broadcasting of a message is terminated */
    RT_TASK *waiting_task;
    char *bufadr;     /* mailbox buffer */
    char *bcbadr;     /* broadcasting buffer */
    int size;         /* mailbox size */
    int fbyte;        /* circular buffer read pointer */
    int avbs;         /* bytes occupied */
    int frbs;         /* bytes free */
    spinlock_t buflock;

} TBX;

#else /* __cplusplus */
extern "C" {
#endif /* !__cplusplus */

int __rtai_tbx_init(void);

void __rtai_tbx_exit(void);

/*
 * send_wp and receive_wp are not implemented because 
 * the packed message must be sent/received atomically
 */ 

int rt_tbx_init(struct rt_typed_mailbox *tbx,
		int size,
		int flags);

int rt_tbx_delete(struct rt_typed_mailbox *tbx);

int rt_tbx_send(struct rt_typed_mailbox *tbx,
		void *msg,
		int msg_size);

int rt_tbx_send_if(struct rt_typed_mailbox *tbx,
		   void *msg,
		   int msg_size);

int rt_tbx_send_until(struct rt_typed_mailbox *tbx,
		      void *msg,
		      int msg_size,
		      RTIME time);

int rt_tbx_send_timed(struct rt_typed_mailbox *tbx,
		      void *msg,
		      int msg_size,
		      RTIME delay);

int rt_tbx_receive(struct rt_typed_mailbox *tbx,
		   void *msg,
		   int msg_size);

int rt_tbx_receive_if(struct rt_typed_mailbox *tbx,
		      void *msg,
		      int msg_size);

int rt_tbx_receive_until(struct rt_typed_mailbox *tbx,
			 void *msg,
			 int msg_size,
			 RTIME time);

int rt_tbx_receive_timed(struct rt_typed_mailbox *tbx,
			 void *msg,
			 int msg_size,
			 RTIME delay);

int rt_tbx_broadcast(struct rt_typed_mailbox *tbx,
		     void *msg,
		     int msg_size);

int rt_tbx_broadcast_if(struct rt_typed_mailbox *tbx,
			void *msg,
			int msg_size);

int rt_tbx_broadcast_until(struct rt_typed_mailbox *tbx,
			   void *msg,
			   int msg_size,
			   RTIME time);

int rt_tbx_broadcast_timed(struct rt_typed_mailbox *tbx,
			   void *msg,
			   int msg_size,
			   RTIME delay);

int rt_tbx_urgent(struct rt_typed_mailbox *tbx,
		  void *msg,
		  int msg_size);

int rt_tbx_urgent_if(struct rt_typed_mailbox *tbx,
		     void *msg,
		     int msg_size);

int rt_tbx_urgent_until(struct rt_typed_mailbox *tbx,
			void *msg,
			int msg_size,
			RTIME time);

int rt_tbx_urgent_timed(struct rt_typed_mailbox *tbx,
			void *msg,
			int msg_size,
			RTIME delay);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#else /* !__KERNEL__ */

#include <rtai_lxrt.h>

#define TBXIDX 0

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

RTAI_PROTO(struct rt_typed_mailbox *, rt_tbx_init,(unsigned long name, int size, int flags))
{
	struct { unsigned long name; int size; int flags; } arg = { name, size, flags };
	return (struct rt_typed_mailbox *)rtai_lxrt(TBXIDX, SIZARG, TBX_INIT, &arg).v[LOW];
}

RTAI_PROTO(int, rt_tbx_delete,(struct rt_typed_mailbox *tbx))
{
	struct { struct rt_typed_mailbox *tbx; } arg = { tbx };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_DELETE, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_send,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_SEND, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_send_if,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_SEND_IF, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_send_until,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME time))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME time; } arg = { tbx, msg, msg_size, time };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_SEND_UNTIL, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_send_timed,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME delay))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME delay; } arg = { tbx, msg, msg_size, delay };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_SEND_TIMED, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_receive,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_RECEIVE, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_receive_if,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_RECEIVE_IF, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_receive_until,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME time))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME time; } arg = { tbx, msg, msg_size, time };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_RECEIVE_UNTIL, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_receive_timed,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME delay))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME delay; } arg = { tbx, msg, msg_size, delay };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_RECEIVE_TIMED, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_broadcast,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_BROADCAST, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_broadcast_if,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_BROADCAST_IF, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_broadcast_until,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME time))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME time; } arg = { tbx, msg, msg_size, time };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_BROADCAST_UNTIL, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_broadcast_timed,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME delay))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME delay; } arg = { tbx, msg, msg_size, delay };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_BROADCAST_TIMED, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_urgent,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_URGENT, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_urgent_if,(struct rt_typed_mailbox *tbx, void *msg, int msg_size))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; } arg = { tbx, msg, msg_size };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_URGENT_IF, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_urgent_until,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME time))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME time; } arg = { tbx, msg, msg_size, time };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_URGENT_UNTIL, &arg).i[LOW];
}

RTAI_PROTO(int, rt_tbx_urgent_timed,(struct rt_typed_mailbox *tbx, void *msg, int msg_size, RTIME delay))
{
	struct { struct rt_typed_mailbox *tbx; void *msg; int msg_size; RTIME delay; } arg = { tbx, msg, msg_size, delay };
	return rtai_lxrt(TBXIDX, SIZARG, TBX_URGENT_TIMED, &arg).i[LOW];
}

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __KERNEL__ */

#if !defined(__KERNEL__) || defined(__cplusplus)

typedef struct rt_typed_mailbox {
    int opaque;
} TBX;

#endif /* !__KERNEL__ || __cplusplus */

#endif /* !_RTAI_TBX_H */