Esempio n. 1
0
/* This thread listens for set_rx_gain commands to the USRP */
static void* thread_gain_fcn(void *h) {
  cuhd_handler *handler = static_cast < cuhd_handler * >(h);
  while(1) {
    pthread_mutex_lock(&handler->mutex);
    while(handler->cur_rx_gain == handler->new_rx_gain && 
          handler->cur_tx_gain == handler->new_tx_gain) 
    {
      pthread_cond_wait(&handler->cond, &handler->mutex);
    }
    if (handler->new_rx_gain != handler->cur_rx_gain) {
      handler->cur_rx_gain = handler->new_rx_gain; 
      cuhd_set_rx_gain(h, handler->cur_rx_gain);
    }
    if (handler->tx_gain_same_rx) {
      cuhd_set_tx_gain(h, handler->cur_rx_gain+handler->tx_rx_gain_offset);
    } else if (handler->new_tx_gain != handler->cur_tx_gain) {
      handler->cur_tx_gain = handler->new_tx_gain; 
      cuhd_set_tx_gain(h, handler->cur_tx_gain);
    }
    pthread_mutex_unlock(&handler->mutex);
  }
}
Esempio n. 2
0
int main(int argc, char **argv) {
  int nf, sf_idx, N_id_2;
  cf_t pss_signal[PSS_LEN];
  float sss_signal0[SSS_LEN]; // for subframe 0
  float sss_signal5[SSS_LEN]; // for subframe 5
  pbch_mib_t mib;
  ra_pdsch_t ra_dl;
  ra_prb_t prb_alloc;
  refsignal_t refs[NSLOTS_X_FRAME];
  int i, n;
  char *data;
  cf_t *sf_symbols[MAX_PORTS];
  dci_msg_t dci_msg;
  dci_location_t locations[NSUBFRAMES_X_FRAME][10];

#ifdef DISABLE_UHD
  if (argc < 3) {
    usage(argv[0]);
    exit(-1);
  }
#endif

  parse_args(argc, argv);

  N_id_2 = cell.id % 3;
  sf_n_re = 2 * CPNORM_NSYMB * cell.nof_prb * RE_X_RB;
  sf_n_samples = 2 * SLOT_LEN(lte_symbol_sz(cell.nof_prb));

  /* this *must* be called after setting slot_len_* */
  base_init();

  /* Generate PSS/SSS signals */
  pss_generate(pss_signal, N_id_2);
  sss_generate(sss_signal0, sss_signal5, cell.id);
  
  /* Generate CRS signals */
  for (i = 0; i < NSLOTS_X_FRAME; i++) {
    if (refsignal_init_LTEDL(&refs[i], 0, i, cell)) {
      fprintf(stderr, "Error initiating CRS slot=%d\n", i);
      return -1;
    }
  }

  mib.nof_ports = cell.nof_ports;
  mib.nof_prb = cell.nof_prb;
  mib.phich_length = PHICH_NORM;
  mib.phich_resources = R_1;
  mib.sfn = 0;

  for (i = 0; i < MAX_PORTS; i++) { // now there's only 1 port
    sf_symbols[i] = sf_buffer;
  }

#ifndef DISABLE_UHD
  if (!output_file_name) {
    printf("Set TX rate: %.2f MHz\n",
        cuhd_set_tx_srate(uhd, lte_sampling_freq_hz(cell.nof_prb)) / 1000000);
    printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_gain));
    printf("Set TX freq: %.2f MHz\n",
        cuhd_set_tx_freq(uhd, uhd_freq) / 1000000);
  }
#endif

  bzero(&ra_dl, sizeof(ra_pdsch_t));
  ra_dl.harq_process = 0;
  ra_dl.mcs_idx = mcs_idx;
  ra_dl.ndi = 0;
  ra_dl.rv_idx = 0;
  ra_dl.alloc_type = alloc_type0;
  ra_dl.type0_alloc.rbg_bitmask = 0xffffffff;
  
  dci_msg_pack_pdsch(&ra_dl, &dci_msg, Format1, cell.nof_prb, false);
  
  ra_prb_get_dl(&prb_alloc, &ra_dl, cell.nof_prb);
  ra_prb_get_re_dl(&prb_alloc, cell.nof_prb, 1, cell.nof_prb<10?(cfi+1):cfi, CPNORM);
  ra_mcs_from_idx_dl(mcs_idx, cell.nof_prb, &ra_dl.mcs);

  ra_pdsch_fprint(stdout, &ra_dl, cell.nof_prb);
  
  /* Initiate valid DCI locations */
  for (i=0;i<NSUBFRAMES_X_FRAME;i++) {
    pdcch_ue_locations(&pdcch, locations[i], 10, i, cfi, 1234);
  }

  data = malloc(sizeof(char) * ra_dl.mcs.tbs);
  if (!data) {
    perror("malloc");
    exit(-1);
  }  
    
  nf = 0;
  
  if (pdsch_harq_setup(&harq_process, ra_dl.mcs, &prb_alloc)) {
    fprintf(stderr, "Error configuring HARQ process\n");
    exit(-1);
  }

  while (nf < nof_frames || nof_frames == -1) {
    for (sf_idx = 0; sf_idx < NSUBFRAMES_X_FRAME && (nf < nof_frames || nof_frames == -1); sf_idx++) {
      bzero(sf_buffer, sizeof(cf_t) * sf_n_re);

      if (sf_idx == 0 || sf_idx == 5) {
        pss_put_slot(pss_signal, sf_buffer, cell.nof_prb, CPNORM);
        sss_put_slot(sf_idx ? sss_signal5 : sss_signal0, sf_buffer, cell.nof_prb,
            CPNORM);
      }
      
      if (sf_idx == 0) {
        pbch_encode(&pbch, &mib, sf_symbols);
      }
    
      for (n=0;n<2;n++) {
        refsignal_put(&refs[2*sf_idx+n], &sf_buffer[n*sf_n_re/2]);
      }

      pcfich_encode(&pcfich, cfi, sf_symbols, sf_idx);       

      INFO("SF: %d, Generating %d random bits\n", sf_idx, ra_dl.mcs.tbs);
      for (i=0;i<ra_dl.mcs.tbs;i++) {
        data[i] = rand()%2;
      }
      
      INFO("Puttting DCI to location: n=%d, L=%d\n", locations[sf_idx][0].ncce, locations[sf_idx][0].L);
      if (pdcch_encode(&pdcch, &dci_msg, locations[sf_idx][0], 1234, sf_symbols, sf_idx, cfi)) {
        fprintf(stderr, "Error encoding DCI message\n");
        exit(-1);
      }
      
      if (pdsch_encode(&pdsch, data, sf_symbols, sf_idx, &harq_process, ra_dl.rv_idx)) {
        fprintf(stderr, "Error encoding PDSCH\n");
        exit(-1);
      }

      /* Transform to OFDM symbols */
      lte_ifft_run_sf(&ifft, sf_buffer, output_buffer);
      
      /* send to file or usrp */
      if (output_file_name) {
        filesink_write(&fsink, output_buffer, sf_n_samples);
        usleep(5000);
      } else {
#ifndef DISABLE_UHD
        vec_sc_prod_cfc(output_buffer, uhd_amp, output_buffer, sf_n_samples);
        cuhd_send(uhd, output_buffer, sf_n_samples, true);
#endif
      }
      nf++;
    }
    mib.sfn = (mib.sfn + 1) % 1024;
    printf("SFN: %4d\r", mib.sfn);
    fflush(stdout);
  }

  base_free();

  printf("Done\n");
  exit(0);
}
Esempio n. 3
0
int main(int argc, char **argv) {
	int nf, ns, N_id_2;
	cf_t pss_signal[PSS_LEN];
	float sss_signal0[SSS_LEN]; // for subframe 0
	float sss_signal5[SSS_LEN]; // for subframe 5
	pbch_mib_t mib;
	refsignal_t refs[NSLOTS_X_FRAME];
	int i;
	cf_t *slot1_symbols[MAX_PORTS_CTRL];


#ifdef DISABLE_UHD
	if (argc < 3) {
		usage(argv[0]);
		exit(-1);
	}
#endif

	parse_args(argc,argv);

	N_id_2 = cell_id%3;
	slot_n_re = CPNORM_NSYMB * nof_prb * RE_X_RB;
	slot_n_samples = SLOT_LEN_CPNORM(lte_symbol_sz(nof_prb));

	/* this *must* be called after setting slot_len_* */
	base_init();

	/* Generate PSS/SSS signals */
	pss_generate(pss_signal, N_id_2);
	sss_generate(sss_signal0, sss_signal5, cell_id);

	/* Generate CRS signals */
	for (i=0;i<NSLOTS_X_FRAME;i++) {
		if (refsignal_init_LTEDL(&refs[i], 0, i, cell_id, CPNORM, nof_prb)) {
			fprintf(stderr, "Error initiating CRS slot=%d\n", i);
			return -1;
		}
	}

	mib.nof_ports = 1;
	mib.nof_prb = 6;
	mib.phich_length = PHICH_NORM;
	mib.phich_resources = R_1;
	mib.sfn = 0;

	for (i=0;i<MAX_PORTS_CTRL;i++) { // now there's only 1 port
		slot1_symbols[i] = slot_buffer;
	}

#ifndef DISABLE_UHD
	if (!output_file_name) {
		printf("Set TX rate: %.2f MHz\n", cuhd_set_tx_srate(uhd, UHD_SAMP_FREQ)/1000000);
		printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_gain));
		printf("Set TX freq: %.2f MHz\n", cuhd_set_tx_freq(uhd, uhd_freq)/1000000);
	}
#endif

	nf = 0;

	while(nf<nof_frames || nof_frames == -1) {
		for (ns=0;ns<NSLOTS_X_FRAME;ns++) {
			bzero(slot_buffer, sizeof(cf_t) * slot_n_re);

			switch(ns) {
			case 0: // tx pss/sss
			case 10: // tx pss/sss
				pss_put_slot(pss_signal, slot_buffer, nof_prb, CPNORM);
				sss_put_slot(ns?sss_signal5:sss_signal0, slot_buffer, nof_prb, CPNORM);
				break;
			case 1: // tx pbch
				pbch_encode(&pbch, &mib, slot1_symbols, 1);
				break;
			default: // transmit zeros
				break;
			}

			refsignal_put(&refs[ns], slot_buffer);

			/* Transform to OFDM symbols */
			lte_ifft_run(&ifft, slot_buffer, output_buffer);

			/* send to file or usrp */
			if (output_file_name) {
				filesink_write(&fsink, output_buffer, slot_n_samples);
				usleep(5000);
			} else {
#ifndef DISABLE_UHD
				vec_sc_prod_cfc(output_buffer, uhd_amp, output_buffer, slot_n_samples);
				cuhd_send(uhd, output_buffer, slot_n_samples, 1);
#endif
			}
		}
		mib.sfn=(mib.sfn+1)%1024;
		printf("SFN: %4d\r", mib.sfn);fflush(stdout);
		nf++;
	}

	base_free();

	printf("Done\n");
	exit(0);
}
Esempio n. 4
0
int main(int argc, char **argv) {
  int sf_idx=0, N_id_2=0;
  cf_t pss_signal[SRSLTE_PSS_LEN];
  float sss_signal0[SRSLTE_SSS_LEN]; // for subframe 0
  float sss_signal5[SRSLTE_SSS_LEN]; // for subframe 5
  int i;
  
#ifdef DISABLE_UHD
  if (argc < 3) {
    usage(argv[0]);
    exit(-1);
  }
#endif

  parse_args(argc, argv);

  N_id_2 = cell.id % 3;
  sf_n_re = 2 * SRSLTE_CP_NORM_NSYMB * cell.nof_prb * SRSLTE_NRE;
  sf_n_samples = 2 * SRSLTE_SLOT_LEN(srslte_symbol_sz(cell.nof_prb));

  cell.phich_length = SRSLTE_PHICH_NORM;
  cell.phich_resources = SRSLTE_PHICH_R_1;

  /* this *must* be called after setting slot_len_* */
  base_init();

  /* Generate PSS/SSS signals */
  srslte_pss_generate(pss_signal, N_id_2);
  srslte_sss_generate(sss_signal0, sss_signal5, cell.id);
  
  printf("Set TX rate: %.2f MHz\n",
      cuhd_set_tx_srate(uhd, srslte_sampling_freq_hz(cell.nof_prb)) / 1000000);
  printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_gain));
  printf("Set TX freq: %.2f MHz\n",
      cuhd_set_tx_freq(uhd, uhd_freq) / 1000000);

  uint32_t nbits; 
  
  srslte_modem_table_t modulator; 
  srslte_modem_table_init(&modulator);
  srslte_modem_table_lte(&modulator, modulation);

  srslte_tcod_t turbocoder; 
  srslte_tcod_init(&turbocoder, SRSLTE_TCOD_MAX_LEN_CB);

  srslte_dft_precoding_t dft_precod;
  srslte_dft_precoding_init(&dft_precod, 12);
  
  nbits = srslte_cbsegm_cbindex(sf_n_samples/8/srslte_mod_bits_x_symbol(modulation)/3 - 12);
  uint32_t ncoded_bits = sf_n_samples/8/srslte_mod_bits_x_symbol(modulation); 
  
  uint8_t *data     = malloc(sizeof(uint8_t)*nbits);
  uint8_t *data_enc = malloc(sizeof(uint8_t)*ncoded_bits);
  cf_t    *symbols  = malloc(sizeof(cf_t)*sf_n_samples);
  
  bzero(data_enc, sizeof(uint8_t)*ncoded_bits);
  while (1) {
    for (sf_idx = 0; sf_idx < SRSLTE_NSUBFRAMES_X_FRAME; sf_idx++) {
      bzero(sf_buffer, sizeof(cf_t) * sf_n_re);

#ifdef kk
      if (sf_idx == 0 || sf_idx == 5) {
        srslte_pss_put_slot(pss_signal, sf_buffer, cell.nof_prb, SRSLTE_CP_NORM);
        srslte_sss_put_slot(sf_idx ? sss_signal5 : sss_signal0, sf_buffer, cell.nof_prb,
            SRSLTE_CP_NORM);
        /* Transform to OFDM symbols */
        srslte_ofdm_tx_sf(&ifft, sf_buffer, output_buffer);
        
        float norm_factor = (float) sqrtf(cell.nof_prb)/15;
        srslte_vec_sc_prod_cfc(output_buffer, uhd_amp*norm_factor, output_buffer, SRSLTE_SF_LEN_PRB(cell.nof_prb));
      
      } else {
#endif
        /* Generate random data */
        for (i=0;i<nbits;i++) {
          data[i] = rand()%2;
        }
        srslte_tcod_encode(&turbocoder, data, data_enc, nbits);
        srslte_mod_modulate(&modulator, data_enc, symbols, ncoded_bits);        
        srslte_interp_linear_offset_cabs(symbols, output_buffer, 8, sf_n_samples/8, 0, 0);
//    }
      
      /* send to usrp */
      srslte_vec_sc_prod_cfc(output_buffer, uhd_amp, output_buffer, sf_n_samples);
      cuhd_send(uhd, output_buffer, sf_n_samples, true);
    }
  }

  base_free();

  printf("Done\n");
  exit(0);
}
Esempio n. 5
0
int main(int argc, char **argv) {
  parse_args(argc, argv);

  srslte_prach_t *p = (srslte_prach_t*)malloc(sizeof(srslte_prach_t));

  bool high_speed_flag      = false;

  cf_t preamble[MAX_LEN];
  memset(preamble, 0, sizeof(cf_t)*MAX_LEN);

  srslte_prach_init(p,
             srslte_symbol_sz(nof_prb),
             preamble_format,
             root_seq_idx,
             high_speed_flag,
             zero_corr_zone);

  uint32_t flen = srslte_sampling_freq_hz(nof_prb)/1000;

  printf("Generating PRACH\n");
  bzero(preamble, flen*sizeof(cf_t));
  srslte_prach_gen(p,
            seq_idx,
            frequency_offset,
            preamble);
  
  
  uint32_t prach_len = p->N_seq;
  
  srslte_vec_save_file("generated",preamble,prach_len*sizeof(cf_t));
  
  cf_t *buffer = malloc(sizeof(cf_t)*flen*nof_frames);
  
  // Send through UHD 
  void *uhd; 
  printf("Opening UHD device...\n");
  if (cuhd_open(uhd_args, &uhd)) {
    fprintf(stderr, "Error opening uhd\n");
    exit(-1);
  }
  printf("Subframe len:   %d samples\n", flen);
  printf("Set TX/RX rate: %.2f MHz\n", cuhd_set_rx_srate(uhd, srslte_sampling_freq_hz(nof_prb)) / 1000000);
  printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain));
  printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_gain));
  printf("Set TX/RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000);
  cuhd_set_tx_srate(uhd, srslte_sampling_freq_hz(nof_prb));
  cuhd_set_tx_freq_offset(uhd, uhd_freq, 8e6);  
  sleep(1);
  
  cf_t *zeros = calloc(sizeof(cf_t),flen);
  
  FILE *f = NULL; 
  if (output_filename) {        
    f = fopen(output_filename, "w");
  }
  
  srslte_timestamp_t tstamp; 
  
  cuhd_start_rx_stream(uhd);
  uint32_t nframe=0;
  
  while(nframe<nof_frames) {
    printf("Rx subframe %d\n", nframe);
    cuhd_recv_with_time(uhd, &buffer[flen*nframe], flen, true, &tstamp.full_secs, &tstamp.frac_secs);
    nframe++;
    if (nframe==9 || nframe==8) {
      srslte_timestamp_add(&tstamp, 0, 2e-3);
      if (nframe==8) {
        cuhd_send_timed2(uhd, zeros, flen, tstamp.full_secs, tstamp.frac_secs, true, false);      
        printf("Transmitting zeros\n");        
      } else {
        cuhd_send_timed2(uhd, preamble, flen, tstamp.full_secs, tstamp.frac_secs, true, true);      
        printf("Transmitting PRACH\n");      
      }
    }

  }
  if (f) {
    fwrite(&buffer[10*flen], flen*sizeof(cf_t), 1, f);
  }
  if (f) {
    fclose(f);
  }

  srslte_prach_free(p);
  free(p);

  printf("Done\n");
  exit(0);
}