IsoHandler::getPacket(): when keeping tabs of the last cycle, allow for cases where...
[ffado.git] / libffado / src / libieee1394 / IEC61883.h
blobfb1bbfc3916380f739214e12c440718e9e6a7d2e
1 /*
2 * Copyright (C) 2005-2008 by Pieter Palmers
4 * This file is part of FFADO
5 * FFADO = Free Firewire (pro-)audio drivers for linux
7 * FFADO is based upon FreeBoB
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) version 3 of the License.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef __FFADO_IEC61883__
25 #define __FFADO_IEC61883__
27 #include "../debugmodule/debugmodule.h"
30 * This is shamelessly stolen from iec61883-private,
31 * but I need these functions!
32 * FIXME: this will only work until somebody decides to change
33 * these in libiec61883.
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
39 /**
40 * Plug Control Registers
41 **/
43 /* maximum number of PCRs allowed within the standard
44 * MPR/PCR addresses defined in IEC-61883.
45 * This refers to the number of output or input PCRs--
46 * not the MPRs and not the combined total.
48 #define IEC61883_PCR_MAX 31
50 /* standard CSR offsets for plugs */
51 #define CSR_O_MPR 0x900
52 #define CSR_O_PCR_0 0x904
54 #define CSR_I_MPR 0x980
55 #define CSR_I_PCR_0 0x984
57 #if ( __BYTE_ORDER == __BIG_ENDIAN )
59 struct iec61883_oMPR {
60 unsigned int data_rate:2;
61 unsigned int bcast_channel:6;
62 unsigned int non_persist_ext:8;
63 unsigned int persist_ext:8;
64 unsigned int reserved:3;
65 unsigned int n_plugs:5;
68 struct iec61883_iMPR {
69 unsigned int data_rate:2;
70 unsigned int reserved:6;
71 unsigned int non_persist_ext:8;
72 unsigned int persist_ext:8;
73 unsigned int reserved2:3;
74 unsigned int n_plugs:5;
77 struct iec61883_oPCR {
78 unsigned int online:1;
79 unsigned int bcast_connection:1;
80 unsigned int n_p2p_connections:6;
81 unsigned int reserved:2;
82 unsigned int channel:6;
83 unsigned int data_rate:2;
84 unsigned int overhead_id:4;
85 unsigned int payload:10;
88 struct iec61883_iPCR {
89 unsigned int online:1;
90 unsigned int bcast_connection:1;
91 unsigned int n_p2p_connections:6;
92 unsigned int reserved:2;
93 unsigned int channel:6;
94 unsigned int reserved2:16;
97 #else
99 struct iec61883_oMPR {
100 unsigned int n_plugs:5;
101 unsigned int reserved:3;
102 unsigned int persist_ext:8;
103 unsigned int non_persist_ext:8;
104 unsigned int bcast_channel:6;
105 unsigned int data_rate:2;
108 struct iec61883_iMPR {
109 unsigned int n_plugs:5;
110 unsigned int reserved2:3;
111 unsigned int persist_ext:8;
112 unsigned int non_persist_ext:8;
113 unsigned int reserved:6;
114 unsigned int data_rate:2;
117 struct iec61883_oPCR {
118 unsigned int payload:10;
119 unsigned int overhead_id:4;
120 unsigned int data_rate:2;
121 unsigned int channel:6;
122 unsigned int reserved:2;
123 unsigned int n_p2p_connections:6;
124 unsigned int bcast_connection:1;
125 unsigned int online:1;
128 struct iec61883_iPCR {
129 unsigned int reserved2:16;
130 unsigned int channel:6;
131 unsigned int reserved:2;
132 unsigned int n_p2p_connections:6;
133 unsigned int bcast_connection:1;
134 unsigned int online:1;
137 #endif
140 * iec61883_plug_get - Read a node's plug register.
141 * @h: A raw1394 handle.
142 * @n: The node id of the node to read
143 * @a: The CSR offset address (relative to base) of the register to read.
144 * @value: A pointer to a quadlet where the plug register's value will be stored.
146 * This function handles bus to host endian conversion. It returns 0 for
147 * suceess or -1 for error (errno available).
150 iec61883_plug_get(raw1394handle_t h, nodeid_t n, nodeaddr_t a, quadlet_t *value);
154 * iec61883_plug_set - Write a node's plug register.
155 * @h: A raw1394 handle.
156 * @n: The node id of the node to read
157 * @a: The CSR offset address (relative to CSR base) of the register to write.
158 * @value: A quadlet containing the new register value.
160 * This uses a compare/swap lock operation to safely write the
161 * new register value, as required by IEC 61883-1.
162 * This function handles host to bus endian conversion. It returns 0 for success
163 * or -1 for error (errno available).
166 iec61883_plug_set(raw1394handle_t h, nodeid_t n, nodeaddr_t a, quadlet_t value);
169 * High level plug access macros
172 #define iec61883_get_oMPR(h,n,v) iec61883_plug_get((h), (n), CSR_O_MPR, (quadlet_t *)(v))
173 #define iec61883_set_oMPR(h,n,v) iec61883_plug_set((h), (n), CSR_O_MPR, *((quadlet_t *)&(v)))
174 #define iec61883_get_oPCR0(h,n,v) iec61883_plug_get((h), (n), CSR_O_PCR_0, (quadlet_t *)(v))
175 #define iec61883_set_oPCR0(h,n,v) iec61883_plug_set((h), (n), CSR_O_PCR_0, *((quadlet_t *)&(v)))
176 #define iec61883_get_oPCRX(h,n,v,x) iec61883_plug_get((h), (n), CSR_O_PCR_0+(4*(x)), (quadlet_t *)(v))
177 #define iec61883_set_oPCRX(h,n,v,x) iec61883_plug_set((h), (n), CSR_O_PCR_0+(4*(x)), *((quadlet_t *)&(v)))
178 #define iec61883_get_iMPR(h,n,v) iec61883_plug_get((h), (n), CSR_I_MPR, (quadlet_t *)(v))
179 #define iec61883_set_iMPR(h,n,v) iec61883_plug_set((h), (n), CSR_I_MPR, *((quadlet_t *)&(v)))
180 #define iec61883_get_iPCR0(h,n,v) iec61883_plug_get((h), (n), CSR_I_PCR_0, (quadlet_t *)(v))
181 #define iec61883_set_iPCR0(h,n,v) iec61883_plug_set((h), (n), CSR_I_PCR_0, *((quadlet_t *)&(v)))
182 #define iec61883_get_iPCRX(h,n,v,x) iec61883_plug_get((h), (n), CSR_I_PCR_0+(4*(x)), (quadlet_t *)(v))
183 #define iec61883_set_iPCRX(h,n,v,x) iec61883_plug_set((h), (n), CSR_I_PCR_0+(4*(x)), *((quadlet_t *)&(v)))
186 #ifdef __cplusplus
188 #endif
190 class IEC61883 {
192 public:
194 IEC61883();
195 virtual ~IEC61883();
197 protected:
198 DECLARE_DEBUG_MODULE;
202 #endif /* __FFADO_IEC61883__ */