transceiver: separate radio clock and vector interfaces

Remove radio clock and vector interfaces into their own
files. This clears up and simplifies the radio interface
and, additionaly, prepares for a further split of the I/O
portion for optional resampler use.

Signed-off-by: Thomas Tsou <ttsou@vt.edu>

git-svn-id: http://wush.net/svn/range/software/public/openbts/trunk@2669 19bc5d8c-e614-43d4-8b26-e1612bc8e597
diff --git a/Transceiver52M/Makefile.am b/Transceiver52M/Makefile.am
index 4669b99..5bad45e 100644
--- a/Transceiver52M/Makefile.am
+++ b/Transceiver52M/Makefile.am
@@ -36,13 +36,18 @@
 
 noinst_LTLIBRARIES = libtransceiver.la
 
-libtransceiver_la_SOURCES = \
+COMMON_SOURCES = \
 	radioInterface.cpp \
+	radioVector.cpp \
+	radioClock.cpp \
 	sigProcLib.cpp \
 	Transceiver.cpp \
 	USRPDevice.cpp \
 	DummyLoad.cpp
 
+libtransceiver_la_SOURCES = \
+	$(COMMON_SOURCES)
+
 noinst_PROGRAMS = \
 	USRPping \
 	transceiver \
@@ -51,6 +56,8 @@
 noinst_HEADERS = \
 	Complex.h \
 	radioInterface.h \
+	radioVector.h \
+	radioClock.h \
 	radioDevice.h \
 	sigProcLib.h \
 	Transceiver.h \
diff --git a/Transceiver52M/radioClock.cpp b/Transceiver52M/radioClock.cpp
new file mode 100644
index 0000000..710018a
--- /dev/null
+++ b/Transceiver52M/radioClock.cpp
@@ -0,0 +1,54 @@
+/*
+ * Written by Thomas Tsou <ttsou@vt.edu>
+ * Based on code by Harvind S Samra <hssamra@kestrelsp.com>
+ *
+ * Copyright 2011 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * See the COPYING file in the main directory for details.
+ */
+
+#include "radioClock.h"
+
+void RadioClock::set(const GSM::Time& wTime)
+{
+	mLock.lock();
+	mClock = wTime;
+	updateSignal.signal();
+	mLock.unlock();
+}
+
+void RadioClock::incTN()
+{
+	mLock.lock();
+	mClock.incTN();
+	updateSignal.signal();
+	mLock.unlock();
+}
+
+GSM::Time RadioClock::get()
+{
+	mLock.lock();
+	GSM::Time retVal = mClock;
+	mLock.unlock();
+
+	return retVal;
+}
+
+void RadioClock::wait()
+{
+	mLock.lock();
+	updateSignal.wait(mLock,1);
+	mLock.unlock();
+}
diff --git a/Transceiver52M/radioClock.h b/Transceiver52M/radioClock.h
new file mode 100644
index 0000000..9c35c44
--- /dev/null
+++ b/Transceiver52M/radioClock.h
@@ -0,0 +1,40 @@
+/*
+ * Written by Thomas Tsou <ttsou@vt.edu>
+ * Based on code by Harvind S Samra <hssamra@kestrelsp.com>
+ *
+ * Copyright 2011 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * See the COPYING file in the main directory for details.
+ */
+
+#ifndef RADIOCLOCK_H
+#define RADIOCLOCK_H
+
+#include "GSMCommon.h"
+
+class RadioClock {
+public:
+	void set(const GSM::Time& wTime);
+	void incTN();
+	GSM::Time get();
+	void wait();
+
+private:
+	GSM::Time mClock;
+	Mutex mLock;
+	Signal updateSignal;
+};
+
+#endif /* RADIOCLOCK_H */
diff --git a/Transceiver52M/radioInterface.cpp b/Transceiver52M/radioInterface.cpp
index 2b56f9a..4e261f7 100644
--- a/Transceiver52M/radioInterface.cpp
+++ b/Transceiver52M/radioInterface.cpp
@@ -25,46 +25,6 @@
 #include "radioInterface.h"
 #include <Logger.h>
 
-
-GSM::Time VectorQueue::nextTime() const
-{
-  GSM::Time retVal;
-  ScopedLock lock(mLock);
-  while (mQ.size()==0) mWriteSignal.wait(mLock);
-  return mQ.top()->time();
-}
-
-radioVector* VectorQueue::getStaleBurst(const GSM::Time& targTime)
-{
-  ScopedLock lock(mLock);
-  if ((mQ.size()==0)) {
-    return NULL;
-  }
-  if (mQ.top()->time() < targTime) {
-    radioVector* retVal = mQ.top();
-    mQ.pop();
-    return retVal;
-  }
-  return NULL;
-}
-
-
-radioVector* VectorQueue::getCurrentBurst(const GSM::Time& targTime)
-{
-  ScopedLock lock(mLock);
-  if ((mQ.size()==0)) {
-    return NULL;
-  }
-  if (mQ.top()->time() == targTime) {
-    radioVector* retVal = mQ.top();
-    mQ.pop();
-    return retVal;
-  }
-  return NULL;
-}
-
-
-
 RadioInterface::RadioInterface(RadioDevice *wRadio,
                                int wReceiveOffset,
 			       int wRadioOversampling,
@@ -167,10 +127,6 @@
 					  INCHUNK*samplesPerSymbol,
 					  &underrun,
 					  writeTimestamp); 
-<<<<<<< HEAD
-  //LOG(DEBUG) << "writeTimestamp: " << writeTimestamp << ", samplesWritten: " << samplesWritten;
-=======
->>>>>>> 957b9c5... transceiver: remove extraneous comments
    
   writeTimestamp += (TIMESTAMP) samplesWritten;
 
diff --git a/Transceiver52M/radioInterface.h b/Transceiver52M/radioInterface.h
index 71273b3..8fb9f27 100644
--- a/Transceiver52M/radioInterface.h
+++ b/Transceiver52M/radioInterface.h
@@ -18,107 +18,14 @@
 #include "GSMCommon.h"
 #include "LinkedLists.h"
 #include "radioDevice.h"
+#include "radioVector.h"
+#include "radioClock.h"
 
 /** samples per GSM symbol */
 #define SAMPSPERSYM 1 
 #define INCHUNK    (625)
 #define OUTCHUNK   (625)
 
-/** class used to organize GSM bursts by GSM timestamps */
-class radioVector : public signalVector {
-
-private:
-
-  GSM::Time mTime;   ///< the burst's GSM timestamp 
-
-public:
-  /** constructor */
-  radioVector(const signalVector& wVector,
-              GSM::Time& wTime): signalVector(wVector),mTime(wTime) {};
-
-  /** timestamp read and write operators */
-  GSM::Time time() const { return mTime;}
-  void time(const GSM::Time& wTime) { mTime = wTime;}
-
-  /** comparison operator, used for sorting */
-  bool operator>(const radioVector& other) const {return mTime > other.mTime;}
-
-};
-
-/** a priority queue of radioVectors, i.e. GSM bursts, sorted so that earliest element is at top */
-class VectorQueue : public InterthreadPriorityQueue<radioVector> {
-
-public:
-
-  /** the top element of the queue */
-  GSM::Time nextTime() const;
-
-  /**
-    Get stale burst, if any.
-    @param targTime The target time.
-    @return Pointer to burst older than target time, removed from queue, or NULL.
-  */
-  radioVector* getStaleBurst(const GSM::Time& targTime);
-
-  /**
-    Get current burst, if any.
-    @param targTime The target time.
-    @return Pointer to burst at the target time, removed from queue, or NULL.
-  */
-  radioVector* getCurrentBurst(const GSM::Time& targTime);
-
-
-};
-
-/** a FIFO of radioVectors */
-class VectorFIFO {
-
-private:
-
-      PointerFIFO mQ;
-      Mutex      mLock;
-
-public:
-
-      unsigned size() {return mQ.size();}
-
-      void put(radioVector *ptr) {ScopedLock lock(mLock); mQ.put((void*) ptr);}
-
-      radioVector *get() { ScopedLock lock(mLock); return (radioVector*) mQ.get();}
-
-};
-
-
-/** the basestation clock class */
-class RadioClock {
-
-private:
-
-  GSM::Time mClock;
-  Mutex mLock;
-  Signal updateSignal;
-
-public:
-
-  /** Set clock */
-  //void set(const GSM::Time& wTime) { ScopedLock lock(mLock); mClock = wTime; updateSignal.signal();}
-  void set(const GSM::Time& wTime) { ScopedLock lock(mLock); mClock = wTime; updateSignal.broadcast();;}
-
-  /** Increment clock */
-  //void incTN() { ScopedLock lock(mLock); mClock.incTN(); updateSignal.signal();}
-  void incTN() { ScopedLock lock(mLock); mClock.incTN(); updateSignal.broadcast();}
-
-  /** Get clock value */
-  GSM::Time get() { ScopedLock lock(mLock); return mClock; }
-
-  /** Wait until clock has changed */
-  //void wait() {ScopedLock lock(mLock); updateSignal.wait(mLock,1);}
-  // FIXME -- If we take away the timeout, a lot of threads don't start.  Why?
-  void wait() {ScopedLock lock(mLock); updateSignal.wait(mLock);}
-
-};
-
-
 /** class to interface the transceiver with the USRP */
 class RadioInterface {
 
diff --git a/Transceiver52M/radioVector.cpp b/Transceiver52M/radioVector.cpp
new file mode 100644
index 0000000..fd4e5a7
--- /dev/null
+++ b/Transceiver52M/radioVector.cpp
@@ -0,0 +1,109 @@
+/*
+ * Written by Thomas Tsou <ttsou@vt.edu>
+ * Based on code by Harvind S Samra <hssamra@kestrelsp.com>
+ *
+ * Copyright 2011 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * See the COPYING file in the main directory for details.
+ */
+
+#include "radioVector.h"
+
+radioVector::radioVector(const signalVector& wVector, GSM::Time& wTime)
+	: signalVector(wVector), mTime(wTime)
+{
+}
+
+GSM::Time radioVector::time() const
+{
+	return mTime;
+}
+
+void radioVector::setTime(const GSM::Time& wTime)
+{
+	mTime = wTime;
+}
+
+bool radioVector::operator>(const radioVector& other) const
+{
+	return mTime > other.mTime;
+}
+
+unsigned VectorFIFO::size()
+{
+	return mQ.size();
+}
+
+void VectorFIFO::put(radioVector *ptr)
+{
+	mQ.put((void*) ptr);
+}
+
+radioVector *VectorFIFO::get()
+{
+	return (radioVector*) mQ.get();
+}
+
+GSM::Time VectorQueue::nextTime() const
+{
+	GSM::Time retVal;
+	mLock.lock();
+
+	while (mQ.size()==0)
+		mWriteSignal.wait(mLock);
+
+	retVal = mQ.top()->time();
+	mLock.unlock();
+
+	return retVal;
+}
+
+radioVector* VectorQueue::getStaleBurst(const GSM::Time& targTime)
+{
+	mLock.lock();
+	if ((mQ.size()==0)) {
+		mLock.unlock();
+		return NULL;
+	}
+
+	if (mQ.top()->time() < targTime) {
+		radioVector* retVal = mQ.top();
+		mQ.pop();
+		mLock.unlock();
+		return retVal;
+	}
+	mLock.unlock();
+
+	return NULL;
+}
+
+radioVector* VectorQueue::getCurrentBurst(const GSM::Time& targTime)
+{
+	mLock.lock();
+	if ((mQ.size()==0)) {
+		mLock.unlock();
+		return NULL;
+	}
+
+	if (mQ.top()->time() == targTime) {
+		radioVector* retVal = mQ.top();
+		mQ.pop();
+		mLock.unlock();
+		return retVal;
+	}
+	mLock.unlock();
+
+	return NULL;
+}
diff --git a/Transceiver52M/radioVector.h b/Transceiver52M/radioVector.h
new file mode 100644
index 0000000..37970ae
--- /dev/null
+++ b/Transceiver52M/radioVector.h
@@ -0,0 +1,56 @@
+/*
+ * Written by Thomas Tsou <ttsou@vt.edu>
+ * Based on code by Harvind S Samra <hssamra@kestrelsp.com>
+ *
+ * Copyright 2011 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * See the COPYING file in the main directory for details.
+ */
+
+#ifndef RADIOVECTOR_H
+#define RADIOVECTOR_H
+
+#include "sigProcLib.h"
+#include "GSMCommon.h"
+
+class radioVector : public signalVector {
+public:
+	radioVector(const signalVector& wVector, GSM::Time& wTime);
+	GSM::Time time() const;
+	void setTime(const GSM::Time& wTime);
+	bool operator>(const radioVector& other) const;
+
+private:
+	GSM::Time mTime;
+};
+
+class VectorFIFO {
+public:
+	unsigned size();
+	void put(radioVector *ptr);
+	radioVector *get();
+
+private:
+	PointerFIFO mQ;
+};
+
+class VectorQueue : public InterthreadPriorityQueue<radioVector> {
+public:
+	GSM::Time nextTime() const;
+	radioVector* getStaleBurst(const GSM::Time& targTime);
+	radioVector* getCurrentBurst(const GSM::Time& targTime);
+};
+
+#endif /* RADIOVECTOR_H */
diff --git a/Transceiver52M/sigProcLib.h b/Transceiver52M/sigProcLib.h
index c20b1ec..3aaa62b 100644
--- a/Transceiver52M/sigProcLib.h
+++ b/Transceiver52M/sigProcLib.h
@@ -12,7 +12,8 @@
 
 */
 
-
+#ifndef SIGPROCLIB_H
+#define SIGPROCLIB_H
 
 #include "Vector.h"
 #include "Complex.h"
@@ -384,3 +385,5 @@
 		       int samplesPerSymbol,
 		       signalVector &w, 
 		       signalVector &b);
+
+#endif /* SIGPROCLIB_H */