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

Revision 748, 8.4 kB (checked in by ppalmers, 15 years ago)

try to reorganize things such that less information is duplicated

  • 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 program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
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 #include <string>
40
41 class ARMHandler;
42
43 class Ieee1394Service : public IEC61883 {
44 public:
45     Ieee1394Service();
46     ~Ieee1394Service();
47
48     bool initialize( int port );
49
50    /**
51     * @brief get number of ports (firewire adapters) in this machine
52     *
53     * @return the number of ports
54     */
55     static unsigned int detectNbPorts();
56
57    /**
58     * @brief get port (adapter) id
59     *
60     * @return get port (adapter) id
61     */
62     int getPort()
63         { return m_port; }
64
65    /**
66     * @brief get port (adapter) name
67     *
68     * @return get port (adapter) name
69     */
70     std::string getPortName()
71         { return m_portName; };
72
73    /**
74     * @brief get number of nodes on the bus
75     *
76     * Since the root node always has
77     * the highest node ID, this number can be used to determine that ID (it's
78     * LOCAL_BUS|(count-1)).
79     *
80     * @return the number of nodes on the bus to which the port is connected.
81     * This value can change with every bus reset.
82     */
83     int getNodeCount();
84
85    /**
86     * @brief get the node id of the local node
87     *
88     * @note does not include the bus part (0xFFC0)
89     *
90     * @return the node id of the local node
91     * This value can change with every bus reset.
92     */
93     nodeid_t getLocalNodeId();
94
95     /// get the most recent cycle timer value (in ticks)
96     unsigned int getCycleTimerTicks();
97     /// get the most recent cycle timer value (as is)
98     unsigned int getCycleTimer();
99
100
101    /**
102     * @brief send async read request to a node and wait for response.
103     *
104     * This does the complete transaction and will return when it's finished.
105     *
106     * @param node target node (\todo needs 0xffc0 stuff)
107     * @param addr address to read from
108     * @param length amount of data to read in quadlets
109     * @param buffer pointer to buffer where data will be saved
110
111     * @return true on success or false on failure (sets errno)
112     */
113     bool read( fb_nodeid_t nodeId,
114            fb_nodeaddr_t addr,
115            size_t length,
116            fb_quadlet_t* buffer );
117
118     bool read_quadlet( fb_nodeid_t nodeId,
119                        fb_nodeaddr_t addr,
120                        fb_quadlet_t* buffer );
121
122     bool read_octlet( fb_nodeid_t nodeId,
123                       fb_nodeaddr_t addr,
124                       fb_octlet_t* buffer );
125
126     /**
127     * @brief send async write request to a node and wait for response.
128     *
129     * This does the complete transaction and will return when it's finished.
130     *
131     * @param node target node (\XXX needs 0xffc0 stuff)
132     * @param addr address to write to
133     * @param length amount of data to write in quadlets
134     * @param data pointer to data to be sent
135     *
136     * @return true on success or false on failure (sets errno)
137     */
138     bool write( fb_nodeid_t nodeId,
139         fb_nodeaddr_t addr,
140         size_t length,
141         fb_quadlet_t* data );
142
143     bool write_quadlet( fb_nodeid_t nodeId,
144                         fb_nodeaddr_t addr,
145                         fb_quadlet_t data );
146
147     bool write_octlet(  fb_nodeid_t nodeId,
148                         fb_nodeaddr_t addr,
149                         fb_octlet_t data );
150
151     /**
152      * @brief send 64-bit compare-swap lock request and wait for response.
153      *
154      * swaps the content of \ref addr with \ref swap_value , but only if
155      * the content of \ref addr equals \ref compare_with
156      *
157      * @note takes care of endiannes
158      *
159      * @param nodeId target node ID
160      * @param addr address within target node address space
161      * @param compare_with value to compare \ref addr with
162      * @param swap_value new value to put in \ref addr
163      * @param result the value (originally) in \ref addr
164      *
165      * @return true if succesful, false otherwise
166      */
167     bool lockCompareSwap64(  fb_nodeid_t nodeId,
168                         fb_nodeaddr_t addr,
169                         fb_octlet_t  compare_value,
170                         fb_octlet_t  swap_value,
171                         fb_octlet_t* result );
172
173     fb_quadlet_t* transactionBlock( fb_nodeid_t nodeId,
174                                     fb_quadlet_t* buf,
175                                     int len,
176                     unsigned int* resp_len );
177
178     bool transactionBlockClose();
179
180     raw1394handle_t getHandle() {return m_handle;};
181
182     int getVerboseLevel();
183
184     bool addBusResetHandler( Functor* functor );
185     bool remBusResetHandler( Functor* functor );
186
187     /**
188      * @brief get the current generation
189      *
190      * @return the current generation
191      **/
192     unsigned int getGeneration() {
193         return raw1394_get_generation( m_handle );
194     }
195
196     /**
197      * @brief register an AddressRangeMapping Handler
198      * @param h pointer to the handler to register
199      *
200      * @return true on success or false on failure
201      **/
202
203     bool registerARMHandler( ARMHandler *h );
204
205     /**
206      * @brief unregister ARM range
207      * @param h pointer to the handler to unregister
208      * @return true if successful, false otherwise
209      */
210     bool unregisterARMHandler( ARMHandler *h );
211
212     nodeaddr_t findFreeARMBlock( nodeaddr_t start, size_t length, size_t step );
213
214 // ISO channel stuff
215 public:
216     signed int getAvailableBandwidth();
217     signed int allocateIsoChannelGeneric(unsigned int bandwidth);
218     signed int allocateIsoChannelCMP(nodeid_t xmit_node, int xmit_plug,
219                                      nodeid_t recv_node, int recv_plug);
220     bool freeIsoChannel(signed int channel);
221
222 private:
223     enum EAllocType {
224         AllocFree = 0, // not allocated (by us)
225         AllocGeneric = 1, // allocated with generic functions
226         AllocCMP=2 // allocated with CMP
227     };
228
229     struct ChannelInfo {
230         int channel;
231         int bandwidth;
232         enum EAllocType alloctype;
233         nodeid_t xmit_node;
234         int xmit_plug;
235         nodeid_t recv_node;
236         int recv_plug;
237     };
238
239     // the info for the channels we manage
240     struct ChannelInfo m_channels[64];
241
242     bool unregisterIsoChannel(unsigned int c);
243     bool registerIsoChannel(unsigned int c, struct ChannelInfo cinfo);
244
245 private:
246
247     bool startRHThread();
248     void stopRHThread();
249     static void* rHThread( void* arg );
250
251     void printBuffer( unsigned int level, size_t length, fb_quadlet_t* buffer ) const;
252     void printBufferBytes( unsigned int level, size_t length, byte_t* buffer ) const;
253
254     static int resetHandlerLowLevel( raw1394handle_t handle,
255                     unsigned int generation );
256     bool resetHandler( unsigned int generation );
257
258     static int armHandlerLowLevel(raw1394handle_t handle, unsigned long arm_tag,
259                      byte_t request_type, unsigned int requested_length,
260                      void *data);
261     bool armHandler(  unsigned long arm_tag,
262                      byte_t request_type, unsigned int requested_length,
263                      void *data);
264
265     raw1394handle_t m_handle;
266     raw1394handle_t m_resetHandle;
267     raw1394handle_t m_rtHandle; // a handle for operations from the rt thread
268     int             m_port;
269     std::string     m_portName;
270
271     pthread_t       m_thread;
272     pthread_mutex_t m_mutex;
273     bool            m_threadRunning;
274
275     typedef std::vector< Functor* > reset_handler_vec_t;
276     reset_handler_vec_t m_busResetHandlers;
277
278     // ARM stuff
279     arm_tag_handler_t m_default_arm_handler;
280
281     typedef std::vector< ARMHandler * > arm_handler_vec_t;
282     arm_handler_vec_t m_armHandlers;
283
284     fb_octlet_t byteSwap_octlet(fb_octlet_t value);
285
286 public:
287     void setVerboseLevel(int l);
288     void show();
289 private:
290     DECLARE_DEBUG_MODULE;
291 };
292
293 #endif // FFADO_IEEE1394SERVICE_H
Note: See TracBrowser for help on using the browser.