mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
234 lines
5.8 KiB
C
234 lines
5.8 KiB
C
11 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
|
* Copyright 2013-2014 The libLTE Developers. See the
|
||
|
* COPYRIGHT file at the top-level directory of this distribution.
|
||
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
|
* This file is part of the libLTE library.
|
||
|
*
|
||
|
* libLTE is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Lesser General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
|
* libLTE is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Lesser General Public License for more details.
|
||
|
*
|
||
|
* A copy of the GNU Lesser General Public License can be found in
|
||
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <strings.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
10 years ago
|
#include "srslte/phy/phy.h"
|
||
11 years ago
|
|
||
11 years ago
|
lte_cell_t cell = {
|
||
|
6, // nof_prb
|
||
|
1, // nof_ports
|
||
|
1, // cell_id
|
||
10 years ago
|
CPNORM, // cyclic prefix
|
||
|
R_1, // PHICH resources
|
||
|
PHICH_NORM // PHICH length
|
||
11 years ago
|
};
|
||
|
|
||
11 years ago
|
uint32_t cfi = 1;
|
||
11 years ago
|
|
||
|
void usage(char *prog) {
|
||
11 years ago
|
printf("Usage: %s [cell.cpv]\n", prog);
|
||
|
printf("\t-c cell id [Default %d]\n", cell.id);
|
||
11 years ago
|
printf("\t-f cfi [Default %d]\n", cfi);
|
||
11 years ago
|
printf("\t-p cell.nof_ports [Default %d]\n", cell.nof_ports);
|
||
|
printf("\t-n cell.nof_prb [Default %d]\n", cell.nof_prb);
|
||
11 years ago
|
printf("\t-v [set verbose to debug, default none]\n");
|
||
11 years ago
|
}
|
||
|
|
||
|
void parse_args(int argc, char **argv) {
|
||
11 years ago
|
int opt;
|
||
11 years ago
|
while ((opt = getopt(argc, argv, "cell.cpnfv")) != -1) {
|
||
11 years ago
|
switch (opt) {
|
||
11 years ago
|
case 'p':
|
||
11 years ago
|
cell.nof_ports = atoi(argv[optind]);
|
||
11 years ago
|
break;
|
||
|
case 'f':
|
||
|
cfi = atoi(argv[optind]);
|
||
|
break;
|
||
|
case 'n':
|
||
11 years ago
|
cell.nof_prb = atoi(argv[optind]);
|
||
11 years ago
|
break;
|
||
|
case 'c':
|
||
11 years ago
|
cell.id = atoi(argv[optind]);
|
||
11 years ago
|
break;
|
||
|
case 'v':
|
||
|
verbose++;
|
||
|
break;
|
||
|
default:
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
int test_dci_payload_size() {
|
||
11 years ago
|
int i, j;
|
||
|
int x[4];
|
||
11 years ago
|
const dci_format_t formats[4] = { Format0, Format1, Format1A, Format1C };
|
||
|
const int prb[6] = { 6, 15, 25, 50, 75, 100 };
|
||
|
const int dci_sz[6][5] = { { 21, 19, 21, 8 }, { 22, 23, 22, 10 }, { 25, 27,
|
||
|
25, 12 }, { 27, 31, 27, 13 }, { 27, 33, 27, 14 }, { 28, 39, 28, 15 } };
|
||
11 years ago
|
|
||
|
printf("Testing DCI payload sizes...\n");
|
||
|
printf(" PRB\t0\t1\t1A\t1C\n");
|
||
11 years ago
|
for (i = 0; i < 6; i++) {
|
||
|
int n = prb[i];
|
||
|
for (j = 0; j < 4; j++) {
|
||
11 years ago
|
x[j] = dci_format_sizeof(formats[j], n);
|
||
|
if (x[j] != dci_sz[i][j]) {
|
||
11 years ago
|
fprintf(stderr, "Invalid DCI payload size for %s\n",
|
||
|
dci_format_string(formats[j]));
|
||
11 years ago
|
return -1;
|
||
|
}
|
||
|
}
|
||
11 years ago
|
printf(" %2d:\t%2d\t%2d\t%2d\t%2d\n", n, x[0], x[1], x[2], x[3]);
|
||
11 years ago
|
}
|
||
|
printf("Ok\n");
|
||
|
return 0;
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
int main(int argc, char **argv) {
|
||
11 years ago
|
pdcch_t pdcch;
|
||
10 years ago
|
dci_msg_t dci_tx[2], dci_rx[2], dci_tmp;
|
||
10 years ago
|
dci_location_t dci_locations[2];
|
||
11 years ago
|
ra_pdsch_t ra_dl;
|
||
|
regs_t regs;
|
||
|
int i, j;
|
||
11 years ago
|
cf_t *ce[MAX_PORTS];
|
||
11 years ago
|
int nof_re;
|
||
11 years ago
|
cf_t *slot_symbols[MAX_PORTS];
|
||
10 years ago
|
int nof_dcis;
|
||
|
|
||
11 years ago
|
int ret = -1;
|
||
|
|
||
11 years ago
|
parse_args(argc, argv);
|
||
11 years ago
|
|
||
11 years ago
|
nof_re = CPNORM_NSYMB * cell.nof_prb * RE_X_RB;
|
||
11 years ago
|
|
||
|
if (test_dci_payload_size()) {
|
||
|
exit(-1);
|
||
|
}
|
||
|
|
||
|
/* init memory */
|
||
11 years ago
|
for (i = 0; i < MAX_PORTS; i++) {
|
||
11 years ago
|
ce[i] = malloc(sizeof(cf_t) * nof_re);
|
||
|
if (!ce[i]) {
|
||
|
perror("malloc");
|
||
|
exit(-1);
|
||
|
}
|
||
11 years ago
|
for (j = 0; j < nof_re; j++) {
|
||
11 years ago
|
ce[i][j] = 1;
|
||
|
}
|
||
11 years ago
|
slot_symbols[i] = malloc(sizeof(cf_t) * nof_re);
|
||
|
if (!slot_symbols[i]) {
|
||
11 years ago
|
perror("malloc");
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
if (regs_init(®s, cell)) {
|
||
11 years ago
|
fprintf(stderr, "Error initiating regs\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
|
||
|
if (regs_set_cfi(®s, cfi)) {
|
||
|
fprintf(stderr, "Error setting CFI\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
|
||
11 years ago
|
if (pdcch_init(&pdcch, ®s, cell)) {
|
||
11 years ago
|
fprintf(stderr, "Error creating PDCCH object\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
|
||
10 years ago
|
nof_dcis = 2;
|
||
11 years ago
|
bzero(&ra_dl, sizeof(ra_pdsch_t));
|
||
|
ra_dl.harq_process = 0;
|
||
10 years ago
|
ra_dl.mcs_idx = 5;
|
||
11 years ago
|
ra_dl.ndi = 0;
|
||
|
ra_dl.rv_idx = 0;
|
||
|
ra_dl.alloc_type = alloc_type0;
|
||
|
ra_dl.type0_alloc.rbg_bitmask = 0x5;
|
||
|
|
||
10 years ago
|
dci_msg_pack_pdsch(&ra_dl, &dci_tx[0], Format1, cell.nof_prb, false);
|
||
|
dci_location_set(&dci_locations[0], 0, 0);
|
||
11 years ago
|
|
||
10 years ago
|
ra_dl.mcs_idx = 15;
|
||
10 years ago
|
dci_msg_pack_pdsch(&ra_dl, &dci_tx[1], Format1, cell.nof_prb, false);
|
||
|
dci_location_set(&dci_locations[1], 0, 1);
|
||
|
|
||
|
for (i=0;i<nof_dcis;i++) {
|
||
10 years ago
|
if (pdcch_encode(&pdcch, &dci_tx[i], dci_locations[i], 1234+i, slot_symbols, 0, cfi)) {
|
||
|
fprintf(stderr, "Error encoding DCI message\n");
|
||
10 years ago
|
goto quit;
|
||
|
}
|
||
|
}
|
||
11 years ago
|
|
||
10 years ago
|
vec_fprint_b(stdout, dci_tx[0].data, dci_tx[0].nof_bits);
|
||
11 years ago
|
/* combine outputs */
|
||
11 years ago
|
for (i = 1; i < cell.nof_ports; i++) {
|
||
11 years ago
|
for (j = 0; j < nof_re; j++) {
|
||
|
slot_symbols[0][j] += slot_symbols[i][j];
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
for (i=0;i<2;i++) {
|
||
10 years ago
|
if (pdcch_extract_llr(&pdcch, slot_symbols[0], ce, 0, 0, cfi)) {
|
||
10 years ago
|
fprintf(stderr, "Error extracting LLRs\n");
|
||
|
goto quit;
|
||
|
}
|
||
|
uint16_t crc_rem;
|
||
10 years ago
|
if (pdcch_decode_msg(&pdcch, &dci_tmp, &dci_locations[i], Format1, &crc_rem)) {
|
||
10 years ago
|
fprintf(stderr, "Error decoding DCI message\n");
|
||
|
goto quit;
|
||
|
}
|
||
|
if (crc_rem >= 1234 && crc_rem < 1234 + nof_dcis) {
|
||
|
crc_rem -= 1234;
|
||
|
memcpy(&dci_rx[crc_rem], &dci_tmp, sizeof(dci_msg_t));
|
||
|
} else {
|
||
|
printf("Received invalid DCI CRC 0x%x\n", crc_rem);
|
||
10 years ago
|
goto quit;
|
||
|
}
|
||
|
}
|
||
|
for (i = 0; i < nof_dcis; i++) {
|
||
|
if (memcmp(dci_tx[i].data, dci_rx[i].data, dci_tx[i].nof_bits)) {
|
||
|
printf("Error in DCI %d: Received data does not match\n", i);
|
||
|
goto quit;
|
||
|
}
|
||
|
}
|
||
11 years ago
|
ret = 0;
|
||
10 years ago
|
|
||
|
quit:
|
||
|
pdcch_free(&pdcch);
|
||
11 years ago
|
regs_free(®s);
|
||
|
|
||
11 years ago
|
for (i = 0; i < MAX_PORTS; i++) {
|
||
11 years ago
|
free(ce[i]);
|
||
11 years ago
|
free(slot_symbols[i]);
|
||
11 years ago
|
}
|
||
|
if (ret) {
|
||
|
printf("Error\n");
|
||
|
} else {
|
||
|
printf("Ok\n");
|
||
|
}
|
||
|
exit(ret);
|
||
11 years ago
|
}
|