Commit c6a662d4 authored by Luhan Wang's avatar Luhan Wang

add trx data

parent ab5d537f
...@@ -387,6 +387,9 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { ...@@ -387,6 +387,9 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
printf("[oxgrf] openair0_cfg->sample_rate == '%f'\n", openair0_cfg->sample_rate); printf("[oxgrf] openair0_cfg->sample_rate == '%f'\n", openair0_cfg->sample_rate);
oxgrf->sample_rate = (unsigned int)openair0_cfg->sample_rate; oxgrf->sample_rate = (unsigned int)openair0_cfg->sample_rate;
oxgrf->sample_rate = 30720000; oxgrf->sample_rate = 30720000;
// set_rx_gain_offset(openair0_cfg, 0);
// if(oxgrf->rx_num_channels > 1)
// set_rx_gain_offset(openair0_cfg, 1);
// return 0; // return 0;
// init required params // init required params
switch ((int)openair0_cfg->sample_rate) { switch ((int)openair0_cfg->sample_rate) {
......
...@@ -6,20 +6,27 @@ ...@@ -6,20 +6,27 @@
#include "system.h" #include "system.h"
#include <semaphore.h> #include <semaphore.h>
#include <pthread.h> #include <pthread.h>
#include <math.h>
#include <time.h> /** For SLEEP **/
#include <getopt.h>
#include <stdio.h>
#define NB_ANTENNAS_RX 4 #define NB_ANTENNAS_RX 1
#define NB_ANTENNAS_TX 1 #define NB_ANTENNAS_TX 1
#define SAMPLE_RATE (122880000) #define SAMPLE_RATE (122880000)
#define FRAME_SAMPLE_NUM 1228800
//#define TX_RX_ONE_THREAD //#define TX_RX_ONE_THREAD
int txdata_size=61440*4; #define SLOTS_NUM 10
int rxdata_size=61440*4; int txdata_size=61440*SLOTS_NUM;
int rxdata_size=61440*SLOTS_NUM;
int absolute_slot=0; int absolute_slot=0;
int nb_slot_frame=2; int nb_slot_frame=2;
int samples_per_subframe=SAMPLE_RATE/1000; int samples_per_subframe=SAMPLE_RATE/1000;
#define TXSEQLEN 256
int32_t gTxSeq[61440]={0};
//samples_per_subframe 30720, samples_per_slot_wCP 14336. //samples_per_subframe 30720, samples_per_slot_wCP 14336.
//txdata_size 57344, txdataF_size 57344, rxdata_size 2465792. //txdata_size 57344, txdataF_size 57344, rxdata_size 2465792.
...@@ -48,6 +55,8 @@ struct timespec nr_get_timespec_diff( ...@@ -48,6 +55,8 @@ struct timespec nr_get_timespec_diff(
openair0_timestamp rx_timestamp, writeTimestamp; openair0_timestamp rx_timestamp, writeTimestamp;
int32_t * rxp[NB_ANTENNAS_RX]; int32_t * rxp[NB_ANTENNAS_RX];
int32_t * txp[NB_ANTENNAS_TX]; int32_t * txp[NB_ANTENNAS_TX];
int32_t * rxp_temp[NB_ANTENNAS_RX];
int32_t * txp_temp[NB_ANTENNAS_RX];
int readBlockSize, writeBlockSize; int readBlockSize, writeBlockSize;
int tx_cnt = 0; int tx_cnt = 0;
int rx_cnt = 0; int rx_cnt = 0;
...@@ -60,6 +69,9 @@ static void *tx_thread(void *param) ...@@ -60,6 +69,9 @@ static void *tx_thread(void *param)
double clock_gettime_cur; double clock_gettime_cur;
struct timespec time_start; struct timespec time_start;
struct timespec time_stop; struct timespec time_stop;
int slot_adv = 2;
int mimdelay = 4096*1+2048;
while (1) { while (1) {
...@@ -67,16 +79,29 @@ static void *tx_thread(void *param) ...@@ -67,16 +79,29 @@ static void *tx_thread(void *param)
//printf("00000000 tx cnt %d rx cnt %d\n", tx_cnt, rx_cnt); //printf("00000000 tx cnt %d rx cnt %d\n", tx_cnt, rx_cnt);
// use previous timing_advance value to compute writeTimestamp // use previous timing_advance value to compute writeTimestamp
//writeTimestamp = timestamp+samples_per_subframe/20*5;// sent after 5 slot. //writeTimestamp = timestamp+samples_per_subframe/20*5;// sent after 5 slot.
writeTimestamp = rx_timestamp+samples_per_subframe/4;// sent after 5 slot. writeTimestamp = rx_timestamp+61440+mimdelay;// sent after 5 slot.
// but use current UE->timing_advance value to compute writeBlockSize // but use current UE->timing_advance value to compute writeBlockSize
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, VCD_FUNCTION_IN ); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, VCD_FUNCTION_IN );
clock_gettime(CLOCK_REALTIME,&time_start); clock_gettime(CLOCK_REALTIME,&time_start);
#if 1 #if 1
if ((tx_cnt+slot_adv) % SLOTS_NUM == 5)
{
for (int i=0; i<NB_ANTENNAS_TX; i++) {
memcpy(txp[i] , gTxSeq, TXSEQLEN*4);
}
}
for (int i=0; i<NB_ANTENNAS_RX; i++) {
txp_temp[i] =(int32_t *)txp[i] + ((tx_cnt+slot_adv) % SLOTS_NUM)* 61440;
}
rfdevice->trx_write_func(rfdevice, rfdevice->trx_write_func(rfdevice,
writeTimestamp, writeTimestamp,
(void **)txp, (void **)txp_temp,
writeBlockSize, writeBlockSize,
1, 1,
1); 1);
...@@ -87,11 +112,25 @@ static void *tx_thread(void *param) ...@@ -87,11 +112,25 @@ static void *tx_thread(void *param)
//printf("11111111 tx cnt %d rx cnt %d\n", tx_cnt, rx_cnt); //printf("11111111 tx cnt %d rx cnt %d\n", tx_cnt, rx_cnt);
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, VCD_FUNCTION_OUT ); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, VCD_FUNCTION_OUT );
}
return NULL;
}
int genSineWave(double freq, double sampleRate, int amp, int len, void *buf)
{
double dF = 2 * 3.1415926535898 * (freq) / (sampleRate);
int i;
int16_t *p16 = buf;
for (i = 0; i < len; i++)
{
p16[i * 2] = cos(dF * i) * amp;
p16[i * 2 + 1] = sin(dF * i) * amp;
} }
return NULL; return 0;
} }
...@@ -112,7 +151,7 @@ int main( int argc, char **argv ) { ...@@ -112,7 +151,7 @@ int main( int argc, char **argv ) {
sched_setscheduler(getpid(), SCHED_RR, &rr_param); sched_setscheduler(getpid(), SCHED_RR, &rr_param);
cpu_set_t mask; cpu_set_t mask;
CPU_ZERO(&mask); CPU_ZERO(&mask);
CPU_SET(20, &mask); CPU_SET(3, &mask);
int rc = sched_setaffinity(getpid(), sizeof(mask), &mask); int rc = sched_setaffinity(getpid(), sizeof(mask), &mask);
assert(rc >= 0); assert(rc >= 0);
...@@ -133,6 +172,8 @@ int main( int argc, char **argv ) { ...@@ -133,6 +172,8 @@ int main( int argc, char **argv ) {
openair0_cfg[card].time_source = 0; openair0_cfg[card].time_source = 0;
openair0_cfg[card].tx_num_channels = NB_ANTENNAS_TX; openair0_cfg[card].tx_num_channels = NB_ANTENNAS_TX;
openair0_cfg[card].rx_num_channels = NB_ANTENNAS_RX; openair0_cfg[card].rx_num_channels = NB_ANTENNAS_RX;
openair0_cfg[card].rx_gain[0] = 80;
openair0_cfg[card].tx_gain[0] = 90;
printf("HW: Configuring card %d, sample_rate %f, tx/rx num_channels %d/%d, duplex_mode %d\n", printf("HW: Configuring card %d, sample_rate %f, tx/rx num_channels %d/%d, duplex_mode %d\n",
card, card,
...@@ -192,20 +233,26 @@ int main( int argc, char **argv ) { ...@@ -192,20 +233,26 @@ int main( int argc, char **argv ) {
for (int i=0; i<NB_ANTENNAS_RX; i++) { for (int i=0; i<NB_ANTENNAS_RX; i++) {
rxp[i] = (int32_t *) malloc16_clear( rxdata_size ); rxp[i] = (int32_t *) malloc16_clear( rxdata_size * sizeof(int32_t));
} }
for (int i=0; i<NB_ANTENNAS_TX; i++) { for (int i=0; i<NB_ANTENNAS_TX; i++) {
txp[i] = (int32_t *) malloc16_clear( txdata_size ); txp[i] = (int32_t *) malloc16_clear( txdata_size * sizeof(int32_t));
txp_temp[i] = (int32_t *) malloc16_clear( 61440 * sizeof(int32_t));
} }
printf("sine wave\n");
genSineWave(3.84e6, 122.88e6, 0x1ff, TXSEQLEN, gTxSeq);
readBlockSize = samples_per_subframe/2; readBlockSize = samples_per_subframe/2;
writeBlockSize = readBlockSize; writeBlockSize = readBlockSize;
device_init(&(rfdevice), &openair0_cfg[0]); device_init(&(rfdevice), &openair0_cfg[0]);
threadCreate(&tx_threads, tx_thread, &rfdevice, "tx_thread", 21, sched_get_priority_max(SCHED_RR)-2); threadCreate(&tx_threads, tx_thread, &rfdevice, "tx_thread", 5, sched_get_priority_max(SCHED_RR)-2);
rfdevice.trx_start_func(&rfdevice); rfdevice.trx_start_func(&rfdevice);
//first time is very long, don't know why. //first time is very long, don't know why.
...@@ -222,13 +269,14 @@ int main( int argc, char **argv ) { ...@@ -222,13 +269,14 @@ int main( int argc, char **argv ) {
clock_gettime_cur = NR_TIMESPEC_TO_DOUBLE_US( nr_get_timespec_diff( &time_start, &time_stop ));//us clock_gettime_cur = NR_TIMESPEC_TO_DOUBLE_US( nr_get_timespec_diff( &time_start, &time_stop ));//us
printf("using %.2lf msec in 1st time\n", clock_gettime_cur/1000); printf("using %.2lf msec in 1st time\n", clock_gettime_cur/1000);
clock_gettime(CLOCK_REALTIME,&time_start); clock_gettime(CLOCK_REALTIME,&time_start);
while (1) { while (1) {
absolute_slot++;
clock_gettime(CLOCK_REALTIME,&time_stop); clock_gettime(CLOCK_REALTIME,&time_stop);
clock_gettime_cur = NR_TIMESPEC_TO_DOUBLE_US( nr_get_timespec_diff( &time_start, &time_stop ));//us clock_gettime_cur = NR_TIMESPEC_TO_DOUBLE_US( nr_get_timespec_diff( &time_start, &time_stop ));//us
if ((clock_gettime_cur > 300) || (clock_gettime_cur_tx > 510)) if ((clock_gettime_cur > 510) || (clock_gettime_cur_tx > 510))
printf("slot_num %d, timestamp %ld, writeTimestamp %ld,time = %.2f sec, delay_time=(%.2lf, %d) (tx %.2lf, %d)msec. readBlockSize %d. real read %ld.\n", printf("slot_num %d, timestamp %ld, writeTimestamp %ld,time = %.2f sec, delay_time=(%.2lf, %d) (tx %.2lf, %d)msec. readBlockSize %d. real read %ld.\n",
absolute_slot, rx_timestamp, writeTimestamp, ((float)absolute_slot)/2/1000, clock_gettime_cur/1000,rx_cnt, clock_gettime_cur_tx/1000, tx_cnt, readBlockSize,(rx_timestamp - timestampold)); absolute_slot, rx_timestamp, writeTimestamp, ((float)absolute_slot)/2/1000, clock_gettime_cur/1000,rx_cnt, clock_gettime_cur_tx/1000, tx_cnt, readBlockSize,(rx_timestamp - timestampold));
clock_gettime(CLOCK_REALTIME,&time_start); clock_gettime(CLOCK_REALTIME,&time_start);
...@@ -236,17 +284,34 @@ int main( int argc, char **argv ) { ...@@ -236,17 +284,34 @@ int main( int argc, char **argv ) {
#if 1 #if 1
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ, VCD_FUNCTION_IN ); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ, VCD_FUNCTION_IN );
for (int i=0; i<NB_ANTENNAS_RX; i++) {
rxp_temp[i] =(int32_t *)rxp[i] + (rx_cnt % SLOTS_NUM)* 61440;
}
rfdevice.trx_read_func(&rfdevice, rfdevice.trx_read_func(&rfdevice,
&rx_timestamp, &rx_timestamp,
(void **)rxp, //(void **)&rxp[0][(rx_cnt % SLOTS_NUM)* 61440],
(void **)rxp_temp,
readBlockSize, readBlockSize,
1); 1);
rx_cnt++; rx_cnt++;
absolute_slot++;
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ, VCD_FUNCTION_OUT ); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ, VCD_FUNCTION_OUT );
#endif #endif
#if 1
if(rx_cnt == 2000)
{
printf("begin to dump\n");
FILE *fp1 = fopen("rfdata_v3_ant0.bin", "wb");
fwrite(&rxp[0][0], 4, rxdata_size, fp1);
fclose(fp1);
printf("end, write file ok ++++++++++++++++++++++++\r\n");
usleep(50000);
exit(0);
}
#endif
#ifdef TX_RX_ONE_THREAD #ifdef TX_RX_ONE_THREAD
// use previous timing_advance value to compute writeTimestamp // use previous timing_advance value to compute writeTimestamp
//writeTimestamp = timestamp+samples_per_subframe/20*5;// sent after 5 slot. //writeTimestamp = timestamp+samples_per_subframe/20*5;// sent after 5 slot.
......
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