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

Revision 1937, 7.5 kB (checked in by adi, 13 years ago)

Heavy refactoring.

I moved writeFunc and readFunc to .h and merged the two for-loops in
prepare(). This code is actually now in prepareSP(), prepare() only
contains the calling loops.

Note that in contrast to the previous code, I conditionally set dll_bw
depending whether it's RX or TX. I guess it was a copy-and-paste error
before. (I'm talking about line 1001 in r1936)

Works for my Alesis device.

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 prepareSP (unsigned int, const Streaming::Port::E_Direction direction_requested);
172     void setRXTXfuncs (const Streaming::Port::E_Direction direction);
173     // quadlet read/write routines
174     bool readReg(fb_nodeaddr_t, fb_quadlet_t *);
175     bool writeReg(fb_nodeaddr_t, fb_quadlet_t);
176     bool readRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
177     bool writeRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
178
179     bool readGlobalReg(fb_nodeaddr_t, fb_quadlet_t *);
180     bool writeGlobalReg(fb_nodeaddr_t, fb_quadlet_t);
181     bool readGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
182     bool writeGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
183     fb_nodeaddr_t globalOffsetGen(fb_nodeaddr_t, size_t);
184
185     bool readTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
186     bool writeTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
187     bool readTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
188     bool writeTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
189     fb_nodeaddr_t txOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
190
191     bool readRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
192     bool writeRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
193     bool readRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
194     bool writeRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
195     fb_nodeaddr_t rxOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
196
197     fb_quadlet_t m_global_reg_offset;
198     fb_quadlet_t m_global_reg_size;
199     fb_quadlet_t m_tx_reg_offset;
200     fb_quadlet_t m_tx_reg_size;
201     fb_quadlet_t m_rx_reg_offset;
202     fb_quadlet_t m_rx_reg_size;
203     fb_quadlet_t m_unused1_reg_offset;
204     fb_quadlet_t m_unused1_reg_size;
205     fb_quadlet_t m_unused2_reg_offset;
206     fb_quadlet_t m_unused2_reg_size;
207
208     fb_quadlet_t m_nb_tx;
209     fb_quadlet_t m_tx_size;
210     fb_quadlet_t m_nb_rx;
211     fb_quadlet_t m_rx_size;
212
213     fb_quadlet_t audio_base_register;
214     fb_quadlet_t midi_base_register;
215     char dir[3];
216
217     // Function pointers to call readTxReg/readRxReg or writeTxReg/writeRxReg respectively
218     bool (Device::*writeFunc) (unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t data);
219     bool (Device::*readFunc) (unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *result);
220
221 // private:
222 public:
223     /**
224      * this class reacts on the DICE device writing to the
225      * hosts notify address
226      */
227     #define DICE_NOTIFIER_BASE_ADDRESS 0x0000FFFFE0000000ULL
228     #define DICE_NOTIFIER_BLOCK_LENGTH 4
229     class Notifier : public Ieee1394Service::ARMHandler
230     {
231     public:
232         Notifier(Device &, nodeaddr_t start);
233         virtual ~Notifier();
234
235     private:
236         Device &m_device;
237     };
238
239     // notification
240     Notifier *m_notifier;
241
242
243
244 };
245
246 }
247 // vim: et
248 #endif
Note: See TracBrowser for help on using the browser.