Commit f4dcc629 authored by Joanne Hugé's avatar Joanne Hugé

wip

parent 454bb157
......@@ -42,6 +42,7 @@
#define PPS_UPDATE_PERIOD INT64_C(1000000000)
#define STAT_INT_LEN "9"
#define N_SAMPLES (32)
#define MIN_PACKET_SIZE 64
#define MAX_CHANNELS 4
#define ETHERNET_HEADER 14
......@@ -850,87 +851,77 @@ static void trx_ecpri_end(TRXState *s1)
free(s);
}
static int64_t prev_ts = 0;
static int64_t prev_timestamp = 0;
static int64_t prev_count = 0;
#define M 32
/* count: how much IQ samples to write (multiple of 32)
timestamp: should be equal to the amount of written IQ samples
__samples: can be null if zeroes are to be written
*/
static void trx_ecpri_write(TRXState *s1, trx_timestamp_t timestamp, const void **__samples, int count, int tx_port_index, TRXWriteMetadata *md)
{
int write_count; int64_t ts; sample_group_t * g;
int64_t count_left, ts; sample_group_t * g;
size_t nc, nk;
float ** _samples = (float **) __samples;
TRXEcpriState *s = s1->opaque;
write_count = count / M;
ts = timestamp / M;
log_debug("TRX_ECPRI_WRITE", "trx_ecpri_write, count = %ld", count);
if(prev_count && ((ts - prev_ts) != prev_count)) {
if(prev_count && ((timestamp - prev_timestamp) != prev_count)) {
log_exit("TRX_ECPRI_WRITE",
"Gap between timestamps: prev_ts %li ts %li prev_count %li count %li diff_ts %li",
prev_ts, ts, prev_count, count, (ts - prev_ts));
prev_timestamp, timestamp, prev_count, count, (timestamp - prev_timestamp));
}
prev_ts = ts; prev_count = write_count;
prev_timestamp = timestamp; prev_count = count;
if(write_count > rbuf_write_amount(&trxw_rbuf[0])) {
if(count > (rbuf_write_amount(&trxw_rbuf[0]) / sizeof(Complex)) ) {
//log_exit("TRX_ECPRI_WRITE",
// "Not enough space to write in trxw_rbuf (write count = %d)", write_count);
update_counter(&tx_drop_counter, write_count);
// "Not enough space to write in trxw_rbuf (count = %d)", count);
update_counter(&tx_drop_counter, count / N_SAMPLES);
return;
}
if(first_trx_write) {
sample_group_t * g2 = RBUF_WRITE0(trxw_group_rbuf, sample_group_t);
g2->count = ts;
g2->wait = 1;
g2->zeroes = 1;
rbuf_update_write_index(&trxw_group_rbuf);
}
g = RBUF_WRITE0(trxw_group_rbuf, sample_group_t);
g->zeroes = __samples ? 0 : 1;
g->wait = 0;
g->count = write_count;
while((nc = rbuf_contiguous_copy(NULL, &trxw_rbuf[0], write_count))) {
size_t len = nc * trxr_rbuf[0].len * sizeof(Complex);
if(__samples)
count_left = count
while((nc = rbuf_contiguous_copy(NULL, &trxw_rbuf[0], count_left * sizeof(Complex)))) {
for(int i = 0; i < s->tx_n_channel; i++) {
if(__samples)
memcpy(
((uint8_t *) trxw_rbuf[i].buffer) +\
trxw_rbuf[0].write_index * trxw_rbuf[0].len * sizeof(Complex),
((uint8_t *) trxw_rbuf[i].buffer) + trxw_rbuf[0].write_index,
((uint8_t *) _samples[i]) + nk,
len);
nc);
else
memset(
((uint8_t *) trxw_rbuf[i].buffer) + trxw_rbuf[0].write_index,
0,
nc);
}
trxw_rbuf[0].write_index = (trxw_rbuf[0].write_index + nc) % trxw_rbuf[0].buf_len;
write_count -= nc;
rbuf_increment_write(&trxw_rbuf, nc);
count_left -= nc / sizeof(Complex);
nk += nc;
}
rbuf_update_write_index(&trxw_group_rbuf);
update_counter(&write_counter, count / M);
update_counter(&write_counter, count / N_SAMPLES);
}
static int trx_ecpri_read(TRXState *s1, trx_timestamp_t *ptimestamp, void **__samples, int count, int rx_port_index, TRXReadMetadata *md)
{
int nc; int n;
int64_t nc; int64_t n, count_left;
float ** _samples = (float **) __samples;
int read_count = (count / M);
int offset = 0;
TRXEcpriState *s = s1->opaque;
log_debug("TRX_ECPRI_READ", "count = %ld (%li)", read_count, read_counter.counter);
log_debug("TRX_ECPRI_READ", "count = %ld (%li)", count, read_counter.counter);
while(rbuf_read_amount(&trxr_rbuf[0]) < read_count);
while((rbuf_read_amount(&trxr_rbuf[0]) / sizeof(Complex)) < count);
sync_complete = 1;
n = read_count;
while((nc = rbuf_contiguous_copy(&trxr_rbuf[0], NULL, n))) {
int len = nc * trxr_rbuf[0].len * sizeof(Complex);
count_left = count;
while((nc = rbuf_contiguous_copy(&trxr_rbuf[0], NULL, count_left * sizeof(Complex)))) {
for(int i = 0; i < s->rx_n_channel; i++ ) {
uint8_t * dst = (uint8_t*) (_samples[i] + offset);
uint8_t * src = ((uint8_t *) trxr_rbuf[i].buffer) + trxr_rbuf[0].read_index * trxr_rbuf[0].len * sizeof(Complex);
memcpy(dst, src, len);
memcpy(
(uint8_t*) (_samples[i] + offset),
((uint8_t *) trxr_rbuf[i].buffer) + trxr_rbuf[0].read_index * trxr_rbuf[0].len * sizeof(Complex);
, len);
}
trxr_rbuf[0].read_index = (trxr_rbuf[0].read_index + nc) % trxr_rbuf[0].buf_len;
n -= nc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment