コード例 #1
0
ファイル: pbch_enodeb.c プロジェクト: KrishnaAdapa/libLTE
void base_init() {
	/* init memory */
	slot_buffer = malloc(sizeof(cf_t) * slot_n_re);
	if (!slot_buffer) {
		perror("malloc");
		exit(-1);
	}
	output_buffer = malloc(sizeof(cf_t) * slot_n_samples);
	if (!output_buffer) {
		perror("malloc");
		exit(-1);
	}
	/* open file or USRP */
	if (output_file_name) {
		if (filesink_init(&fsink, output_file_name, COMPLEX_FLOAT_BIN)) {
			fprintf(stderr, "Error opening file %s\n", output_file_name);
			exit(-1);
		}
	} else {
#ifndef DISABLE_UHD
		printf("Opening UHD device...\n");
		if (cuhd_open(uhd_args,&uhd)) {
			fprintf(stderr, "Error opening uhd\n");
			exit(-1);
		}
#else
		printf("Error UHD not available. Select an output file\n");
		exit(-1);
#endif
	}

	/* create ifft object */
	if (lte_ifft_init(&ifft, CPNORM, nof_prb)) {
		fprintf(stderr, "Error creating iFFT object\n");
		exit(-1);
	}
	if (pbch_init(&pbch, 6, cell_id, CPNORM)) {
		fprintf(stderr, "Error creating PBCH object\n");
		exit(-1);
	}
}
コード例 #2
0
ファイル: pdsch_enodeb.c プロジェクト: SPLURGE831/libLTE
void base_init() {
  
  /* init memory */
  sf_buffer = malloc(sizeof(cf_t) * sf_n_re);
  if (!sf_buffer) {
    perror("malloc");
    exit(-1);
  }
  output_buffer = malloc(sizeof(cf_t) * sf_n_samples);
  if (!output_buffer) {
    perror("malloc");
    exit(-1);
  }
  /* open file or USRP */
  if (output_file_name) {
    if (filesink_init(&fsink, output_file_name, COMPLEX_FLOAT_BIN)) {
      fprintf(stderr, "Error opening file %s\n", output_file_name);
      exit(-1);
    }
  } else {
#ifndef DISABLE_UHD
    printf("Opening UHD device...\n");
    if (cuhd_open(uhd_args, &uhd)) {
      fprintf(stderr, "Error opening uhd\n");
      exit(-1);
    }
#else
    printf("Error UHD not available. Select an output file\n");
    exit(-1);
#endif
  }

  /* create ifft object */
  if (lte_ifft_init(&ifft, CPNORM, cell.nof_prb)) {
    fprintf(stderr, "Error creating iFFT object\n");
    exit(-1);
  }
  if (pbch_init(&pbch, cell)) {
    fprintf(stderr, "Error creating PBCH object\n");
    exit(-1);
  }

  if (regs_init(&regs, R_1, PHICH_NORM, cell)) {
    fprintf(stderr, "Error initiating regs\n");
    exit(-1);
  }

  if (pcfich_init(&pcfich, &regs, cell)) {
    fprintf(stderr, "Error creating PBCH object\n");
    exit(-1);
  }

  if (regs_set_cfi(&regs, cfi)) {
    fprintf(stderr, "Error setting CFI\n");
    exit(-1);
  }

  if (pdcch_init(&pdcch, &regs, cell)) {
    fprintf(stderr, "Error creating PDCCH object\n");
    exit(-1);
  }

  if (pdsch_init(&pdsch, cell)) {
    fprintf(stderr, "Error creating PDSCH object\n");
    exit(-1);
  }
  
  pdsch_set_rnti(&pdsch, 1234);
  
  if (pdsch_harq_init(&harq_process, &pdsch)) {
    fprintf(stderr, "Error initiating HARQ process\n");
    exit(-1);
  }
}
コード例 #3
0
ファイル: sync_test.c プロジェクト: wujunning2011/libLTE
int main(int argc, char **argv) {
  int N_id_2, ns, find_ns;
  cf_t *buffer, *fft_buffer;
  cf_t pss_signal[PSS_LEN];
  float sss_signal0[SSS_LEN]; // for subframe 0
  float sss_signal5[SSS_LEN]; // for subframe 5
  int cid, max_cid; 
  uint32_t find_idx;
  sync_t sync;
  lte_fft_t ifft;

  parse_args(argc, argv);

  buffer = malloc(sizeof(cf_t) * FLEN);
  if (!buffer) {
    perror("malloc");
    exit(-1);
  }

  fft_buffer = malloc(sizeof(cf_t) * 2 * FLEN);
  if (!fft_buffer) {
    perror("malloc");
    exit(-1);
  }

  if (lte_ifft_init(&ifft, cp, 6)) {
    fprintf(stderr, "Error creating iFFT object\n");
    exit(-1);
  }

  if (sync_init(&sync, FLEN, 128, 128)) {
    fprintf(stderr, "Error initiating PSS/SSS\n");
    return -1;
  }

  sync_set_threshold(&sync, 1, 1);

  if (cell_id == -1) {
    cid = 0;
    max_cid = 49;
  } else {
    cid = cell_id;
    max_cid = cell_id;
}
  while(cid <= max_cid) {
    N_id_2 = cid%3;

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

    for (ns=0;ns<2;ns++) {
      memset(buffer, 0, sizeof(cf_t) * FLEN);
      pss_put_slot(pss_signal, buffer, 6, cp);
      sss_put_slot(ns?sss_signal5:sss_signal0, buffer, 6, cp);

      /* Transform to OFDM symbols */
      memset(fft_buffer, 0, sizeof(cf_t) * 2 * FLEN);
      lte_ifft_run_slot(&ifft, buffer, &fft_buffer[offset]);

      sync_find(&sync, fft_buffer, &find_idx);
      find_ns = sync_get_slot_id(&sync);
      printf("cell_id: %d find: %d, offset: %d, ns=%d find_ns=%d\n", cid, find_idx, offset,
          ns, find_ns);
      if (find_idx != offset + 960) {
        printf("offset != find_offset: %d != %d\n", find_idx, offset + 960);
        exit(-1);
      }
      if (ns*10 != find_ns) {
        printf("ns != find_ns\n", 10 * ns, find_ns);
        exit(-1);
      }
      if (sync_get_cp(&sync) != cp) {
        printf("Detected CP should be %s\n", CP_ISNORM(cp)?"Normal":"Extended");
        exit(-1);
      }
    }
    cid++;
  }

  free(fft_buffer);
  free(buffer);

  sync_free(&sync);
  lte_ifft_free(&ifft);

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