aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Transceiver52M/DriveLoop.cpp27
-rw-r--r--Transceiver52M/DriveLoop.h9
-rw-r--r--Transceiver52M/radioInterface.cpp20
-rw-r--r--Transceiver52M/radioInterface.h4
4 files changed, 54 insertions, 6 deletions
diff --git a/Transceiver52M/DriveLoop.cpp b/Transceiver52M/DriveLoop.cpp
index 51ce750..7521a18 100644
--- a/Transceiver52M/DriveLoop.cpp
+++ b/Transceiver52M/DriveLoop.cpp
@@ -33,6 +33,7 @@ DriveLoop::DriveLoop(int wBasePort, const char *TRXAddress,
int wChanM, int wC0, int wSamplesPerSymbol,
GSM::Time wTransmitLatency)
: Thread("DriveLoop")
+, mUseCount(0)
, mClockSocket(wBasePort, TRXAddress, wBasePort + 100)
, mC0(wC0)
{
@@ -85,6 +86,32 @@ DriveLoop::~DriveLoop()
sigProcLibDestroy();
}
+bool DriveLoop::start()
+{
+ // Use count must not be negative
+ assert(mUseCount>=0);
+
+ mUseCount++;
+ if (mUseCount>1)
+ return false;
+
+ startThread();
+ return true;
+}
+
+bool DriveLoop::stop()
+{
+ // Use count must not be negative or zero
+ assert(mUseCount>0);
+
+ mUseCount--;
+ if (mUseCount>0)
+ return false;
+
+ stopThread();
+ return true;
+}
+
void DriveLoop::pushRadioVector(GSM::Time &nowTime)
{
int i;
diff --git a/Transceiver52M/DriveLoop.h b/Transceiver52M/DriveLoop.h
index f396abd..eeabe03 100644
--- a/Transceiver52M/DriveLoop.h
+++ b/Transceiver52M/DriveLoop.h
@@ -45,10 +45,12 @@
//#define TRANSMIT_LOGGING 1
/** The Transceiver class, responsible for physical layer of basestation */
-class DriveLoop : public Thread {
+class DriveLoop : private Thread {
private:
+ int mUseCount; ///< Use counter
+
GSM::Time mTransmitLatency; ///< latency between basestation clock and transmit deadline clock
GSM::Time mLatencyUpdateTime; ///< last time latency was updated
GSM::Time mLastClockUpdateTime; ///< last time clock update was sent up to core
@@ -110,6 +112,11 @@ public:
/** Destructor */
~DriveLoop();
+ /** Increase usage counter and start the thread if not started yet */
+ bool start();
+ /** Decrease usage counter and stop the thread if no users left */
+ bool stop();
+
VectorQueue *priorityQueue(int m) { return &mTransmitPriorityQueue[m]; }
/** Codes for burst types of received bursts*/
diff --git a/Transceiver52M/radioInterface.cpp b/Transceiver52M/radioInterface.cpp
index 6694066..6ae6ef7 100644
--- a/Transceiver52M/radioInterface.cpp
+++ b/Transceiver52M/radioInterface.cpp
@@ -55,6 +55,7 @@ RadioInterface::RadioInterface(RadioDevice *wRadio,
int wReceiveOffset,
GSM::Time wStartTime)
: mChanM(wChanM), underrun(false), sendCursor(0), rcvCursor(0), mOn(false),
+ mUseCount(0),
mRadio(wRadio), receiveOffset(wReceiveOffset), samplesPerSymbol(wSPS),
powerScaling(1.0), loadTest(false)
{
@@ -147,9 +148,13 @@ bool RadioInterface::tuneRx(double freq, int chan)
bool RadioInterface::start()
{
- int i;
+ // Use count must not be negative
+ assert(mUseCount>=0);
+ // Being on while mUseCount is 0 is a wrong condition
+ assert(!(mOn && mUseCount==0));
- if (mOn)
+ mUseCount++;
+ if (mOn || mUseCount>1)
return false;
mOn = true;
@@ -160,7 +165,7 @@ bool RadioInterface::start()
#endif
writeTimestamp = mRadio->initialWriteTimestamp();
readTimestamp = mRadio->initialReadTimestamp();
- for (i = 0; i < mChanM; i++) {
+ for (int i = 0; i < mChanM; i++) {
sendBuffer[i] = new float[8*2*INCHUNK];
rcvBuffer[i] = new float[8*2*OUTCHUNK];
}
@@ -178,11 +183,18 @@ bool RadioInterface::start()
bool RadioInterface::stop()
{
- if (!mOn)
+ // Use count must not be negative or zero
+ assert(mUseCount>0);
+ // Must be on while stopping
+ assert(mOn);
+
+ mUseCount--;
+ if (mUseCount>0)
return false;
mOn = false;
mRadio->stop();
+ return true;
}
#ifdef USRP1
diff --git a/Transceiver52M/radioInterface.h b/Transceiver52M/radioInterface.h
index 83413cf..c2c4255 100644
--- a/Transceiver52M/radioInterface.h
+++ b/Transceiver52M/radioInterface.h
@@ -59,6 +59,7 @@ protected:
int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots
bool mOn; ///< indicates radio is on
+ int mUseCount; ///< Use counter
double powerScaling;
@@ -90,8 +91,9 @@ private:
public:
- /** start the interface */
+ /** Increase usage counter and start the interface if not started yet */
bool start();
+ /** Decrease usage counter and stop the interface if no users left */
bool stop();
bool started() { return mOn; };