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

Revision 445, 7.6 kB (checked in by pieterpalmers, 14 years ago)

* name change from FreeBoB to FFADO
* replaced tabs by 4 spaces
* got rid of end-of-line spaces
* made all license and copyrights conform

library becomes LGPL, apps become GPL
explicitly state LGPL v2.1 and GPL v2 (don't like v3 draft)

copyrights are 2005-2007 Daniel & Pieter
except for the MotU stuff (C) Jonathan, Pieter

  • 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 register an AddressRangeMapping Handler
161      * @param h pointer to the handler to register
162      *
163      * @return true on success or false on failure
164      **/
165
166     bool registerARMHandler( ARMHandler *h );
167
168     /**
169      * @brief unregister ARM range
170      * @param h pointer to the handler to unregister
171      * @return true if successful, false otherwise
172      */
173     bool unregisterARMHandler( ARMHandler *h );
174
175     nodeaddr_t findFreeARMBlock( nodeaddr_t start, size_t length, size_t step );
176
177 // ISO channel stuff
178 public:
179     signed int getAvailableBandwidth();
180     signed int allocateIsoChannelGeneric(unsigned int bandwidth);
181     signed int allocateIsoChannelCMP(nodeid_t xmit_node, int xmit_plug,
182                                      nodeid_t recv_node, int recv_plug);
183     bool freeIsoChannel(signed int channel);
184
185 private:
186     enum EAllocType {
187         AllocFree = 0, // not allocated (by us)
188         AllocGeneric = 1, // allocated with generic functions
189         AllocCMP=2 // allocated with CMP
190     };
191
192     struct ChannelInfo {
193         int channel;
194         int bandwidth;
195         enum EAllocType alloctype;
196         nodeid_t xmit_node;
197         int xmit_plug;
198         nodeid_t recv_node;
199         int recv_plug;
200     };
201
202     // the info for the channels we manage
203     struct ChannelInfo m_channels[64];
204
205     bool unregisterIsoChannel(unsigned int c);
206     bool registerIsoChannel(unsigned int c, struct ChannelInfo cinfo);
207
208 private:
209
210     bool startRHThread();
211     void stopRHThread();
212     static void* rHThread( void* arg );
213
214     void printBuffer( unsigned int level, size_t length, fb_quadlet_t* buffer ) const;
215     void printBufferBytes( unsigned int level, size_t length, byte_t* buffer ) const;
216
217     static int resetHandlerLowLevel( raw1394handle_t handle,
218                     unsigned int generation );
219     bool resetHandler( unsigned int generation );
220
221     static int armHandlerLowLevel(raw1394handle_t handle, unsigned long arm_tag,
222                      byte_t request_type, unsigned int requested_length,
223                      void *data);
224     bool armHandler(  unsigned long arm_tag,
225                      byte_t request_type, unsigned int requested_length,
226                      void *data);
227
228     raw1394handle_t m_handle;
229     raw1394handle_t m_resetHandle;
230     int             m_port;
231     unsigned int    m_generation;
232
233     pthread_t       m_thread;
234     pthread_mutex_t m_mutex;
235     bool            m_threadRunning;
236
237     typedef std::vector< Functor* > reset_handler_vec_t;
238     reset_handler_vec_t m_busResetHandlers;
239
240     // ARM stuff
241     arm_tag_handler_t m_default_arm_handler;
242
243     typedef std::vector< ARMHandler * > arm_handler_vec_t;
244     arm_handler_vec_t m_armHandlers;
245
246     fb_octlet_t byteSwap_octlet(fb_octlet_t value);
247
248 public:
249     void setVerboseLevel(int l);
250 private:
251     DECLARE_DEBUG_MODULE;
252 };
253
254 #endif // FFADO_IEEE1394SERVICE_H
Note: See TracBrowser for help on using the browser.