root/branches/streaming-rework/src/libieee1394/ieee1394service.h

Revision 415, 7.4 kB (checked in by pieterpalmers, 15 years ago)

ieee1394service:
- implemented 64bit compare-swap-lock operation (needed for DICE)
- small name change of (un)registerARMhandler to (un)registerARMHandler

iavdevice.h:
- made the stream start/stop functions return bool instead of int
- updated function documentation for consistency and to reflect changes

BeBoB avdevice:
- replaced the 2 fixed streamprocessor pointers with a 2 vectors of streamprocessors
- implemented the 'snoop mode' (cannot be activated yet)

libstreaming:
- removed unused 'type' attribute from AmdtpPortInfo? & children

mh_avdevice, motu_avdevice, rme_avdevice:
- replaced m_1394service with m_p1394service for consistence

maudio_avdevice.cpp:
- removed unused code

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