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

Revision 414, 6.5 kB (checked in by pieterpalmers, 16 years ago)

extended ARM handler functionality

  • 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     * @return the node id of the local node
62     * This value can change with every bus reset.
63     */
64     nodeid_t getLocalNodeId();
65    
66    /**
67     * @brief send async read request to a node and wait for response.
68     *
69     * This does the complete transaction and will return when it's finished.
70     *
71     * @param node target node (\todo needs 0xffc0 stuff)
72     * @param addr address to read from
73     * @param length amount of data to read in quadlets
74     * @param buffer pointer to buffer where data will be saved
75    
76     * @return true on success or false on failure (sets errno)
77     */
78     bool read( fb_nodeid_t nodeId,
79                fb_nodeaddr_t addr,
80                size_t length,
81                fb_quadlet_t* buffer );
82
83     bool read_quadlet( fb_nodeid_t nodeId,
84                        fb_nodeaddr_t addr,
85                        fb_quadlet_t* buffer );
86
87     bool read_octlet( fb_nodeid_t nodeId,
88                       fb_nodeaddr_t addr,
89                       fb_octlet_t* buffer );
90
91     /**
92     * @brief send async write request to a node and wait for response.
93     *
94     * This does the complete transaction and will return when it's finished.
95     *
96     * @param node target node (\XXX needs 0xffc0 stuff)
97     * @param addr address to write to
98     * @param length amount of data to write in quadlets
99     * @param data pointer to data to be sent
100     *
101     * @return true on success or false on failure (sets errno)
102     */
103     bool write( fb_nodeid_t nodeId,
104                 fb_nodeaddr_t addr,
105                 size_t length,
106                 fb_quadlet_t* data );
107
108     bool write_quadlet( fb_nodeid_t nodeId,
109                         fb_nodeaddr_t addr,
110                         fb_quadlet_t data );
111
112     bool write_octlet(  fb_nodeid_t nodeId,
113                         fb_nodeaddr_t addr,
114                         fb_octlet_t data );
115
116     fb_quadlet_t* transactionBlock( fb_nodeid_t nodeId,
117                                     fb_quadlet_t* buf,
118                                     int len,
119                                     unsigned int* resp_len );
120
121     bool transactionBlockClose();
122
123     raw1394handle_t getHandle() {return m_handle;};
124
125     bool setVerbose( int verboseLevel );
126     int getVerboseLevel();
127
128     bool addBusResetHandler( Functor* functor );
129     bool remBusResetHandler( Functor* functor );
130    
131     /**
132      * @brief register an AddressRangeMapping Handler
133      * @param h pointer to the handler to register
134      *
135      * @return true on success or false on failure
136      **/
137
138     bool registerARMhandler( ARMHandler *h );
139
140     /**
141      * @brief unregister ARM range
142      * @param h pointer to the handler to unregister
143      * @return true if successful, false otherwise
144      */
145     bool unregisterARMhandler( ARMHandler *h );
146    
147     nodeaddr_t findFreeARMBlock( nodeaddr_t start, size_t length, size_t step );
148
149 // ISO channel stuff
150 public:
151     signed int getAvailableBandwidth();
152     signed int allocateIsoChannelGeneric(unsigned int bandwidth);
153     signed int allocateIsoChannelCMP(nodeid_t xmit_node, int xmit_plug,
154                                      nodeid_t recv_node, int recv_plug);
155     bool freeIsoChannel(signed int channel);
156    
157 private:
158     enum EAllocType {
159         AllocFree = 0, // not allocated (by us)
160         AllocGeneric = 1, // allocated with generic functions
161         AllocCMP=2 // allocated with CMP
162     };
163
164     struct ChannelInfo {
165         int channel;
166         int bandwidth;
167         enum EAllocType alloctype;
168         nodeid_t xmit_node;
169         int xmit_plug;
170         nodeid_t recv_node;
171         int recv_plug;
172     };
173    
174     // the info for the channels we manage
175     struct ChannelInfo m_channels[64];
176    
177     bool unregisterIsoChannel(unsigned int c);
178     bool registerIsoChannel(unsigned int c, struct ChannelInfo cinfo);
179
180 private:
181
182     bool startRHThread();
183     void stopRHThread();
184     static void* rHThread( void* arg );
185
186     void printBuffer( unsigned int level, size_t length, fb_quadlet_t* buffer ) const;
187     void printBufferBytes( unsigned int level, size_t length, byte_t* buffer ) const;
188    
189     static int resetHandlerLowLevel( raw1394handle_t handle,
190                     unsigned int generation );
191     bool resetHandler( unsigned int generation );
192    
193     static int armHandlerLowLevel(raw1394handle_t handle, unsigned long arm_tag,
194                      byte_t request_type, unsigned int requested_length,
195                      void *data);
196     bool armHandler(  unsigned long arm_tag,
197                      byte_t request_type, unsigned int requested_length,
198                      void *data);
199
200     raw1394handle_t m_handle;
201     raw1394handle_t m_resetHandle;
202     int             m_port;
203     unsigned int    m_generation;
204
205     pthread_t       m_thread;
206     pthread_mutex_t m_mutex;
207     bool            m_threadRunning;
208
209     typedef std::vector< Functor* > reset_handler_vec_t;
210     reset_handler_vec_t m_busResetHandlers;
211    
212     // ARM stuff
213     arm_tag_handler_t m_default_arm_handler;
214    
215     typedef std::vector< ARMHandler * > arm_handler_vec_t;
216     arm_handler_vec_t m_armHandlers;
217    
218     DECLARE_DEBUG_MODULE;
219 };
220
221 #endif
Note: See TracBrowser for help on using the browser.