示例#1
0
void base_free() {
  int i;

  filesource_free(&fsrc);

  free(input_buffer);
  free(fft_buffer);

  filesource_free(&fsrc);
  for (i=0;i<MAX_PORTS;i++) {
    free(ce[i]);
  }
  chest_dl_free(&chest);
  lte_fft_free(&fft);

  pdcch_free(&pdcch);
  regs_free(&regs);
}
示例#2
0
void base_free() {
	int i;

	filesource_free(&fsrc);
	if (fmatlab) {
		fclose(fmatlab);
	}

	free(input_buffer);
	free(fft_buffer);

	filesource_free(&fsrc);
	for (i=0;i<MAX_PORTS_CTRL;i++) {
		free(ce[i]);
	}
	chest_free(&chest);
	lte_fft_free(&fft);

	phich_free(&phich);
	regs_free(&regs);
}
示例#3
0
void base_free() {
  int i;

  filesource_free(&fsrc);
  if (fmatlab) {
    fclose(fmatlab);
  }

  free(input_buffer);
  free(fft_buffer);

  filesource_free(&fsrc);
  for (i=0;i<MAX_PORTS;i++) {
    free(ce[i]);
  }
  chest_free(&chest);
  lte_fft_free(&fft);

  pdcch_free(&pdcch);
  pdsch_free(&pdsch);
  pdsch_harq_free(&harq_process);
  regs_free(&regs);
}
示例#4
0
void base_free() {

  pdsch_harq_free(&harq_process);
  pdsch_free(&pdsch);
  pdcch_free(&pdcch);
  regs_free(&regs);
  pbch_free(&pbch);

  lte_ifft_free(&ifft);

  if (sf_buffer) {
    free(sf_buffer);
  }
  if (output_buffer) {
    free(output_buffer);
  }
  if (output_file_name) {
    filesink_free(&fsink);
  } else {
#ifndef DISABLE_UHD
    cuhd_close(&uhd);
#endif
  }
}
示例#5
0
int main(int argc, char **argv) {
  pcfich_t pcfich;
  regs_t regs;
  int i, j;
  cf_t *ce[MAX_PORTS];
  int nof_re;
  cf_t *slot_symbols[MAX_PORTS];
  uint32_t cfi, cfi_rx, nsf;
  int cid, max_cid;
  float corr_res; 

  parse_args(argc,argv);

  nof_re = CPNORM_NSYMB * cell.nof_prb * RE_X_RB;

  /* init memory */
  for (i=0;i<MAX_PORTS;i++) {
    ce[i] = malloc(sizeof(cf_t) * nof_re);
    if (!ce[i]) {
      perror("malloc");
      exit(-1);
    }
    for (j=0;j<nof_re;j++) {
      ce[i][j] = 1;
    }
    slot_symbols[i] = malloc(sizeof(cf_t) * nof_re);
    if (!slot_symbols[i]) {
      perror("malloc");
      exit(-1);
    }
  }

  if (cell.id == 1000) {
    cid = 0;
    max_cid = 503;
  } else {
    cid = cell.id;
    max_cid = cell.id;
  }
  
  while(cid <= max_cid) {
    cell.id = cid;

    printf("Testing CellID=%d...\n", cid);

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

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

    for (nsf=0;nsf<10;nsf++) {
      for (cfi=1;cfi<4;cfi++) {
        pcfich_encode(&pcfich, cfi, slot_symbols, nsf);

        /* combine outputs */
        for (i=1;i<cell.nof_ports;i++) {
          for (j=0;j<nof_re;j++) {
            slot_symbols[0][j] += slot_symbols[i][j];
          }
        }
        if (pcfich_decode(&pcfich, slot_symbols[0], ce, 0, nsf, &cfi_rx, &corr_res)<0) {
          exit(-1);
        }
        INFO("cfi_tx: %d, cfi_rx: %d, ns: %d, distance: %f\n",
            cfi, cfi_rx, nsf, corr_res);
      }
    }
    pcfich_free(&pcfich);
    regs_free(&regs);
    cid++;
  }

  for (i=0;i<MAX_PORTS;i++) {
    free(ce[i]);
    free(slot_symbols[i]);
  }
  printf("OK\n");
  exit(0);
}
示例#6
0
文件: regs.c 项目: SPLURGE831/libLTE
/**
 * Initializes REGs structure.
 * Sets all REG indices and initializes PCFICH, PHICH and PDCCH REGs
 * Returns 0 if OK, -1 on error
 */
int regs_init(regs_t *h, phich_resources_t phich_res, phich_length_t phich_len, lte_cell_t cell) {
  int ret = LIBLTE_ERROR_INVALID_INPUTS;
  uint32_t i, k;
  uint32_t j[4], jmax, prb;
  uint32_t n[4], vo;
  uint32_t max_ctrl_symbols;

  if (h != NULL &&
      lte_cell_isvalid(&cell))
  {
    bzero(h, sizeof(regs_t));
    ret = LIBLTE_ERROR;
    
    max_ctrl_symbols = cell.nof_prb<10?4:3;
    vo = cell.id % 3;
    h->cell = cell;
    h->max_ctrl_symbols = max_ctrl_symbols;
    h->cfi_initiated = false;
    h->phich_res = phich_res;
    h->phich_len = phich_len;

    h->nof_regs = 0;
    for (i = 0; i < max_ctrl_symbols; i++) {
      n[i] = regs_num_x_symbol(i, h->cell.nof_ports, h->cell.cp);
      if (n[i] == -1) {
        return -1;
      }
      h->nof_regs += h->cell.nof_prb * n[i];
    }
    INFO("Indexing %d REGs. CellId: %d, %d PRB, CP: %s\n", h->nof_regs, h->cell.id, h->cell.nof_prb,
        CP_ISNORM(h->cell.cp)?"Normal":"Extended");
    h->regs = malloc(sizeof(regs_reg_t) * h->nof_regs);
    if (!h->regs) {
      perror("malloc");
      goto clean_and_exit;
    }

    /* Sort REGs according to PDCCH mapping, beggining from the lowest l index then k */
    bzero(j, sizeof(int) * 4);
    k = i = prb = jmax = 0;
    while (k < h->nof_regs) {
      if (n[i] == 3 || (n[i] == 2 && jmax != 1)) {
        if (regs_reg_init(&h->regs[k], i, j[i], prb * RE_X_RB, n[i], vo)) {
          fprintf(stderr, "Error initializing REGs\n");
          goto clean_and_exit;
        }
        /*DEBUG("Available REG #%3d: l=%d, prb=%d, nreg=%d (k0=%d)\n", k, i, prb, j[i],
            h->regs[k].k0);
        */
        j[i]++;
        k++;
      }
      i++;
      if (i == max_ctrl_symbols) {
        i = 0;
        jmax++;
      }
      if (jmax == 3) {
        prb++;
        bzero(j, sizeof(int) * 4);
        jmax = 0;
      }
    }
    if (regs_pcfich_init(h)) {
      fprintf(stderr, "Error initializing PCFICH REGs\n");
      goto clean_and_exit;
    }

    if (regs_phich_init(h)) {
      fprintf(stderr, "Error initializing PHICH REGs\n");
      goto clean_and_exit;
    }
    if (regs_pdcch_init(h)) {
      fprintf(stderr, "Error initializing PDCCH REGs\n");
      goto clean_and_exit;
    }

    ret = LIBLTE_SUCCESS;
  }
clean_and_exit:
  if (ret == LIBLTE_ERROR) {
    regs_free(h);
  }
  return ret;
}
示例#7
0
int main(int argc, char **argv) {
	phich_t phich;
	regs_t regs;
	int i, j;
	cf_t *ce[MAX_PORTS_CTRL];
	int nof_re;
	cf_t *slot_symbols[MAX_PORTS_CTRL];
	char ack[50][PHICH_NORM_NSEQUENCES], ack_rx;
	int nsf, distance;
	int cid, max_cid;
	int ngroup, nseq, max_nseq;

	parse_args(argc,argv);

	max_nseq = CP_ISNORM(cp)?PHICH_NORM_NSEQUENCES:PHICH_EXT_NSEQUENCES;

	nof_re = CPNORM_NSYMB * nof_prb * RE_X_RB;

	/* init memory */
	for (i=0;i<MAX_PORTS_CTRL;i++) {
		ce[i] = malloc(sizeof(cf_t) * nof_re);
		if (!ce[i]) {
			perror("malloc");
			exit(-1);
		}
		for (j=0;j<nof_re;j++) {
			ce[i][j] = 1;
		}
		slot_symbols[i] = malloc(sizeof(cf_t) * nof_re);
		if (!slot_symbols[i]) {
			perror("malloc");
			exit(-1);
		}
	}

	if (cell_id == -1) {
		cid = 0;
		max_cid = 503;
	} else {
		cid = cell_id;
		max_cid = cell_id;
	}
	while(cid <= max_cid) {

		printf("Testing CellID=%d...\n", cid);

		if (regs_init(&regs, cid, nof_prb, nof_ports, phich_res, phich_length, cp)) {
			fprintf(stderr, "Error initiating regs\n");
			exit(-1);
		}

		if (phich_init(&phich, &regs, cid, nof_prb, nof_ports, cp)) {
			fprintf(stderr, "Error creating PBCH object\n");
			exit(-1);
		}

		for (nsf=0;nsf<10;nsf++) {

			phich_reset(&phich, slot_symbols);

			/* Transmit all PHICH groups and sequence numbers */
			for (ngroup=0;ngroup<phich_ngroups(&phich);ngroup++) {
				for (nseq=0;nseq<max_nseq;nseq++) {

					ack[ngroup][nseq] = rand()%2;

					phich_encode(&phich, ack[ngroup][nseq], ngroup, nseq, nsf, slot_symbols);
				}
			}
			/* combine outputs */
			for (i=1;i<nof_ports;i++) {
				for (j=0;j<nof_re;j++) {
					slot_symbols[0][j] += slot_symbols[i][j];
				}
			}

			/* Receive all PHICH groups and sequence numbers */
			for (ngroup=0;ngroup<phich_ngroups(&phich);ngroup++) {
				for (nseq=0;nseq<max_nseq;nseq++) {

					if (phich_decode(&phich, slot_symbols[0], ce, ngroup, nseq, nsf, &ack_rx, &distance)<0) {
						printf("Error decoding ACK\n");
						exit(-1);
					}
					INFO("%d/%d, ack_tx: %d, ack_rx: %d, ns: %d, distance: %d\n",
							ngroup, nseq, ack[ngroup][nseq], ack_rx, nsf, distance);
					if (ack[ngroup][nseq] != ack_rx) {
						printf("Invalid received ACK: %d!=%d\n", ack[ngroup][nseq], ack_rx);
						exit(-1);
					}
					if (distance) {
						printf("Error\n");
						exit(-1);
					}
				}
			}
		}
		phich_free(&phich);
		regs_free(&regs);
		cid++;
	}

	for (i=0;i<MAX_PORTS_CTRL;i++) {
		free(ce[i]);
		free(slot_symbols[i]);
	}
	printf("OK\n");
	exit(0);
}
示例#8
0
/* the gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  int i; 
  lte_cell_t cell; 
  pcfich_t pcfich;
  chest_dl_t chest; 
  lte_fft_t fft; 
  regs_t regs;
  uint32_t sf_idx; 
  cf_t *input_fft, *input_signal;
  
  if (nrhs != NOF_INPUTS) {
    help();
    return;
  }
    
  if (mexutils_read_cell(ENBCFG, &cell)) {
    help();
    return;
  }
  
  if (mexutils_read_uint32_struct(ENBCFG, "NSubframe", &sf_idx)) {
    help();
    return;
  }

  if (chest_dl_init(&chest, cell)) {
    mexErrMsgTxt("Error initializing equalizer\n");
    return;
  }

  if (lte_fft_init(&fft, cell.cp, cell.nof_prb)) {
    mexErrMsgTxt("Error initializing FFT\n");
    return;
  }
  
  if (regs_init(&regs, cell)) {
    mexErrMsgTxt("Error initiating regs\n");
    return;
  }
  
  if (pcfich_init(&pcfich, &regs, cell)) {
    mexErrMsgTxt("Error creating PBCH object\n");
    return;
  }
      
  /** Allocate input buffers */
  if (mexutils_read_cf(INPUT, &input_signal) < 0) {
    mexErrMsgTxt("Error reading input signal\n");
    return; 
  }
  input_fft = vec_malloc(SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
  
  // Set Channel estimates to 1.0 (ignore fading) 
  cf_t *ce[MAX_PORTS];
  for (i=0;i<cell.nof_ports;i++) {
    ce[i] = vec_malloc(SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
  }
  
  lte_fft_run_sf(&fft, input_signal, input_fft);

  if (nrhs > NOF_INPUTS) {
    cf_t *cearray; 
    mexutils_read_cf(prhs[NOF_INPUTS], &cearray);
    for (i=0;i<cell.nof_ports;i++) {
      for (int j=0;j<SF_LEN_RE(cell.nof_prb, cell.cp);j++) {
        ce[i][j] = *cearray;
        cearray++;
      }
    }
  } else {
    chest_dl_estimate(&chest, input_fft, ce, sf_idx);    
  }
  float noise_power;
  if (nrhs > NOF_INPUTS + 1) {
    noise_power = mxGetScalar(prhs[NOF_INPUTS+1]);
  } else {
    noise_power = chest_dl_get_noise_estimate(&chest);
  }
    
    
  uint32_t cfi;
  float corr_res; 
  int n = pcfich_decode(&pcfich, input_fft, ce, noise_power,  sf_idx, &cfi, &corr_res);

  if (nlhs >= 1) { 
    if (n < 0) {      
      plhs[0] = mxCreateDoubleScalar(-1);
    } else {
      plhs[0] = mxCreateDoubleScalar(cfi);      
    }
  }
  if (nlhs >= 2) {
    mexutils_write_cf(pcfich.pcfich_d, &plhs[1], 16, 1);  
  }
  if (nlhs >= 3) {
    mexutils_write_cf(pcfich.pcfich_symbols[0], &plhs[2], 16, 1);  
  }
  
  chest_dl_free(&chest);
  lte_fft_free(&fft);
  pcfich_free(&pcfich);
  regs_free(&regs);
  
  for (i=0;i<cell.nof_ports;i++) {
    free(ce[i]);
  }
  free(input_signal);
  free(input_fft);
  
  return;
}