root/trunk/libffado/src/libieee1394/ieee1394service.h

Revision 677, 7.7 kB (checked in by ppalmers, 15 years ago)

make generation unambiguous.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
3  * Copyright (C) 2005-2007 by Pieter Palmers
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License version 2.1, as published by the Free Software Foundation;
13  *
14  * This library 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 GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22  * MA 02110-1301 USA
23  */
24
25 #ifndef FFADO_IEEE1394SERVICE_H
26 #define FFADO_IEEE1394SERVICE_H
27
28 #include "fbtypes.h"
29 #include "threads.h"
30
31 #include "debugmodule/debugmodule.h"
32
33 #include "IEC61883.h"
34
35 #include <libraw1394/raw1394.h>
36 #include <pthread.h>
37
38 #include <vector>
39
40 class ARMHandler;
41
42 class Ieee1394Service : public IEC61883 {
43 public:
44     Ieee1394Service();
45     ~Ieee1394Service();
46
47     bool initialize( int port );
48
49     int getPort()
50     { return m_port; }
51    /**
52     * @brief get number of nodes on the bus
53     *
54     * Since the root node always has
55     * the highest node ID, this number can be used to determine that ID (it's
56     * LOCAL_BUS|(count-1)).
57     *
58     * @return the number of nodes on the bus to which the port is connected.
59     * This value can change with every bus reset.
60     */
61     int getNodeCount();
62
63    /**
64     * @brief get the node id of the local node
65     *
66     * @note does not include the bus part (0xFFC0)
67     *
68     * @return the node id of the local node
69     * This value can change with every bus reset.
70     */
71     nodeid_t getLocalNodeId();
72
73    /**
74     * @brief send async read request to a node and wait for response.
75     *
76     * This does the complete transaction and will return when it's finished.
77     *
78     * @param node target node (\todo needs 0xffc0 stuff)
79     * @param addr address to read from
80     * @param length amount of data to read in quadlets
81     * @param buffer pointer to buffer where data will be saved
82
83     * @return true on success or false on failure (sets errno)
84     */
85     bool read( fb_nodeid_t nodeId,
86            fb_nodeaddr_t addr,
87            size_t length,
88            fb_quadlet_t* buffer );
89
90     bool read_quadlet( fb_nodeid_t nodeId,
91                        fb_nodeaddr_t addr,
92                        fb_quadlet_t* buffer );
93
94     bool read_octlet( fb_nodeid_t nodeId,
95                       fb_nodeaddr_t addr,
96                       fb_octlet_t* buffer );
97
98     /**
99     * @brief send async write request to a node and wait for response.
100     *
101     * This does the complete transaction and will return when it's finished.
102     *
103     * @param node target node (\XXX needs 0xffc0 stuff)
104     * @param addr address to write to
105     * @param length amount of data to write in quadlets
106     * @param data pointer to data to be sent
107     *
108     * @return true on success or false on failure (sets errno)
109     */
110     bool write( fb_nodeid_t nodeId,
111         fb_nodeaddr_t addr,
112         size_t length,
113         fb_quadlet_t* data );
114
115     bool write_quadlet( fb_nodeid_t nodeId,
116                         fb_nodeaddr_t addr,
117                         fb_quadlet_t data );
118
119     bool write_octlet(  fb_nodeid_t nodeId,
120                         fb_nodeaddr_t addr,
121                         fb_octlet_t data );
122
123     /**
124      * @brief send 64-bit compare-swap lock request and wait for response.
125      *
126      * swaps the content of \ref addr with \ref swap_value , but only if
127      * the content of \ref addr equals \ref compare_with
128      *
129      * @note takes care of endiannes
130      *
131      * @param nodeId target node ID
132      * @param addr address within target node address space
133      * @param compare_with value to compare \ref addr with
134      * @param swap_value new value to put in \ref addr
135      * @param result the value (originally) in \ref addr
136      *
137      * @return true if succesful, false otherwise
138      */
139     bool lockCompareSwap64(  fb_nodeid_t nodeId,
140                         fb_nodeaddr_t addr,
141                         fb_octlet_t  compare_value,
142                         fb_octlet_t  swap_value,
143                         fb_octlet_t* result );
144
145     fb_quadlet_t* transactionBlock( fb_nodeid_t nodeId,
146                                     fb_quadlet_t* buf,
147                                     int len,
148                     unsigned int* resp_len );
149
150     bool transactionBlockClose();
151
152     raw1394handle_t getHandle() {return m_handle;};
153
154     int getVerboseLevel();
155
156     bool addBusResetHandler( Functor* functor );
157     bool remBusResetHandler( Functor* functor );
158
159     /**
160      * @brief get the current generation
161      *
162      * @return the current generation
163      **/
164     unsigned int getGeneration() {
165         return raw1394_get_generation( m_handle );
166     }
167
168     /**
169      * @brief register an AddressRangeMapping Handler
170      * @param h pointer to the handler to register
171      *
172      * @return true on success or false on failure
173      **/
174
175     bool registerARMHandler( ARMHandler *h );
176
177     /**
178      * @brief unregister ARM range
179      * @param h pointer to the handler to unregister
180      * @return true if successful, false otherwise
181      */
182     bool unregisterARMHandler( ARMHandler *h );
183
184     nodeaddr_t findFreeARMBlock( nodeaddr_t start, size_t length, size_t step );
185
186 // ISO channel stuff
187 public:
188     signed int getAvailableBandwidth();
189     signed int allocateIsoChannelGeneric(unsigned int bandwidth);
190     signed int allocateIsoChannelCMP(nodeid_t xmit_node, int xmit_plug,
191                                      nodeid_t recv_node, int recv_plug);
192     bool freeIsoChannel(signed int channel);
193
194 private:
195     enum EAllocType {
196         AllocFree = 0, // not allocated (by us)
197         AllocGeneric = 1, // allocated with generic functions
198         AllocCMP=2 // allocated with CMP
199     };
200
201     struct ChannelInfo {
202         int channel;
203         int bandwidth;
204         enum EAllocType alloctype;
205         nodeid_t xmit_node;
206         int xmit_plug;
207         nodeid_t recv_node;
208         int recv_plug;
209     };
210
211     // the info for the channels we manage
212     struct ChannelInfo m_channels[64];
213
214     bool unregisterIsoChannel(unsigned int c);
215     bool registerIsoChannel(unsigned int c, struct ChannelInfo cinfo);
216
217 private:
218
219     bool startRHThread();
220     void stopRHThread();
221     static void* rHThread( void* arg );
222
223     void printBuffer( unsigned int level, size_t length, fb_quadlet_t* buffer ) const;
224     void printBufferBytes( unsigned int level, size_t length, byte_t* buffer ) const;
225
226     static int resetHandlerLowLevel( raw1394handle_t handle,
227                     unsigned int generation );
228     bool resetHandler( unsigned int generation );
229
230     static int armHandlerLowLevel(raw1394handle_t handle, unsigned long arm_tag,
231                      byte_t request_type, unsigned int requested_length,
232                      void *data);
233     bool armHandler(  unsigned long arm_tag,
234                      byte_t request_type, unsigned int requested_length,
235                      void *data);
236
237     raw1394handle_t m_handle;
238     raw1394handle_t m_resetHandle;
239     int             m_port;
240
241     pthread_t       m_thread;
242     pthread_mutex_t m_mutex;
243     bool            m_threadRunning;
244
245     typedef std::vector< Functor* > reset_handler_vec_t;
246     reset_handler_vec_t m_busResetHandlers;
247
248     // ARM stuff
249     arm_tag_handler_t m_default_arm_handler;
250
251     typedef std::vector< ARMHandler * > arm_handler_vec_t;
252     arm_handler_vec_t m_armHandlers;
253
254     fb_octlet_t byteSwap_octlet(fb_octlet_t value);
255
256 public:
257     void setVerboseLevel(int l);
258 private:
259     DECLARE_DEBUG_MODULE;
260 };
261
262 #endif // FFADO_IEEE1394SERVICE_H
Note: See TracBrowser for help on using the browser.