Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

VrSigProc.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- */
00002 /*
00003  * Copyright 2001 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  */
00022 /*
00023  *  Copyright 1997 Massachusetts Institute of Technology
00024  * 
00025  *  Permission to use, copy, modify, distribute, and sell this software and its
00026  *  documentation for any purpose is hereby granted without fee, provided that
00027  *  the above copyright notice appear in all copies and that both that
00028  *  copyright notice and this permission notice appear in supporting
00029  *  documentation, and that the name of M.I.T. not be used in advertising or
00030  *  publicity pertaining to distribution of the software without specific,
00031  *  written prior permission.  M.I.T. makes no representations about the
00032  *  suitability of this software for any purpose.  It is provided "as is"
00033  *  without express or implied warranty.
00034  * 
00035  */
00036 
00037 #ifndef _VRSIGPROC_H_
00038 #define _VRSIGPROC_H_
00039 
00040 #include <VrTypes.h>
00041 #include <VrPerfGraph.h>
00042 
00043 extern unsigned int cacheSize;
00044 extern float maxLatency;
00045 class VrBuffer;
00046 class VrConnect;
00047 class VrMultiTask;
00048 
00049 struct writerLL {
00050   //everything from current thread's desiredWP to maxValid is valid
00051   VrSampleIndex maxValid;
00052   struct writerLL *next;
00053 };
00054 
00055 struct readerLL {
00056   VrSampleIndex index;
00057   struct readerLL *next;
00058 };
00059 
00061 
00067 class VrSigProc {
00068   friend class VrMultiTask;
00069 
00070 private:
00071   /***********************************************************/
00072   /*** "Internal" methods -- only called from core modules ***/
00073   /***********************************************************/
00074 
00075   int uses_sync; 
00076   double proc_samplingFrequency;
00077 
00079   volatile VrSampleIndex WP; 
00080 
00082   volatile VrSampleIndex markedWP; 
00083 
00085 
00090   unsigned int maxOutSize; 
00091 
00092   /*** Performance monitoring data ***/
00093 #ifdef PERFMON
00094   VrCycleCount *cycles;
00095 #endif
00096   /*** Input Connectors ***/
00097   VrConnect ** inputConn;
00098   unsigned int setupCalled;
00099   unsigned int outputSize; 
00100   unsigned int type_size;
00101   unsigned int itype_size;
00102   unsigned int initializeCalled;
00103 #ifdef THREADS
00104   pthread_key_t myMarkedData; //pointer to VrSampleRange
00105   pthread_key_t inputs_forecasted; //array of VrSampleRange
00106   pthread_key_t myWriterLL; //pointer to writerLL
00107   pthread_key_t myReaderLLs; //array of readerLLs
00108 #else
00109   VrSampleRange myMarkedData;
00110   VrSampleRange *inputs_forecasted;
00111   writerLL *myWriterLL;
00112   readerLL *myReaderLLs; //array of size numberInputs
00113 #endif
00114 
00115   /* Linked list of writing threads */
00116   /*   each writerLL structure indicated where the thread started writing */
00117   volatile writerLL *first, *last;
00118   MUTEX_DECLARE(mutex);
00119   void attach_writer(writerLL *r);
00120   void detach_writer(writerLL *r);
00121 
00127   void init_base();
00128 
00140   virtual void pre_initialize();
00141 
00143   virtual void initialize() {};
00144 
00145   virtual bool isConnectedToSource();
00146 
00147   int minwritespace(VrSampleIndex newWP, unsigned int desired); 
00148 
00149   //These work best in the constructor, but will work
00150   //  in initialize if the SigProc has ONLY ONE output buffer
00151   void initOutputBuffers(int n);
00152   virtual void initOutputBuffer(int n); //create a particular buffer
00153   void initMarkedData();
00154   virtual unsigned int mapSizeUp(int i, unsigned int size);
00155 
00157   virtual bool dataMarked(VrSampleRange r); 
00158 
00159 
00161   virtual int markData(VrSampleRange r);
00162   static const int MARK_ALREADY = 2;      
00163   static const int MARK_READY = 1;        
00164   static const int MARK_READY_NO_MARK = 0;
00165                                           //   but no further data should be marked
00166   static const int MARK_NO_READY = -1;    
00167   static const int MARK_THREAD = -2;      
00168   static const int MARK_continue = -3;    
00169 
00170   virtual int VrSigProc::markDataUpstream (VrSampleRange *inputs,
00171                                            bool *dataMarkedUpstream);
00173   virtual bool compute();
00174 
00175 protected:
00176 
00177   VrBuffer** outBuffer;
00178 
00180   unsigned int maxDSReadSize; 
00181 
00182   unsigned int numberInputs;
00183   unsigned int numberOutputs; 
00184   virtual VrSigProc *getUpstreamModuleN(port p);
00185   double getInputSamplingFrequencyN(port p);
00186 
00188   void setOutputSize(int o) { outputSize=o; }
00189   unsigned int getOutputSize() {return outputSize;}
00190 
00191   void setup_upstream();
00192   int getNumberInputs() {return numberInputs;}
00193 
00198   bool is_synced (VrSampleIndex arg_index) {
00199     return WP >= arg_index;
00200   }
00201   
00203   void sync (VrSampleIndex arg_index);
00204 
00205   VrSampleIndex proc_minRP();
00206 
00207 public:    
00208   VrSigProc(int number_of_outputs, unsigned int arg_itype_size, unsigned int arg_type_size);
00209   virtual ~VrSigProc();
00210 
00212   bool connect_proc(VrSigProc* proc, port n);
00213 
00214   /*******************************************************************/
00215   /*** Methods you should override in processing modules ***/
00216   /*******************************************************************/
00217 
00219 
00220   virtual const char *name() { return "VrSigProc"; }
00221 
00223   //  0=OK results and -1=don't know what I need yet
00224 
00225   virtual int forecast(VrSampleRange output, VrSampleRange inputs[]); 
00226 
00233   virtual float memoryTouched(); 
00234 
00246   virtual int work(VrSampleRange output, void *o[],
00247                    VrSampleRange inputs[], void *i[]) = 0; 
00248 
00249   //what fraction of the input samples (from input n) does this module look
00250   //at? 1.0=all 0.0=none <1.0=some fraction
00251   // >1.0 -- very very rare, means looks at proportionally more
00252   //         data (e.g. always twice the input data) --
00253   //         this isn't taps or any constant extra data
00254 
00255   virtual float averageInputUse(int n) {return 1.0;} 
00256 
00257   virtual int checkOutputSamplingFrequency(float) { return 0;} 
00258 
00260   bool isSink ();
00261   
00262   /**********************************************************/
00263   /*** "External" methods -- call from out-of-band script ***/
00264   /**********************************************************/
00265   virtual int setSamplingFrequency(double sf); 
00266 
00267   //has data already been computed?
00268   virtual bool dataReady(VrSampleRange r); 
00269   virtual void size_setup(unsigned int size);
00270   virtual void setup();
00271   VrSampleIndex getMarkedWP() {return markedWP;}
00272 
00273 #ifdef PERFMON
00274   /*** Performance monitoring procedures ***/
00275   unsigned int num_print_stats;
00276   long long getTotalCycles();
00277   long long getTotalCycles(int m);
00278   long getTotalSamples();
00279   long long getCyclesPerSample();
00280   long long getCyclesPerSample(int m);
00281   void addToGraph(VrPerfGraph *g);
00282   void print_stats();
00283 #endif
00284   unsigned int getMaxOutputSize() {return maxOutSize;}
00285   VrSampleIndex getWP() {return WP;}
00286   double getSamplingFrequency() { return proc_samplingFrequency; }
00287   virtual int callback(int attribute_number, float value) { return 0; }
00288 };
00289 
00290 // "New World Order" connect macro...
00291 // connect a's nth output to b's next input
00292 // Ahhhh, doesn't that feel better.
00293 // #define      NWO_CONNECTN(a, n, b) (b)->connect_proc (a, n)
00294 // #define      NWO_CONNECT(a, b)     NWO_CONNECTN (a, 0, b)
00295 
00296 static inline void
00297 NWO_CONNECTN (VrSigProc *src, int n, VrSigProc *dst)
00298 {
00299   dst->connect_proc (src, n);
00300 }
00301 
00302 static inline void
00303 NWO_CONNECT (VrSigProc *src, VrSigProc *dst)
00304 {
00305   NWO_CONNECTN (src, 0, dst);
00306 }
00307 
00308 // Macro to connect_proc (next) input of a to (1st) output of B.
00309 // (deprecated)
00310 #define CONNECTN(a, b, n, sf, bps) NWO_CONNECTN (b, n, a)
00311 #define CONNECT(a, b, sf, bps)     NWO_CONNECT (b, a)
00312 
00313 #endif

Generated on Tue Mar 15 23:48:04 2005 for GNU Radio by  doxygen 1.4.0