root/branches/libffado-2.0/src/libieee1394/ieee1394service.h

Revision 1190, 9.4 kB (checked in by ppalmers, 13 years ago)

remove unused code, clean up for release

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