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

wip

parent 454bb157
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#define PPS_UPDATE_PERIOD INT64_C(1000000000) #define PPS_UPDATE_PERIOD INT64_C(1000000000)
#define STAT_INT_LEN "9" #define STAT_INT_LEN "9"
#define N_SAMPLES (32)
#define MIN_PACKET_SIZE 64 #define MIN_PACKET_SIZE 64
#define MAX_CHANNELS 4 #define MAX_CHANNELS 4
#define ETHERNET_HEADER 14 #define ETHERNET_HEADER 14
...@@ -850,87 +851,77 @@ static void trx_ecpri_end(TRXState *s1) ...@@ -850,87 +851,77 @@ static void trx_ecpri_end(TRXState *s1)
free(s); free(s);
} }
static int64_t prev_ts = 0; static int64_t prev_timestamp = 0;
static int64_t prev_count = 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) 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; size_t nc, nk;
float ** _samples = (float **) __samples; float ** _samples = (float **) __samples;
TRXEcpriState *s = s1->opaque; TRXEcpriState *s = s1->opaque;
write_count = count / M;
ts = timestamp / M;
log_debug("TRX_ECPRI_WRITE", "trx_ecpri_write, count = %ld", count); 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", log_exit("TRX_ECPRI_WRITE",
"Gap between timestamps: prev_ts %li ts %li prev_count %li count %li diff_ts %li", "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", //log_exit("TRX_ECPRI_WRITE",
// "Not enough space to write in trxw_rbuf (write count = %d)", write_count); // "Not enough space to write in trxw_rbuf (count = %d)", count);
update_counter(&tx_drop_counter, write_count); update_counter(&tx_drop_counter, count / N_SAMPLES);
return; return;
} }
if(first_trx_write) { count_left = count
sample_group_t * g2 = RBUF_WRITE0(trxw_group_rbuf, sample_group_t); while((nc = rbuf_contiguous_copy(NULL, &trxw_rbuf[0], count_left * sizeof(Complex)))) {
g2->count = ts; for(int i = 0; i < s->tx_n_channel; i++) {
g2->wait = 1; if(__samples)
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)
for(int i = 0; i < s->tx_n_channel; i++) {
memcpy( memcpy(
((uint8_t *) trxw_rbuf[i].buffer) +\ ((uint8_t *) trxw_rbuf[i].buffer) + trxw_rbuf[0].write_index,
trxw_rbuf[0].write_index * trxw_rbuf[0].len * sizeof(Complex),
((uint8_t *) _samples[i]) + nk, ((uint8_t *) _samples[i]) + nk,
len); nc);
} else
trxw_rbuf[0].write_index = (trxw_rbuf[0].write_index + nc) % trxw_rbuf[0].buf_len; memset(
write_count -= nc; ((uint8_t *) trxw_rbuf[i].buffer) + trxw_rbuf[0].write_index,
0,
nc);
}
rbuf_increment_write(&trxw_rbuf, nc);
count_left -= nc / sizeof(Complex);
nk += nc; nk += nc;
} }
update_counter(&write_counter, count / N_SAMPLES);
rbuf_update_write_index(&trxw_group_rbuf);
update_counter(&write_counter, count / M);
} }
static int trx_ecpri_read(TRXState *s1, trx_timestamp_t *ptimestamp, void **__samples, int count, int rx_port_index, TRXReadMetadata *md) 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; float ** _samples = (float **) __samples;
int read_count = (count / M);
int offset = 0; int offset = 0;
TRXEcpriState *s = s1->opaque; 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; sync_complete = 1;
n = read_count; count_left = count;
while((nc = rbuf_contiguous_copy(&trxr_rbuf[0], NULL, n))) { while((nc = rbuf_contiguous_copy(&trxr_rbuf[0], NULL, count_left * sizeof(Complex)))) {
int len = nc * trxr_rbuf[0].len * sizeof(Complex);
for(int i = 0; i < s->rx_n_channel; i++ ) { for(int i = 0; i < s->rx_n_channel; i++ ) {
uint8_t * dst = (uint8_t*) (_samples[i] + offset); memcpy(
uint8_t * src = ((uint8_t *) trxr_rbuf[i].buffer) + trxr_rbuf[0].read_index * trxr_rbuf[0].len * sizeof(Complex); (uint8_t*) (_samples[i] + offset),
memcpy(dst, src, len); ((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; trxr_rbuf[0].read_index = (trxr_rbuf[0].read_index + nc) % trxr_rbuf[0].buf_len;
n -= nc; 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