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

Revision 785, 6.5 kB (checked in by ppalmers, 15 years ago)

shutdown fix for DICE and MOTU

Line 
1 /*
2  * Copyright (C) 2005-2007 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 3 of the License, or
12  * (at your option) any later version.
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     char *vendor_name;
52     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 );
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 protected:
92     struct VendorModelEntry *m_model;
93
94     // streaming stuff
95     typedef std::vector< Streaming::StreamProcessor * > StreamProcessorVector;
96     typedef std::vector< Streaming::StreamProcessor * >::iterator StreamProcessorVectorIterator;
97     StreamProcessorVector m_receiveProcessors;
98     StreamProcessorVector m_transmitProcessors;
99
100 private: // streaming & port helpers
101     enum EPortTypes {
102         ePT_Analog,
103         ePT_MIDI,
104     };
105
106     typedef struct {
107         std::string name;
108         enum EPortTypes portType;
109         unsigned int streamPosition;
110         unsigned int streamLocation;
111     } diceChannelInfo;
112
113     bool addChannelToProcessor( diceChannelInfo *,
114                               Streaming::StreamProcessor *,
115                               Streaming::Port::E_Direction direction);
116
117     int allocateIsoChannel(unsigned int packet_size);
118     bool deallocateIsoChannel(int channel);
119
120 private: // helper functions
121     bool enableIsoStreaming();
122     bool disableIsoStreaming();
123     bool isIsoStreamingEnabled();
124
125     bool maskedCheckZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
126     bool maskedCheckNotZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
127
128     typedef std::vector< std::string > diceNameVector;
129     typedef std::vector< std::string >::iterator diceNameVectorIterator;
130     diceNameVector splitNameString(std::string in);
131     diceNameVector getTxNameString(unsigned int i);
132     diceNameVector getRxNameString(unsigned int i);
133     diceNameVector getClockSourceNameString();
134     std::string getDeviceNickName();
135
136     enum eClockSourceType  clockIdToType(unsigned int id);
137     bool isClockSourceIdLocked(unsigned int id, quadlet_t ext_status_reg);
138     bool isClockSourceIdSlipping(unsigned int id, quadlet_t ext_status_reg);
139
140 private: // register I/O routines
141     bool initIoFunctions();
142     // quadlet read/write routines
143     bool readReg(fb_nodeaddr_t, fb_quadlet_t *);
144     bool writeReg(fb_nodeaddr_t, fb_quadlet_t);
145     bool readRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
146     bool writeRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
147
148     bool readGlobalReg(fb_nodeaddr_t, fb_quadlet_t *);
149     bool writeGlobalReg(fb_nodeaddr_t, fb_quadlet_t);
150     bool readGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
151     bool writeGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
152     fb_nodeaddr_t globalOffsetGen(fb_nodeaddr_t, size_t);
153
154     bool readTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
155     bool writeTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
156     bool readTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
157     bool writeTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
158     fb_nodeaddr_t txOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
159
160     bool readRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
161     bool writeRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
162     bool readRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
163     bool writeRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
164     fb_nodeaddr_t rxOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
165
166     fb_quadlet_t m_global_reg_offset;
167     fb_quadlet_t m_global_reg_size;
168     fb_quadlet_t m_tx_reg_offset;
169     fb_quadlet_t m_tx_reg_size;
170     fb_quadlet_t m_rx_reg_offset;
171     fb_quadlet_t m_rx_reg_size;
172     fb_quadlet_t m_unused1_reg_offset;
173     fb_quadlet_t m_unused1_reg_size;
174     fb_quadlet_t m_unused2_reg_offset;
175     fb_quadlet_t m_unused2_reg_size;
176
177     fb_quadlet_t m_nb_tx;
178     fb_quadlet_t m_tx_size;
179     fb_quadlet_t m_nb_rx;
180     fb_quadlet_t m_rx_size;
181
182 private:
183     // notification
184     DiceNotifier *m_notifier;
185
186     /**
187      * this class reacts on the DICE device writing to the
188      * hosts notify address
189      */
190     #define DICE_NOTIFIER_BASE_ADDRESS 0x0000FFFFE0000000ULL
191     #define DICE_NOTIFIER_BLOCK_LENGTH 4
192     class DiceNotifier : public ARMHandler
193     {
194     public:
195         DiceNotifier(DiceAvDevice *, nodeaddr_t start);
196         virtual ~DiceNotifier();
197
198     private:
199         DiceAvDevice *m_dicedevice;
200     };
201 };
202
203 }
204 #endif
Note: See TracBrowser for help on using the browser.