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

Revision 436, 7.5 kB (checked in by pieterpalmers, 14 years ago)

- fixed verbose level setting
- debugged DICE code, works with EVM

  • 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 "IEC61883.h"
31
32 #include <libraw1394/raw1394.h>
33 #include <pthread.h>
34
35 #include <vector>
36
37 class ARMHandler;
38
39 class Ieee1394Service : public IEC61883 {
40 public:
41     Ieee1394Service();
42     ~Ieee1394Service();
43
44     bool initialize( int port );
45
46     int getPort()
47         { return m_port; }
48    /**
49     * @brief get number of nodes on the bus
50     *
51     * Since the root node always has
52     * the highest node ID, this number can be used to determine that ID (it's
53     * LOCAL_BUS|(count-1)).
54     *
55     * @return the number of nodes on the bus to which the port is connected.
56     * This value can change with every bus reset.
57     */
58     int getNodeCount();
59    
60    /**
61     * @brief get the node id of the local node
62     *
63     * @note does not include the bus part (0xFFC0)
64     *
65     * @return the node id of the local node
66     * This value can change with every bus reset.
67     */
68     nodeid_t getLocalNodeId();
69    
70    /**
71     * @brief send async read request to a node and wait for response.
72     *
73     * This does the complete transaction and will return when it's finished.
74     *
75     * @param node target node (\todo needs 0xffc0 stuff)
76     * @param addr address to read from
77     * @param length amount of data to read in quadlets
78     * @param buffer pointer to buffer where data will be saved
79    
80     * @return true on success or false on failure (sets errno)
81     */
82     bool read( fb_nodeid_t nodeId,
83                fb_nodeaddr_t addr,
84                size_t length,
85                fb_quadlet_t* buffer );
86
87     bool read_quadlet( fb_nodeid_t nodeId,
88                        fb_nodeaddr_t addr,
89                        fb_quadlet_t* buffer );
90
91     bool read_octlet( fb_nodeid_t nodeId,
92                       fb_nodeaddr_t addr,
93                       fb_octlet_t* buffer );
94
95     /**
96     * @brief send async write request to a node and wait for response.
97     *
98     * This does the complete transaction and will return when it's finished.
99     *
100     * @param node target node (\XXX needs 0xffc0 stuff)
101     * @param addr address to write to
102     * @param length amount of data to write in quadlets
103     * @param data pointer to data to be sent
104     *
105     * @return true on success or false on failure (sets errno)
106     */
107     bool write( fb_nodeid_t nodeId,
108                 fb_nodeaddr_t addr,
109                 size_t length,
110                 fb_quadlet_t* data );
111
112     bool write_quadlet( fb_nodeid_t nodeId,
113                         fb_nodeaddr_t addr,
114                         fb_quadlet_t data );
115
116     bool write_octlet(  fb_nodeid_t nodeId,
117                         fb_nodeaddr_t addr,
118                         fb_octlet_t data );
119
120     /**
121      * @brief send 64-bit compare-swap lock request and wait for response.
122      *
123      * swaps the content of \ref addr with \ref swap_value , but only if
124      * the content of \ref addr equals \ref compare_with
125      *
126      * @note takes care of endiannes
127      *
128      * @param nodeId target node ID
129      * @param addr address within target node address space
130      * @param compare_with value to compare \ref addr with
131      * @param swap_value new value to put in \ref addr
132      * @param result the value (originally) in \ref addr
133      *
134      * @return true if succesful, false otherwise
135      */
136     bool lockCompareSwap64(  fb_nodeid_t nodeId,
137                         fb_nodeaddr_t addr,
138                         fb_octlet_t  compare_value,
139                         fb_octlet_t  swap_value,
140                         fb_octlet_t* result );
141
142     fb_quadlet_t* transactionBlock( fb_nodeid_t nodeId,
143                                     fb_quadlet_t* buf,
144                                     int len,
145                                     unsigned int* resp_len );
146
147     bool transactionBlockClose();
148
149     raw1394handle_t getHandle() {return m_handle;};
150
151     int getVerboseLevel();
152
153     bool addBusResetHandler( Functor* functor );
154     bool remBusResetHandler( Functor* functor );
155    
156     /**
157      * @brief register an AddressRangeMapping Handler
158      * @param h pointer to the handler to register
159      *
160      * @return true on success or false on failure
161      **/
162
163     bool registerARMHandler( ARMHandler *h );
164
165     /**
166      * @brief unregister ARM range
167      * @param h pointer to the handler to unregister
168      * @return true if successful, false otherwise
169      */
170     bool unregisterARMHandler( ARMHandler *h );
171    
172     nodeaddr_t findFreeARMBlock( nodeaddr_t start, size_t length, size_t step );
173
174 // ISO channel stuff
175 public:
176     signed int getAvailableBandwidth();
177     signed int allocateIsoChannelGeneric(unsigned int bandwidth);
178     signed int allocateIsoChannelCMP(nodeid_t xmit_node, int xmit_plug,
179                                      nodeid_t recv_node, int recv_plug);
180     bool freeIsoChannel(signed int channel);
181    
182 private:
183     enum EAllocType {
184         AllocFree = 0, // not allocated (by us)
185         AllocGeneric = 1, // allocated with generic functions
186         AllocCMP=2 // allocated with CMP
187     };
188
189     struct ChannelInfo {
190         int channel;
191         int bandwidth;
192         enum EAllocType alloctype;
193         nodeid_t xmit_node;
194         int xmit_plug;
195         nodeid_t recv_node;
196         int recv_plug;
197     };
198    
199     // the info for the channels we manage
200     struct ChannelInfo m_channels[64];
201    
202     bool unregisterIsoChannel(unsigned int c);
203     bool registerIsoChannel(unsigned int c, struct ChannelInfo cinfo);
204
205 private:
206
207     bool startRHThread();
208     void stopRHThread();
209     static void* rHThread( void* arg );
210
211     void printBuffer( unsigned int level, size_t length, fb_quadlet_t* buffer ) const;
212     void printBufferBytes( unsigned int level, size_t length, byte_t* buffer ) const;
213    
214     static int resetHandlerLowLevel( raw1394handle_t handle,
215                     unsigned int generation );
216     bool resetHandler( unsigned int generation );
217    
218     static int armHandlerLowLevel(raw1394handle_t handle, unsigned long arm_tag,
219                      byte_t request_type, unsigned int requested_length,
220                      void *data);
221     bool armHandler(  unsigned long arm_tag,
222                      byte_t request_type, unsigned int requested_length,
223                      void *data);
224
225     raw1394handle_t m_handle;
226     raw1394handle_t m_resetHandle;
227     int             m_port;
228     unsigned int    m_generation;
229
230     pthread_t       m_thread;
231     pthread_mutex_t m_mutex;
232     bool            m_threadRunning;
233
234     typedef std::vector< Functor* > reset_handler_vec_t;
235     reset_handler_vec_t m_busResetHandlers;
236    
237     // ARM stuff
238     arm_tag_handler_t m_default_arm_handler;
239    
240     typedef std::vector< ARMHandler * > arm_handler_vec_t;
241     arm_handler_vec_t m_armHandlers;
242    
243     fb_octlet_t byteSwap_octlet(fb_octlet_t value);
244    
245 public:
246     void setVerboseLevel(int l);
247 private:
248     DECLARE_DEBUG_MODULE;
249 };
250
251 #endif
Note: See TracBrowser for help on using the browser.