Xenomai API  2.6.5
buffer.h
Go to the documentation of this file.
1 
22 #ifndef _XENO_BUFFER_H
23 #define _XENO_BUFFER_H
24 
25 #include <native/types.h>
26 
27 /* Creation flags. */
28 #define B_PRIO XNSYNCH_PRIO /* Pend by task priority order. */
29 #define B_FIFO XNSYNCH_FIFO /* Pend by FIFO order. */
30 
31 typedef struct rt_buffer_info {
32 
33  int iwaiters;
34  int owaiters;
35  size_t totalmem;
36  size_t availmem;
37  char name[XNOBJECT_NAME_LEN];
38 
39 } RT_BUFFER_INFO;
40 
41 typedef struct rt_buffer_placeholder {
42  xnhandle_t opaque;
43 } RT_BUFFER_PLACEHOLDER;
44 
45 #if (defined(__KERNEL__) || defined(__XENO_SIM__)) && !defined(DOXYGEN_CPP)
46 
47 #include <nucleus/synch.h>
48 #include <nucleus/heap.h>
49 #include <native/ppd.h>
50 
51 #define XENO_BUFFER_MAGIC 0x55550c0c
52 
53 typedef struct rt_buffer {
54 
55  unsigned magic; /* !< Magic code - must be first */
56 
57  xnsynch_t isynch_base; /* !< Base synchronization object -- input side. */
58  xnsynch_t osynch_base; /* !< Base synchronization object -- output side. */
59  xnhandle_t handle; /* !< Handle in registry -- zero if unregistered. */
60  char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
61 
62  int mode; /* !< Creation mode. */
63  off_t rdoff; /* !< Read offset. */
64  off_t wroff; /* !< Write offset. */
65  size_t fillsz; /* !< Filled space. */
66 
67  u_long wrtoken; /* !< Write token. */
68  u_long rdtoken; /* !< Read token. */
69 
70  size_t bufsz; /* !< Buffer size. */
71  caddr_t bufmem; /* !< Buffer space. */
72 
73 #ifdef CONFIG_XENO_OPT_PERVASIVE
74  pid_t cpid; /* !< Creator's pid. */
75 #endif /* CONFIG_XENO_OPT_PERVASIVE */
76  xnholder_t rlink; /* !< Link in resource queue. */
77 #define rlink2buffer(ln) container_of(ln, RT_BUFFER, rlink)
78  xnqueue_t *rqueue; /* !< Backpointer to resource queue. */
79 
80 } RT_BUFFER;
81 
82 #ifdef __cplusplus
83 extern "C" {
84 #endif
85 
86 #ifdef CONFIG_XENO_OPT_NATIVE_BUFFER
87 
88 int __native_buffer_pkg_init(void);
89 
90 void __native_buffer_pkg_cleanup(void);
91 
92 static inline void __native_buffer_flush_rq(xnqueue_t *rq)
93 {
94  xeno_flush_rq(RT_BUFFER, rq, buffer);
95 }
96 
97 struct xnbufd;
98 
99 ssize_t rt_buffer_read_inner(RT_BUFFER *bf, struct xnbufd *bufd,
100  xntmode_t timeout_mode, RTIME timeout);
101 
102 ssize_t rt_buffer_write_inner(RT_BUFFER *bf, struct xnbufd *bufd,
103  xntmode_t timeout_mode, RTIME timeout);
104 
105 #else /* !CONFIG_XENO_OPT_NATIVE_BUFFER */
106 
107 #define __native_buffer_pkg_init() ({ 0; })
108 #define __native_buffer_pkg_cleanup() do { } while(0)
109 #define __native_buffer_flush_rq(rq) do { } while(0)
110 
111 #endif /* !CONFIG_XENO_OPT_NATIVE_BUFFER */
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #else /* !(__KERNEL__ || __XENO_SIM__) */
118 
119 typedef RT_BUFFER_PLACEHOLDER RT_BUFFER;
120 
121 #ifdef __cplusplus
122 extern "C" {
123 #endif
124 
125 int rt_buffer_bind(RT_BUFFER *bf,
126  const char *name,
127  RTIME timeout);
128 
129 static inline int rt_buffer_unbind(RT_BUFFER *bf)
130 {
131  bf->opaque = XN_NO_HANDLE;
132  return 0;
133 }
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #endif /* __KERNEL__ || __XENO_SIM__ */
140 
141 #ifdef __cplusplus
142 extern "C" {
143 #endif
144 
145 /* Public interface. */
146 
147 int rt_buffer_create(RT_BUFFER *bf,
148  const char *name,
149  size_t bufsz,
150  int mode);
151 
152 int rt_buffer_delete(RT_BUFFER *bf);
153 
154 ssize_t rt_buffer_write(RT_BUFFER *bf,
155  const void *ptr, size_t size,
156  RTIME timeout);
157 
158 ssize_t rt_buffer_write_until(RT_BUFFER *bf,
159  const void *ptr, size_t size,
160  RTIME timeout);
161 
162 ssize_t rt_buffer_read(RT_BUFFER *bf,
163  void *ptr, size_t size,
164  RTIME timeout);
165 
166 ssize_t rt_buffer_read_until(RT_BUFFER *bf,
167  void *ptr, size_t size,
168  RTIME timeout);
169 
170 int rt_buffer_clear(RT_BUFFER *bf);
171 
172 int rt_buffer_inquire(RT_BUFFER *bf,
173  RT_BUFFER_INFO *info);
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 #endif /* !_XENO_BUFFER_H */
ssize_t rt_buffer_write_until(RT_BUFFER *bf, const void *ptr, size_t size, RTIME timeout)
Write to a buffer (with absolute timeout date).
Definition: buffer.c:63
int rt_buffer_create(RT_BUFFER *bf, const char *name, size_t bufsz, int mode)
Create a buffer.
Definition: buffer.c:24
int rt_buffer_delete(RT_BUFFER *bf)
Delete a buffer.
Definition: buffer.c:37
This file is part of the Xenomai project.
ssize_t rt_buffer_write(RT_BUFFER *bf, const void *ptr, size_t size, RTIME timeout)
Write to a buffer.
Definition: buffer.c:56
ssize_t rt_buffer_read(RT_BUFFER *bf, void *ptr, size_t size, RTIME timeout)
Read from a buffer.
Definition: buffer.c:42
int rt_buffer_bind(RT_BUFFER *bf, const char *name, RTIME timeout)
Bind to a buffer.
Definition: buffer.c:31
int rt_buffer_clear(RT_BUFFER *bf)
Clear a buffer.
Definition: buffer.c:70
int rt_buffer_inquire(RT_BUFFER *bf, RT_BUFFER_INFO *info)
Inquire about a buffer.
Definition: buffer.c:76
static int rt_buffer_unbind(RT_BUFFER *bf)
Unbind from a buffer.
Definition: buffer.h:129
This file is part of the Xenomai project.