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

Revision 745, 6.4 kB (checked in by ppalmers, 15 years ago)

implement clock source selection for DICE EVM

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