master
Ismael Gomez 6 years ago
parent 0294923e2b
commit dabfbfb75a

@ -30,25 +30,24 @@
#include "srslte/interfaces/enb_interfaces.h"
#include "srslte/common/log.h"
#include "srslte/common/threads.h"
#include "srslte/common/block_queue.h"
#include "srslte/common/buffer_pool.h"
namespace srsenb {
class prach_worker : thread
{
public:
prach_worker() : initiated(false), prach_nof_det(0), max_prach_offset_us(0), pending_tti(0), processed_tti(0),
prach_worker() : initiated(false), prach_nof_det(0), max_prach_offset_us(0), buffer_pool(8),
running(false), nof_sf(0), sf_cnt(0) {
log_h = NULL;
mac = NULL;
signal_buffer_rx = NULL;
bzero(&prach, sizeof(srslte_prach_t));
bzero(&prach_indices, sizeof(prach_indices));
bzero(&prach_offsets, sizeof(prach_offsets));
bzero(&prach_p2avg, sizeof(prach_p2avg));
bzero(&cell, sizeof(cell));
bzero(&prach_cfg, sizeof(prach_cfg));
bzero(&mutex, sizeof(mutex));
bzero(&cvar, sizeof(cvar));
}
int init(srslte_cell_t *cell, srslte_prach_cfg_t *prach_cfg, mac_interface_phy *mac, srslte::log *log_h, int priority);
@ -57,10 +56,7 @@ public:
void stop();
private:
void run_thread();
int run_tti(uint32_t tti);
uint32_t prach_nof_det;
uint32_t prach_nof_det;
uint32_t prach_indices[165];
float prach_offsets[165];
float prach_p2avg[165];
@ -69,20 +65,32 @@ private:
srslte_prach_cfg_t prach_cfg;
srslte_prach_t prach;
pthread_mutex_t mutex;
pthread_cond_t cvar;
const static int sf_buffer_sz = 128*1024;
class sf_buffer {
public:
sf_buffer() { nof_samples = 0; tti = 0; }
void reset() { nof_samples = 0; tti = 0; }
cf_t samples[sf_buffer_sz];
uint32_t nof_samples;
uint32_t tti;
char debug_name[SRSLTE_BUFFER_POOL_LOG_NAME_LEN];
};
srslte::buffer_pool<sf_buffer> buffer_pool;
srslte::block_queue<sf_buffer*> pending_buffers;
sf_buffer* current_buffer;
cf_t *signal_buffer_rx;
srslte::log* log_h;
mac_interface_phy *mac;
float max_prach_offset_us;
bool initiated;
uint32_t pending_tti;
int processed_tti;
bool running;
uint32_t nof_sf;
uint32_t sf_cnt;
void run_thread();
int run_tti(sf_buffer *b);
};
}
#endif // SRSENB_PRACH_WORKER_H

@ -38,9 +38,6 @@ int prach_worker::init(srslte_cell_t *cell_, srslte_prach_cfg_t *prach_cfg_, mac
max_prach_offset_us = 50;
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cvar, NULL);
if (srslte_prach_init_cfg(&prach, &prach_cfg, cell.nof_prb)) {
fprintf(stderr, "Error initiating PRACH\n");
return -1;
@ -50,34 +47,20 @@ int prach_worker::init(srslte_cell_t *cell_, srslte_prach_cfg_t *prach_cfg_, mac
nof_sf = (uint32_t) ceilf(prach.T_tot*1000);
signal_buffer_rx = (cf_t*) srslte_vec_malloc(sizeof(cf_t)*nof_sf*SRSLTE_SF_LEN_PRB(cell.nof_prb));
if (!signal_buffer_rx) {
perror("malloc");
return -1;
}
start(priority);
initiated = true;
sf_cnt = 0;
pending_tti = 0;
processed_tti = 0;
return 0;
return 0;
}
void prach_worker::stop()
{
srslte_prach_free(&prach);
if (signal_buffer_rx) {
free(signal_buffer_rx);
}
pthread_mutex_lock(&mutex);
processed_tti = 99999;
running = false;
pthread_cond_signal(&cvar);
pthread_mutex_unlock(&mutex);
running = false;
sf_buffer *s = NULL;
pending_buffers.push(s);
wait_thread_finish();
}
@ -90,35 +73,45 @@ int prach_worker::new_tti(uint32_t tti_rx, cf_t* buffer_rx)
{
// Save buffer only if it's a PRACH TTI
if (srslte_prach_tti_opportunity(&prach, tti_rx, -1) || sf_cnt) {
memcpy(&signal_buffer_rx[sf_cnt*SRSLTE_SF_LEN_PRB(cell.nof_prb)], buffer_rx, sizeof(cf_t)*SRSLTE_SF_LEN_PRB(cell.nof_prb));
sf_cnt++;
if (sf_cnt == nof_sf) {
sf_cnt = 0;
if ((int) pending_tti != processed_tti) {
log_h->warning("PRACH thread did not finish processing TTI=%d\n", pending_tti);
if (sf_cnt == 0) {
current_buffer = buffer_pool.allocate();
if (!current_buffer) {
log_h->warning("PRACH skipping tti=%d due to lack of available buffers\n", tti_rx);
return 0;
}
pthread_mutex_lock(&mutex);
if (tti_rx+1 > nof_sf) {
pending_tti = tti_rx+1-nof_sf;
} else {
pending_tti = 10240+(tti_rx+1-nof_sf);
}
if (!current_buffer) {
log_h->error("PRACH: Expected available current_buffer\n");
return -1;
}
if (current_buffer->nof_samples+SRSLTE_SF_LEN_PRB(cell.nof_prb) < sf_buffer_sz) {
memcpy(&current_buffer->samples[sf_cnt*SRSLTE_SF_LEN_PRB(cell.nof_prb)], buffer_rx, sizeof(cf_t)*SRSLTE_SF_LEN_PRB(cell.nof_prb));
current_buffer->nof_samples += SRSLTE_SF_LEN_PRB(cell.nof_prb);
if (sf_cnt == 0) {
current_buffer->tti = tti_rx;
}
pthread_cond_signal(&cvar);
pthread_mutex_unlock(&mutex);
} else {
log_h->error("PRACH: Not enough space in current_buffer\n");
return -1;
}
sf_cnt++;
if (sf_cnt == nof_sf) {
sf_cnt = 0;
pending_buffers.push(current_buffer);
}
}
return 0;
}
int prach_worker::run_tti(uint32_t tti_rx)
int prach_worker::run_tti(sf_buffer *b)
{
if (srslte_prach_tti_opportunity(&prach, tti_rx, -1))
if (srslte_prach_tti_opportunity(&prach, b->tti, -1))
{
// Detect possible PRACHs
if (srslte_prach_detect_offset(&prach,
prach_cfg.freq_offset,
&signal_buffer_rx[prach.N_cp],
&b->samples[prach.N_cp],
nof_sf*SRSLTE_SF_LEN_PRB(cell.nof_prb)-prach.N_cp,
prach_indices,
prach_offsets,
@ -135,7 +128,7 @@ int prach_worker::run_tti(uint32_t tti_rx)
i, prach_nof_det, prach_indices[i], prach_offsets[i]*1e6, prach_p2avg[i], max_prach_offset_us);
if (prach_offsets[i]*1e6 < max_prach_offset_us) {
mac->rach_detected(tti_rx, prach_indices[i], (uint32_t) (prach_offsets[i]*1e6));
mac->rach_detected(b->tti, prach_indices[i], (uint32_t) (prach_offsets[i]*1e6));
}
}
}
@ -147,18 +140,15 @@ void prach_worker::run_thread()
{
running = true;
while(running) {
pthread_mutex_lock(&mutex);
while(processed_tti == (int) pending_tti) {
pthread_cond_wait(&cvar, &mutex);
}
pthread_mutex_unlock(&mutex);
log_h->debug("Processing pending_tti=%d\n", pending_tti);
if (running) {
if (run_tti(pending_tti)) {
running = false;
sf_buffer* b = pending_buffers.wait_pop();
if (running && b) {
int ret = run_tti(b);
b->reset();
buffer_pool.deallocate(b);
if (ret) {
running = false;
}
}
processed_tti = pending_tti;
}
}
}

@ -83,6 +83,7 @@ bool mac::init(phy_interface_mac *phy, rlc_interface_mac *rlc, rrc_interface_mac
void mac::stop()
{
srslte_softbuffer_rx_free(&pch_softbuffer);
srslte_softbuffer_rx_free(&mch_softbuffer);
pdu_process_thread.stop();
stop_thread();

Loading…
Cancel
Save