Debian Codegraph @

src/iec61883-private.h

raw
1 /*
2 * iec61883-private.h - Linux IEEE 1394 streaming media library.
3 * Copyright (C) 2004 Kristian Hogsberg, Dan Dennedy, and Dan Maas.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #ifndef _IEC61883_PRIVATE_H
21 #define _IEC61883_PRIVATE_H
22
23 #include <libraw1394/raw1394.h>
24 #include <endian.h>
25 #include "tsbuffer.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #ifdef IEC61883_DEBUG
32 #define DEBUG(s, args...) fprintf(stderr, "libiec61883 debug: " s "\n", ## args)
33 #else
34 #define DEBUG(s, args...)
35 #endif
36 #ifndef QUIET
37 #define WARN(s, args...) {fprintf(stderr, "libiec61883 warning: " s "\n", ## args);}
38 #else
39 #define WARN(s, args...) {}
40 #endif
41 #define FAIL(s, args...) {fprintf(stderr, "libiec61883 error: " s "\n", ## args);return(-1);}
42
43 /*
44 * The TAG value is present in the isochronous header (first quadlet). It
45 * provides a high level label for the format of data carried by the
46 * isochronous packet.
47 */
48
49 #define IEC61883_TAG_WITHOUT_CIP 0 /* CIP header NOT included */
50 #define IEC61883_TAG_WITH_CIP 1 /* CIP header included. */
51 #define IEC61883_TAG_RESERVED1 2 /* Reserved */
52 #define IEC61883_TAG_RESERVED2 3 /* Reserved */
53
54 /**
55 * Common Isochronous Protocol
56 **/
57
58 #define IEC61883_FMT_DV 0x00
59 #define IEC61883_FMT_AMDTP 0x10
60 #define IEC61883_FMT_MPEG2 0x20
61
62 #if __BYTE_ORDER == __BIG_ENDIAN
63
64 struct iso_packet_header {
65 unsigned int data_length : 16;
66 unsigned int tag : 2;
67 unsigned int channel : 6;
68 unsigned int tcode : 4;
69 unsigned int sy : 4;
70 };
71
72 struct iec61883_packet {
73 /* First quadlet */
74 unsigned int dbs : 8;
75 unsigned int eoh0 : 2;
76 unsigned int sid : 6;
77
78 unsigned int dbc : 8;
79 unsigned int fn : 2;
80 unsigned int qpc : 3;
81 unsigned int sph : 1;
82 unsigned int reserved : 2;
83
84 /* Second quadlet */
85 unsigned int fdf : 8;
86 unsigned int eoh1 : 2;
87 unsigned int fmt : 6;
88
89 unsigned int syt : 16;
90
91 unsigned char data[0];
92 };
93
94 #elif __BYTE_ORDER == __LITTLE_ENDIAN
95
96 struct iso_packet_header {
97 unsigned int data_length : 16;
98 unsigned int channel : 6;
99 unsigned int tag : 2;
100 unsigned int sy : 4;
101 unsigned int tcode : 4;
102 };
103
104 struct iec61883_packet {
105 /* First quadlet */
106 unsigned int sid : 6;
107 unsigned int eoh0 : 2;
108 unsigned int dbs : 8;
109
110 unsigned int reserved : 2;
111 unsigned int sph : 1;
112 unsigned int qpc : 3;
113 unsigned int fn : 2;
114 unsigned int dbc : 8;
115
116 /* Second quadlet */
117 unsigned int fmt : 6;
118 unsigned int eoh1 : 2;
119 unsigned int fdf : 8;
120
121 unsigned int syt : 16;
122
123 unsigned char data[0];
124 };
125
126 #else
127
128 #error Unknown bitfield type
129
130 #endif
131
132 struct iec61883_fraction {
133 int integer;
134 int numerator;
135 int denominator;
136 };
137
138 struct iec61883_cip {
139 struct iec61883_fraction cycle_offset;
140 struct iec61883_fraction ticks_per_syt_offset;
141 struct iec61883_fraction ready_samples;
142 struct iec61883_fraction samples_per_cycle;
143 int dbc, dbs;
144 int cycle_count;
145 int mode;
146 int syt_interval;
147 int dimension;
148 int rate;
149 int fdf;
150 int format;
151 };
152
153 void
154 iec61883_cip_init(struct iec61883_cip *cip, int format, int fdf,
155 int rate, int dbs, int syt_interval);
156 void
157 iec61883_cip_resync(struct iec61883_cip *ptz, int cycle);
158 void
159 iec61883_cip_set_transmission_mode(struct iec61883_cip *ptz, int mode);
160
161 int
162 iec61883_cip_get_max_packet_size(struct iec61883_cip *ptz);
163
164 int
165 iec61883_cip_fill_header(raw1394handle_t handle, struct iec61883_cip *cip,
166 struct iec61883_packet *packet);
167
168
169 /**
170 * Audio and Music Data Transport Protocol
171 **/
172
173 #define IEC61883_FDF_NODATA 0xFF
174
175 /* AM824 format definitions. */
176 #define IEC61883_FDF_AM824 0x00
177 #define IEC61883_FDF_AM824_CONTROLLED 0x04
178 #define IEC61883_FDF_SFC_MASK 0x03
179
180 #define IEC61883_AM824_LABEL 0x40
181 #define IEC61883_AM824_LABEL_RAW_24BITS 0x40
182 #define IEC61883_AM824_LABEL_RAW_20BITS 0x41
183 #define IEC61883_AM824_LABEL_RAW_16BITS 0x42
184 #define IEC61883_AM824_LABEL_RAW_RESERVED 0x43
185
186 #define IEC61883_AM824_VBL_24BITS 0x0
187 #define IEC61883_AM824_VBL_20BITS 0x1
188 #define IEC61883_AM824_VBL_16BITS 0x2
189 #define IEC61883_AM824_VBL_RESERVED 0x3
190
191 /* IEC-60958 format definitions. */
192 #define IEC60958_LABEL 0x0
193 #define IEC60958_PAC_B 0x3 /* Preamble Code 'B': Start of channel 1, at
194 * the start of a data block. */
195 #define IEC60958_PAC_RSV 0x2 /* Preamble Code 'RESERVED' */
196 #define IEC60958_PAC_M 0x1 /* Preamble Code 'M': Start of channel 1 that
197 * is not at the start of a data block. */
198 #define IEC60958_PAC_W 0x0 /* Preamble Code 'W': start of channel 2. */
199 #define IEC60958_DATA_VALID 0 /* When cleared means data is valid. */
200 #define IEC60958_DATA_INVALID 1 /* When set means data is not suitable for an ADC. */
201
202 #if __BYTE_ORDER == __BIG_ENDIAN
203
204 struct iec60958_data {
205 u_int32_t data : 24;
206 u_int32_t validity : 1;
207 u_int32_t user_data : 1;
208 u_int32_t ch_status : 1;
209 u_int32_t parity : 1;
210 u_int32_t pac : 2;
211 u_int32_t label : 2;
212 };
213
214 #elif __BYTE_ORDER == __LITTLE_ENDIAN
215
216 struct iec60958_data {
217 u_int32_t data : 24;
218 u_int32_t validity : 1;
219 u_int32_t user_data : 1;
220 u_int32_t ch_status : 1;
221 u_int32_t parity : 1;
222 u_int32_t pac : 2;
223 u_int32_t label : 2;
224 };
225
226 #else
227
228 #error Unknown bitfield type
229
230 #endif
231
232 struct iec61883_amdtp {
233 struct iec61883_cip cip;
234 int dimension;
235 int rate;
236 int iec958_rate_code;
237 int sample_format;
238 int iec958_frame_count;
239 iec61883_amdtp_recv_t put_data;
240 iec61883_amdtp_xmit_t get_data;
241 void *callback_data;
242 int format;
243 int syt_interval;
244 raw1394handle_t handle;
245 int channel;
246 unsigned int buffer_packets;
247 unsigned int prebuffer_packets;
248 unsigned int irq_interval;
249 int synch;
250 int speed;
251 unsigned int total_dropped;
252 };
253
254
255 /**
256 * DV Digital Video
257 **/
258
259 struct iec61883_dv {
260 struct iec61883_cip cip;
261 iec61883_dv_recv_t put_data;
262 iec61883_dv_xmit_t get_data;
263 void *callback_data;
264 raw1394handle_t handle;
265 int channel;
266 unsigned int buffer_packets;
267 unsigned int prebuffer_packets;
268 unsigned int irq_interval;
269 int synch;
270 int speed;
271 unsigned int total_dropped;
272 };
273
274 struct iec61883_dv_fb {
275 iec61883_dv_t dv;
276 unsigned char data[480*300];
277 int len;
278 iec61883_dv_fb_recv_t put_data;
279 void *callback_data;
280 int ff;
281 unsigned int total_incomplete;
282 };
283
284
285 /**
286 * MPEG-2 Transport Stream
287 **/
288
289 struct iec61883_mpeg2 {
290 struct iec61883_cip cip;
291 iec61883_mpeg2_recv_t put_data;
292 iec61883_mpeg2_xmit_t get_data;
293 void *callback_data;
294 int syt_interval;
295 raw1394handle_t handle;
296 int channel;
297 struct tsbuffer *tsbuffer;
298 unsigned int buffer_packets;
299 unsigned int prebuffer_packets;
300 unsigned int irq_interval;
301 int synch;
302 int speed;
303 unsigned int total_dropped;
304 };
305
306
307 /**
308 * Plug Control Registers
309 **/
310
311 /* maximum number of PCRs allowed within the standard
312 * MPR/PCR addresses defined in IEC-61883.
313 * This refers to the number of output or input PCRs--
314 * not the MPRs and not the combined total.
315 */
316 #define IEC61883_PCR_MAX 31
317
318 /* standard CSR offsets for plugs */
319 #define CSR_O_MPR 0x900
320 #define CSR_O_PCR_0 0x904
321
322 #define CSR_I_MPR 0x980
323 #define CSR_I_PCR_0 0x984
324
325 #if ( __BYTE_ORDER == __BIG_ENDIAN )
326
327 struct iec61883_oMPR {
328 unsigned int data_rate:2;
329 unsigned int bcast_channel:6;
330 unsigned int non_persist_ext:8;
331 unsigned int persist_ext:8;
332 unsigned int reserved:3;
333 unsigned int n_plugs:5;
334 };
335
336 struct iec61883_iMPR {
337 unsigned int data_rate:2;
338 unsigned int reserved:6;
339 unsigned int non_persist_ext:8;
340 unsigned int persist_ext:8;
341 unsigned int reserved2:3;
342 unsigned int n_plugs:5;
343 };
344
345 struct iec61883_oPCR {
346 unsigned int online:1;
347 unsigned int bcast_connection:1;
348 unsigned int n_p2p_connections:6;
349 unsigned int reserved:2;
350 unsigned int channel:6;
351 unsigned int data_rate:2;
352 unsigned int overhead_id:4;
353 unsigned int payload:10;
354 };
355
356 struct iec61883_iPCR {
357 unsigned int online:1;
358 unsigned int bcast_connection:1;
359 unsigned int n_p2p_connections:6;
360 unsigned int reserved:2;
361 unsigned int channel:6;
362 unsigned int reserved2:16;
363 };
364
365 #else
366
367 struct iec61883_oMPR {
368 unsigned int n_plugs:5;
369 unsigned int reserved:3;
370 unsigned int persist_ext:8;
371 unsigned int non_persist_ext:8;
372 unsigned int bcast_channel:6;
373 unsigned int data_rate:2;
374 };
375
376 struct iec61883_iMPR {
377 unsigned int n_plugs:5;
378 unsigned int reserved2:3;
379 unsigned int persist_ext:8;
380 unsigned int non_persist_ext:8;
381 unsigned int reserved:6;
382 unsigned int data_rate:2;
383 };
384
385 struct iec61883_oPCR {
386 unsigned int payload:10;
387 unsigned int overhead_id:4;
388 unsigned int data_rate:2;
389 unsigned int channel:6;
390 unsigned int reserved:2;
391 unsigned int n_p2p_connections:6;
392 unsigned int bcast_connection:1;
393 unsigned int online:1;
394 };
395
396 struct iec61883_iPCR {
397 unsigned int reserved2:16;
398 unsigned int channel:6;
399 unsigned int reserved:2;
400 unsigned int n_p2p_connections:6;
401 unsigned int bcast_connection:1;
402 unsigned int online:1;
403 };
404
405 #endif
406
407 /**
408 * iec61883_plug_get - Read a node's plug register.
409 * @h: A raw1394 handle.
410 * @n: The node id of the node to read
411 * @a: The CSR offset address (relative to base) of the register to read.
412 * @value: A pointer to a quadlet where the plug register's value will be stored.
413 *
414 * This function handles bus to host endian conversion. It returns 0 for
415 * suceess or -1 for error (errno available).
416 **/
417 int
418 iec61883_plug_get(raw1394handle_t h, nodeid_t n, nodeaddr_t a, quadlet_t *value);
419
420
421 /**
422 * iec61883_plug_set - Write a node's plug register.
423 * @h: A raw1394 handle.
424 * @n: The node id of the node to read
425 * @a: The CSR offset address (relative to CSR base) of the register to write.
426 * @value: A quadlet containing the new register value.
427 *
428 * This uses a compare/swap lock operation to safely write the
429 * new register value, as required by IEC 61883-1.
430 * This function handles host to bus endian conversion. It returns 0 for success
431 * or -1 for error (errno available).
432 **/
433 int
434 iec61883_plug_set(raw1394handle_t h, nodeid_t n, nodeaddr_t a, quadlet_t value);
435
436 /**
437 * High level plug access macros
438 */
439
440 #define iec61883_get_oMPR(h,n,v) iec61883_plug_get((h), (n), CSR_O_MPR, (quadlet_t *)(v))
441 #define iec61883_set_oMPR(h,n,v) iec61883_plug_set((h), (n), CSR_O_MPR, *((quadlet_t *)&(v)))
442 #define iec61883_get_oPCR0(h,n,v) iec61883_plug_get((h), (n), CSR_O_PCR_0, (quadlet_t *)(v))
443 #define iec61883_set_oPCR0(h,n,v) iec61883_plug_set((h), (n), CSR_O_PCR_0, *((quadlet_t *)&(v)))
444 #define iec61883_get_oPCRX(h,n,v,x) iec61883_plug_get((h), (n), CSR_O_PCR_0+(4*(x)), (quadlet_t *)(v))
445 #define iec61883_set_oPCRX(h,n,v,x) iec61883_plug_set((h), (n), CSR_O_PCR_0+(4*(x)), *((quadlet_t *)&(v)))
446 #define iec61883_get_iMPR(h,n,v) iec61883_plug_get((h), (n), CSR_I_MPR, (quadlet_t *)(v))
447 #define iec61883_set_iMPR(h,n,v) iec61883_plug_set((h), (n), CSR_I_MPR, *((quadlet_t *)&(v)))
448 #define iec61883_get_iPCR0(h,n,v) iec61883_plug_get((h), (n), CSR_I_PCR_0, (quadlet_t *)(v))
449 #define iec61883_set_iPCR0(h,n,v) iec61883_plug_set((h), (n), CSR_I_PCR_0, *((quadlet_t *)&(v)))
450 #define iec61883_get_iPCRX(h,n,v,x) iec61883_plug_get((h), (n), CSR_I_PCR_0+(4*(x)), (quadlet_t *)(v))
451 #define iec61883_set_iPCRX(h,n,v,x) iec61883_plug_set((h), (n), CSR_I_PCR_0+(4*(x)), *((quadlet_t *)&(v)))
452
453
454 #ifdef __cplusplus
455 }
456 #endif
457
458 #endif /* _IEC61883_PRIVATE_H */