root/trunk/libffado/src/dice/dice_avdevice.h

Revision 1239, 7.2 kB (checked in by ppalmers, 16 years ago)
Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef DICEDEVICE_H
25 #define DICEDEVICE_H
26
27 #include "ffadodevice.h"
28
29 #include "debugmodule/debugmodule.h"
30 #include "libavc/avc_definitions.h"
31
32 #include "libstreaming/amdtp/AmdtpReceiveStreamProcessor.h"
33 #include "libstreaming/amdtp/AmdtpTransmitStreamProcessor.h"
34 #include "libstreaming/amdtp/AmdtpPort.h"
35 #include "libieee1394/ARMHandler.h"
36
37 #include <string>
38 #include <vector>
39
40 class ConfigRom;
41 class Ieee1394Service;
42
43 namespace Dice {
44
45 class DiceNotifier;
46
47 // struct to define the supported devices
48 struct VendorModelEntry {
49     unsigned int vendor_id;
50     unsigned int model_id;
51     const char *vendor_name;
52     const char *model_name;
53 };
54
55 class DiceAvDevice : public FFADODevice {
56 private:
57     class DiceNotifier;
58 public:
59     DiceAvDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
60     ~DiceAvDevice();
61
62     static bool probe( ConfigRom& configRom, bool generic = false );
63     static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
64     virtual bool discover();
65
66     static int getConfigurationId( );
67
68     virtual void showDevice();
69
70     virtual bool setSamplingFrequency( int samplingFrequency );
71     virtual int getSamplingFrequency( );
72
73     virtual ClockSourceVector getSupportedClockSources();
74     virtual bool setActiveClockSource(ClockSource);
75     virtual ClockSource getActiveClockSource();
76
77     virtual int getStreamCount();
78     virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i);
79
80     virtual bool prepare();
81
82     virtual bool lock();
83     virtual bool unlock();
84
85     virtual bool startStreamByIndex(int i);
86     virtual bool stopStreamByIndex(int i);
87
88     virtual bool enableStreaming();
89     virtual bool disableStreaming();
90
91     virtual std::string getNickname();
92     virtual bool setNickname(std::string name);
93
94 protected:
95     struct VendorModelEntry *m_model;
96
97     // streaming stuff
98     typedef std::vector< Streaming::StreamProcessor * > StreamProcessorVector;
99     typedef std::vector< Streaming::StreamProcessor * >::iterator StreamProcessorVectorIterator;
100     StreamProcessorVector m_receiveProcessors;
101     StreamProcessorVector m_transmitProcessors;
102
103 private: // streaming & port helpers
104     enum EPortTypes {
105         ePT_Analog,
106         ePT_MIDI,
107     };
108
109     typedef struct {
110         std::string name;
111         enum EPortTypes portType;
112         unsigned int streamPosition;
113         unsigned int streamLocation;
114     } diceChannelInfo;
115
116     bool addChannelToProcessor( diceChannelInfo *,
117                               Streaming::StreamProcessor *,
118                               Streaming::Port::E_Direction direction);
119
120     int allocateIsoChannel(unsigned int packet_size);
121     bool deallocateIsoChannel(int channel);
122
123 private: // helper functions
124     bool enableIsoStreaming();
125     bool disableIsoStreaming();
126     bool isIsoStreamingEnabled();
127
128     bool maskedCheckZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
129     bool maskedCheckNotZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
130
131     typedef std::vector< std::string > diceNameVector;
132     typedef std::vector< std::string >::iterator diceNameVectorIterator;
133     diceNameVector splitNameString(std::string in);
134     diceNameVector getTxNameString(unsigned int i);
135     diceNameVector getRxNameString(unsigned int i);
136     diceNameVector getClockSourceNameString();
137     std::string getDeviceNickName();
138     bool setDeviceNickName(std::string name);
139
140     enum eClockSourceType  clockIdToType(unsigned int id);
141     bool isClockSourceIdLocked(unsigned int id, quadlet_t ext_status_reg);
142     bool isClockSourceIdSlipping(unsigned int id, quadlet_t ext_status_reg);
143
144 private: // register I/O routines
145     bool initIoFunctions();
146     // quadlet read/write routines
147     bool readReg(fb_nodeaddr_t, fb_quadlet_t *);
148     bool writeReg(fb_nodeaddr_t, fb_quadlet_t);
149     bool readRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
150     bool writeRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
151     bool readRegBlockSwapped(fb_nodeaddr_t, fb_quadlet_t *, size_t);
152     bool writeRegBlockSwapped(fb_nodeaddr_t, fb_quadlet_t *, size_t);
153
154     bool readGlobalReg(fb_nodeaddr_t, fb_quadlet_t *);
155     bool writeGlobalReg(fb_nodeaddr_t, fb_quadlet_t);
156     bool readGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
157     bool writeGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
158     bool readGlobalRegBlockSwapped(fb_nodeaddr_t, fb_quadlet_t *, size_t);
159     bool writeGlobalRegBlockSwapped(fb_nodeaddr_t, fb_quadlet_t *, size_t);
160     fb_nodeaddr_t globalOffsetGen(fb_nodeaddr_t, size_t);
161
162     bool readTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
163     bool writeTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
164     bool readTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
165     bool writeTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
166     bool readTxRegBlockSwapped(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
167     fb_nodeaddr_t txOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
168
169     bool readRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
170     bool writeRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
171     bool readRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
172     bool writeRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
173     bool readRxRegBlockSwapped(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
174     fb_nodeaddr_t rxOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
175
176     fb_quadlet_t m_global_reg_offset;
177     fb_quadlet_t m_global_reg_size;
178     fb_quadlet_t m_tx_reg_offset;
179     fb_quadlet_t m_tx_reg_size;
180     fb_quadlet_t m_rx_reg_offset;
181     fb_quadlet_t m_rx_reg_size;
182     fb_quadlet_t m_unused1_reg_offset;
183     fb_quadlet_t m_unused1_reg_size;
184     fb_quadlet_t m_unused2_reg_offset;
185     fb_quadlet_t m_unused2_reg_size;
186
187     fb_quadlet_t m_nb_tx;
188     fb_quadlet_t m_tx_size;
189     fb_quadlet_t m_nb_rx;
190     fb_quadlet_t m_rx_size;
191
192 private:
193     // notification
194     DiceNotifier *m_notifier;
195
196     /**
197      * this class reacts on the DICE device writing to the
198      * hosts notify address
199      */
200     #define DICE_NOTIFIER_BASE_ADDRESS 0x0000FFFFE0000000ULL
201     #define DICE_NOTIFIER_BLOCK_LENGTH 4
202     class DiceNotifier : public ARMHandler
203     {
204     public:
205         DiceNotifier(DiceAvDevice *, nodeaddr_t start);
206         virtual ~DiceNotifier();
207
208     private:
209         DiceAvDevice *m_dicedevice;
210     };
211 };
212
213 }
214 #endif
Note: See TracBrowser for help on using the browser.