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

Revision 864, 10.3 kB (checked in by ppalmers, 13 years ago)

update license to GPLv2 or GPLv3 instead of GPLv2 or any later version. Update copyrights to reflect the new year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Copyright (C) 2005-2008 by Daniel Wagner
3  * Copyright (C) 2005-2008 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 2 of the License, or
13  * (at your option) version 3 of the License.
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 class IsoHandlerManager;
43 class CycleTimerHelper;
44
45 namespace Util {
46     class TimeSource;
47 }
48
49 class Ieee1394Service : public IEC61883 {
50 public:
51     Ieee1394Service();
52     Ieee1394Service(bool rt, int prio);
53     ~Ieee1394Service();
54
55     bool initialize( int port );
56     bool setThreadParameters(bool rt, int priority);
57    /**
58     * @brief get number of ports (firewire adapters) in this machine
59     *
60     * @return the number of ports
61     */
62     static unsigned int detectNbPorts();
63
64    /**
65     * @brief get port (adapter) id
66     *
67     * @return get port (adapter) id
68     */
69     int getPort()
70         { return m_port; }
71
72    /**
73     * @brief get port (adapter) name
74     *
75     * @return get port (adapter) name
76     */
77     std::string getPortName()
78         { return m_portName; };
79
80    /**
81     * @brief get number of nodes on the bus
82     *
83     * Since the root node always has
84     * the highest node ID, this number can be used to determine that ID (it's
85     * LOCAL_BUS|(count-1)).
86     *
87     * @return the number of nodes on the bus to which the port is connected.
88     * This value can change with every bus reset.
89     */
90     int getNodeCount();
91
92    /**
93     * @brief get the node id of the local node
94     *
95     * @note does not include the bus part (0xFFC0)
96     *
97     * @return the node id of the local node
98     * This value can change with every bus reset.
99     */
100     nodeid_t getLocalNodeId();
101
102     /**
103      * @brief get the most recent cycle timer value (in ticks)
104      *
105      * @note Uses the most appropriate method for getting the cycle timer
106      *       which is not necessarily a direct read (could be DLL)
107      */
108     uint32_t getCycleTimerTicks();
109
110     /**
111      * @brief get the most recent cycle timer value (in CTR format)
112      *
113      * @note Uses the most appropriate method for getting the cycle timer
114      *       which is not necessarily a direct read (could be DLL)
115      */
116     uint32_t getCycleTimer();
117
118     /**
119      * @brief get the cycle timer value for a specific time instant (in ticks)
120      *
121      * @note Uses the most appropriate method for getting the cycle timer
122      *       which is not necessarily a direct read (could be DLL)
123      */
124     uint32_t getCycleTimerTicks(uint64_t t);
125
126     /**
127      * @brief get the cycle timer value for a specific time instant (in CTR format)
128      *
129      * @note Uses the most appropriate method for getting the cycle timer
130      *       which is not necessarily a direct read (could be DLL)
131      */
132     uint32_t getCycleTimer(uint64_t t);
133
134     /**
135      * @brief read the cycle timer value from the controller (in CTR format)
136      *
137      * @note Uses a direct method to read the value from the controller
138      * @return true if successful
139      */
140     bool readCycleTimerReg(uint32_t *cycle_timer, uint64_t *local_time);
141
142     /**
143      * @brief provide the current system time
144      * @return
145      */
146     uint64_t getCurrentTimeAsUsecs();
147
148     /**
149      * @brief send async read request to a node and wait for response.
150      *
151      * This does the complete transaction and will return when it's finished.
152      *
153      * @param node target node (\todo needs 0xffc0 stuff)
154      * @param addr address to read from
155      * @param length amount of data to read in quadlets
156      * @param buffer pointer to buffer where data will be saved
157      *
158      * @return true on success or false on failure (sets errno)
159      */
160     bool read( fb_nodeid_t nodeId,
161            fb_nodeaddr_t addr,
162            size_t length,
163            fb_quadlet_t* buffer );
164
165     bool read_quadlet( fb_nodeid_t nodeId,
166                        fb_nodeaddr_t addr,
167                        fb_quadlet_t* buffer );
168
169     bool read_octlet( fb_nodeid_t nodeId,
170                       fb_nodeaddr_t addr,
171                       fb_octlet_t* buffer );
172
173     /**
174     * @brief send async write request to a node and wait for response.
175     *
176     * This does the complete transaction and will return when it's finished.
177     *
178     * @param node target node (\XXX needs 0xffc0 stuff)
179     * @param addr address to write to
180     * @param length amount of data to write in quadlets
181     * @param data pointer to data to be sent
182     *
183     * @return true on success or false on failure (sets errno)
184     */
185     bool write( fb_nodeid_t nodeId,
186         fb_nodeaddr_t addr,
187         size_t length,
188         fb_quadlet_t* data );
189
190     bool write_quadlet( fb_nodeid_t nodeId,
191                         fb_nodeaddr_t addr,
192                         fb_quadlet_t data );
193
194     bool write_octlet(  fb_nodeid_t nodeId,
195                         fb_nodeaddr_t addr,
196                         fb_octlet_t data );
197
198     /**
199      * @brief send 64-bit compare-swap lock request and wait for response.
200      *
201      * swaps the content of \ref addr with \ref swap_value , but only if
202      * the content of \ref addr equals \ref compare_with
203      *
204      * @note takes care of endiannes
205      *
206      * @param nodeId target node ID
207      * @param addr address within target node address space
208      * @param compare_with value to compare \ref addr with
209      * @param swap_value new value to put in \ref addr
210      * @param result the value (originally) in \ref addr
211      *
212      * @return true if succesful, false otherwise
213      */
214     bool lockCompareSwap64(  fb_nodeid_t nodeId,
215                         fb_nodeaddr_t addr,
216                         fb_octlet_t  compare_value,
217                         fb_octlet_t  swap_value,
218                         fb_octlet_t* result );
219
220     fb_quadlet_t* transactionBlock( fb_nodeid_t nodeId,
221                                     fb_quadlet_t* buf,
222                                     int len,
223                     unsigned int* resp_len );
224
225     bool transactionBlockClose();
226
227     raw1394handle_t getHandle() {return m_handle;};
228
229     int getVerboseLevel();
230
231     bool addBusResetHandler( Functor* functor );
232     bool remBusResetHandler( Functor* functor );
233
234     /**
235      * @brief get the current generation
236      *
237      * @return the current generation
238      **/
239     unsigned int getGeneration() {
240         return raw1394_get_generation( m_handle );
241     }
242
243     /**
244      * @brief register an AddressRangeMapping Handler
245      * @param h pointer to the handler to register
246      *
247      * @return true on success or false on failure
248      **/
249
250     bool registerARMHandler( ARMHandler *h );
251
252     /**
253      * @brief unregister ARM range
254      * @param h pointer to the handler to unregister
255      * @return true if successful, false otherwise
256      */
257     bool unregisterARMHandler( ARMHandler *h );
258
259     nodeaddr_t findFreeARMBlock( nodeaddr_t start, size_t length, size_t step );
260
261 // ISO channel stuff
262 public:
263     signed int getAvailableBandwidth();
264     signed int allocateIsoChannelGeneric(unsigned int bandwidth);
265     signed int allocateIsoChannelCMP(nodeid_t xmit_node, int xmit_plug,
266                                      nodeid_t recv_node, int recv_plug);
267     bool freeIsoChannel(signed int channel);
268
269     IsoHandlerManager& getIsoHandlerManager() {return *m_pIsoManager;};
270 private:
271     enum EAllocType {
272         AllocFree = 0, // not allocated (by us)
273         AllocGeneric = 1, // allocated with generic functions
274         AllocCMP=2 // allocated with CMP
275     };
276
277     struct ChannelInfo {
278         int channel;
279         int bandwidth;
280         enum EAllocType alloctype;
281         nodeid_t xmit_node;
282         int xmit_plug;
283         nodeid_t recv_node;
284         int recv_plug;
285     };
286
287     // the info for the channels we manage
288     struct ChannelInfo m_channels[64];
289
290     bool unregisterIsoChannel(unsigned int c);
291     bool registerIsoChannel(unsigned int c, struct ChannelInfo cinfo);
292
293 private:
294
295     bool startRHThread();
296     void stopRHThread();
297     static void* rHThread( void* arg );
298
299     void printBuffer( unsigned int level, size_t length, fb_quadlet_t* buffer ) const;
300     void printBufferBytes( unsigned int level, size_t length, byte_t* buffer ) const;
301
302     static int resetHandlerLowLevel( raw1394handle_t handle,
303                     unsigned int generation );
304     bool resetHandler( unsigned int generation );
305
306     static int armHandlerLowLevel(raw1394handle_t handle, unsigned long arm_tag,
307                      byte_t request_type, unsigned int requested_length,
308                      void *data);
309     bool armHandler(  unsigned long arm_tag,
310                      byte_t request_type, unsigned int requested_length,
311                      void *data);
312
313     raw1394handle_t m_handle;
314     raw1394handle_t m_resetHandle;
315     raw1394handle_t m_util_handle; // a handle for operations from the rt thread
316     int             m_port;
317     std::string     m_portName;
318
319     pthread_t       m_thread;
320     pthread_mutex_t m_mutex;
321     bool            m_threadRunning;
322
323     bool            m_realtime;
324     int             m_base_priority;
325
326     IsoHandlerManager*      m_pIsoManager;
327     CycleTimerHelper*       m_pCTRHelper;
328     bool                    m_have_new_ctr_read;
329
330     // the time source
331     Util::TimeSource*   m_pTimeSource;
332
333     typedef std::vector< Functor* > reset_handler_vec_t;
334     reset_handler_vec_t m_busResetHandlers;
335
336     // ARM stuff
337     arm_tag_handler_t m_default_arm_handler;
338
339     typedef std::vector< ARMHandler * > arm_handler_vec_t;
340     arm_handler_vec_t m_armHandlers;
341
342     fb_octlet_t byteSwap_octlet(fb_octlet_t value);
343
344 public:
345     void setVerboseLevel(int l);
346     void show();
347 private:
348     DECLARE_DEBUG_MODULE;
349 };
350
351 #endif // FFADO_IEEE1394SERVICE_H
Note: See TracBrowser for help on using the browser.