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

Revision 1939, 7.5 kB (checked in by adi, 12 years ago)

Refactor startStreamByIndex and stopStreamByIndex.

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 "ffadotypes.h"
28 #include "ffadodevice.h"
29
30 #include "debugmodule/debugmodule.h"
31 #include "libavc/avc_definitions.h"
32
33 #include "libstreaming/amdtp/AmdtpReceiveStreamProcessor.h"
34 #include "libstreaming/amdtp/AmdtpTransmitStreamProcessor.h"
35 #include "libstreaming/amdtp/AmdtpPort.h"
36
37 #include "libieee1394/ieee1394service.h"
38
39 #include "libcontrol/Element.h"
40 #include "libcontrol/MatrixMixer.h"
41 #include "libcontrol/CrossbarRouter.h"
42
43 #include <string>
44 #include <vector>
45
46 class ConfigRom;
47 class Ieee1394Service;
48
49 namespace Util {
50     class Configuration;
51 }
52
53 namespace Dice {
54
55 class EAP;
56
57
58 /**
59   @brief Devices based on the DICE-platform
60
61   This class is the basic implementation for devices using the DICE-chip.
62   */
63 class Device : public FFADODevice {
64 private:
65     friend class EAP;
66
67 public:
68     /// constructor
69     Device( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
70     /// destructor
71     ~Device();
72
73     static bool probe( Util::Configuration& c, ConfigRom& configRom, bool generic = false );
74     static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
75     virtual bool discover();
76
77     static int getConfigurationId( );
78
79     virtual void showDevice();
80
81     virtual bool setSamplingFrequency( int samplingFrequency );
82     virtual int getSamplingFrequency( );
83     virtual std::vector<int> getSupportedSamplingFrequencies();
84
85     virtual ClockSourceVector getSupportedClockSources();
86     virtual bool setActiveClockSource(ClockSource);
87     virtual ClockSource getActiveClockSource();
88
89     virtual int getStreamCount();
90     virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i);
91
92     virtual bool prepare();
93
94     virtual bool lock();
95     virtual bool unlock();
96
97     virtual bool startStreamByIndex(int i);
98     virtual bool stopStreamByIndex(int i);
99
100     virtual bool enableStreaming();
101     virtual bool disableStreaming();
102
103     virtual std::string getNickname();
104     virtual bool setNickname(std::string name);
105
106 protected:
107     // streaming stuff
108     typedef std::vector< Streaming::StreamProcessor * > StreamProcessorVector;
109     typedef std::vector< Streaming::StreamProcessor * >::iterator StreamProcessorVectorIterator;
110     StreamProcessorVector m_receiveProcessors;
111     StreamProcessorVector m_transmitProcessors;
112
113 private: // streaming & port helpers
114     enum EPortTypes {
115         ePT_Analog,
116         ePT_MIDI,
117     };
118
119     typedef struct {
120         std::string name;
121         enum EPortTypes portType;
122         unsigned int streamPosition;
123         unsigned int streamLocation;
124     } diceChannelInfo;
125
126     bool addChannelToProcessor( diceChannelInfo *,
127                               Streaming::StreamProcessor *,
128                               Streaming::Port::E_Direction direction);
129
130     int allocateIsoChannel(unsigned int packet_size);
131     bool deallocateIsoChannel(int channel);
132
133 private: // active config
134     enum eDiceConfig {
135         eDC_Unknown,
136         eDC_Low,
137         eDC_Mid,
138         eDC_High,
139     };
140
141     enum eDiceConfig getCurrentConfig();
142
143 private: // helper functions
144     bool enableIsoStreaming();
145     bool disableIsoStreaming();
146     bool isIsoStreamingEnabled();
147
148     bool maskedCheckZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
149     bool maskedCheckNotZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
150
151     stringlist splitNameString(std::string in);
152     stringlist getTxNameString(unsigned int i);
153     stringlist getRxNameString(unsigned int i);
154     stringlist getClockSourceNameString();
155
156     enum eClockSourceType  clockIdToType(unsigned int id);
157     bool isClockSourceIdLocked(unsigned int id, quadlet_t ext_status_reg);
158     bool isClockSourceIdSlipping(unsigned int id, quadlet_t ext_status_reg);
159
160 // EAP stuff
161 private:
162     EAP*         m_eap;
163 protected:
164     virtual EAP* createEAP();
165 public:
166     EAP* getEAP() {return m_eap;};
167
168 private: // register I/O routines
169     bool initIoFunctions();
170     // functions used for RX/TX abstraction
171     bool startstopStreamByIndex(int i, const bool start);
172     bool prepareSP (unsigned int, const Streaming::Port::E_Direction direction_requested);
173     void setRXTXfuncs (const Streaming::Port::E_Direction direction);
174     // quadlet read/write routines
175     bool readReg(fb_nodeaddr_t, fb_quadlet_t *);
176     bool writeReg(fb_nodeaddr_t, fb_quadlet_t);
177     bool readRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
178     bool writeRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
179
180     bool readGlobalReg(fb_nodeaddr_t, fb_quadlet_t *);
181     bool writeGlobalReg(fb_nodeaddr_t, fb_quadlet_t);
182     bool readGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
183     bool writeGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
184     fb_nodeaddr_t globalOffsetGen(fb_nodeaddr_t, size_t);
185
186     bool readTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
187     bool writeTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
188     bool readTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
189     bool writeTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
190     fb_nodeaddr_t txOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
191
192     bool readRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
193     bool writeRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
194     bool readRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
195     bool writeRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
196     fb_nodeaddr_t rxOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
197
198     fb_quadlet_t m_global_reg_offset;
199     fb_quadlet_t m_global_reg_size;
200     fb_quadlet_t m_tx_reg_offset;
201     fb_quadlet_t m_tx_reg_size;
202     fb_quadlet_t m_rx_reg_offset;
203     fb_quadlet_t m_rx_reg_size;
204     fb_quadlet_t m_unused1_reg_offset;
205     fb_quadlet_t m_unused1_reg_size;
206     fb_quadlet_t m_unused2_reg_offset;
207     fb_quadlet_t m_unused2_reg_size;
208
209     fb_quadlet_t m_nb_tx;
210     fb_quadlet_t m_tx_size;
211     fb_quadlet_t m_nb_rx;
212     fb_quadlet_t m_rx_size;
213
214     fb_quadlet_t audio_base_register;
215     fb_quadlet_t midi_base_register;
216     char dir[3];
217
218     // Function pointers to call readTxReg/readRxReg or writeTxReg/writeRxReg respectively
219     bool (Device::*writeFunc) (unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t data);
220     bool (Device::*readFunc) (unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *result);
221
222 // private:
223 public:
224     /**
225      * this class reacts on the DICE device writing to the
226      * hosts notify address
227      */
228     #define DICE_NOTIFIER_BASE_ADDRESS 0x0000FFFFE0000000ULL
229     #define DICE_NOTIFIER_BLOCK_LENGTH 4
230     class Notifier : public Ieee1394Service::ARMHandler
231     {
232     public:
233         Notifier(Device &, nodeaddr_t start);
234         virtual ~Notifier();
235
236     private:
237         Device &m_device;
238     };
239
240     // notification
241     Notifier *m_notifier;
242
243
244
245 };
246
247 }
248 // vim: et
249 #endif
Note: See TracBrowser for help on using the browser.