mirror of https://github.com/pvnis/srsRAN_4G.git
Added condvar synchronization to ue itf class. SIB1 test working.
parent
bb08b2f04b
commit
736517babb
@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* \section COPYRIGHT
|
||||||
|
*
|
||||||
|
* Copyright 2013-2014 The srsLTE Developers. See the
|
||||||
|
* COPYRIGHT file at the top-level directory of this distribution.
|
||||||
|
*
|
||||||
|
* \section LICENSE
|
||||||
|
*
|
||||||
|
* This file is part of the srsLTE library.
|
||||||
|
*
|
||||||
|
* srsLTE is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* srsLTE 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* A copy of the GNU Lesser General Public License can be found in
|
||||||
|
* the LICENSE file in the top-level directory of this distribution
|
||||||
|
* and at http://www.gnu.org/licenses/.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "srslte/srslte.h"
|
||||||
|
|
||||||
|
#ifndef TTISYNC_H
|
||||||
|
#define TTISYNC_H
|
||||||
|
|
||||||
|
|
||||||
|
namespace srslte {
|
||||||
|
namespace ue {
|
||||||
|
|
||||||
|
/* Interface used for PHY-MAC synchronization (producer-consumer model).
|
||||||
|
* The consumer waits while its counter is lower than the producer counter.
|
||||||
|
* The PHY is the consumer. The MAC is the producer.
|
||||||
|
*/
|
||||||
|
class SRSLTE_API tti_sync
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
tti_sync(uint32_t modulus_)
|
||||||
|
{
|
||||||
|
modulus = modulus_;
|
||||||
|
init_counters(0);
|
||||||
|
}
|
||||||
|
virtual void increase() = 0;
|
||||||
|
virtual uint32_t wait() = 0;
|
||||||
|
virtual void set_producer_cntr(uint32_t) = 0;
|
||||||
|
uint32_t get_producer_cntr() { return producer_cntr; }
|
||||||
|
uint32_t get_consumer_cntr() { return consumer_cntr; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void increase_producer() { producer_cntr = (producer_cntr + 1)%modulus; }
|
||||||
|
void increase_consumer() { consumer_cntr = (consumer_cntr + 1)%modulus; }
|
||||||
|
bool wait_condition() { return producer_cntr == consumer_cntr; }
|
||||||
|
void init_counters(uint32_t val)
|
||||||
|
{
|
||||||
|
consumer_cntr = val;
|
||||||
|
producer_cntr = val;
|
||||||
|
}
|
||||||
|
uint32_t modulus;
|
||||||
|
uint32_t producer_cntr;
|
||||||
|
uint32_t consumer_cntr;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* \section COPYRIGHT
|
||||||
|
*
|
||||||
|
* Copyright 2013-2014 The srsLTE Developers. See the
|
||||||
|
* COPYRIGHT file at the top-level directory of this distribution.
|
||||||
|
*
|
||||||
|
* \section LICENSE
|
||||||
|
*
|
||||||
|
* This file is part of the srsLTE library.
|
||||||
|
*
|
||||||
|
* srsLTE is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* srsLTE 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* A copy of the GNU Lesser General Public License can be found in
|
||||||
|
* the LICENSE file in the top-level directory of this distribution
|
||||||
|
* and at http://www.gnu.org/licenses/.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include "srslte/ue_itf/tti_sync.h"
|
||||||
|
#include "srslte/srslte.h"
|
||||||
|
|
||||||
|
#ifndef TTISYNC_CV_H
|
||||||
|
#define TTISYNC_CV_H
|
||||||
|
|
||||||
|
|
||||||
|
namespace srslte {
|
||||||
|
namespace ue {
|
||||||
|
|
||||||
|
/* Implements tti_sync interface with condition variables.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class SRSLTE_API tti_sync_cv : public tti_sync
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
tti_sync_cv(uint32_t modulus);
|
||||||
|
~tti_sync_cv();
|
||||||
|
void increase();
|
||||||
|
uint32_t wait();
|
||||||
|
void set_producer_cntr(uint32_t producer_cntr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
pthread_cond_t cond;
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* \section COPYRIGHT
|
||||||
|
*
|
||||||
|
* Copyright 2013-2014 The srsLTE Developers. See the
|
||||||
|
* COPYRIGHT file at the top-level directory of this distribution.
|
||||||
|
*
|
||||||
|
* \section LICENSE
|
||||||
|
*
|
||||||
|
* This file is part of the srsLTE library.
|
||||||
|
*
|
||||||
|
* srsLTE is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* srsLTE 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* A copy of the GNU Lesser General Public License can be found in
|
||||||
|
* the LICENSE file in the top-level directory of this distribution
|
||||||
|
* and at http://www.gnu.org/licenses/.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include "srslte/ue_itf/tti_sync_cv.h"
|
||||||
|
|
||||||
|
namespace srslte {
|
||||||
|
namespace ue {
|
||||||
|
|
||||||
|
tti_sync_cv::tti_sync_cv(uint32_t modulus): tti_sync(modulus)
|
||||||
|
{
|
||||||
|
pthread_mutex_init(&mutex, NULL);
|
||||||
|
pthread_cond_init(&cond, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
tti_sync_cv::~tti_sync_cv()
|
||||||
|
{
|
||||||
|
pthread_cond_destroy(&cond);
|
||||||
|
pthread_mutex_destroy(&mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t tti_sync_cv::wait()
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&mutex);
|
||||||
|
while(wait_condition()) {
|
||||||
|
pthread_cond_wait(&cond, &mutex);
|
||||||
|
}
|
||||||
|
uint32_t x = consumer_cntr;
|
||||||
|
increase_consumer();
|
||||||
|
pthread_mutex_unlock(&mutex);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tti_sync_cv::set_producer_cntr(uint32_t producer_cntr)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&mutex);
|
||||||
|
init_counters(producer_cntr);
|
||||||
|
pthread_cond_signal(&cond);
|
||||||
|
pthread_mutex_unlock(&mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tti_sync_cv::increase()
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&mutex);
|
||||||
|
increase_producer();
|
||||||
|
pthread_cond_signal(&cond);
|
||||||
|
pthread_mutex_unlock(&mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue