2014-06-17 03:44:42 -07:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* \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>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
2015-03-18 05:31:13 -07:00
|
|
|
#include "srslte/srslte.h"
|
2014-06-17 03:44:42 -07:00
|
|
|
|
2015-03-18 05:41:50 -07:00
|
|
|
srslte_cell_t cell = {
|
2014-06-29 10:51:25 -07:00
|
|
|
6, // nof_prb
|
|
|
|
1, // nof_ports
|
2015-01-21 05:55:09 -08:00
|
|
|
0, // cell_id
|
2015-03-18 05:59:29 -07:00
|
|
|
SRSLTE_SRSLTE_CP_NORM, // cyclic prefix
|
|
|
|
SRSLTE_PHICH_SRSLTE_PHICH_R_1_6, // PHICH resources
|
|
|
|
SRSLTE_PHICH_NORM // PHICH length
|
2014-06-29 10:51:25 -07:00
|
|
|
};
|
|
|
|
|
2015-01-21 05:55:09 -08:00
|
|
|
uint32_t cfi = 2;
|
2014-07-07 11:42:10 -07:00
|
|
|
uint32_t tbs = 0;
|
2015-01-29 16:15:09 -08:00
|
|
|
uint32_t nof_tbs = 0;
|
2014-07-01 01:48:51 -07:00
|
|
|
uint32_t subframe = 1;
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_mod_t modulation = SRSLTE_MOD_BPSK;
|
2014-07-07 11:42:10 -07:00
|
|
|
uint32_t rv_idx = 0;
|
2014-06-17 03:44:42 -07:00
|
|
|
|
|
|
|
void usage(char *prog) {
|
2015-01-29 16:15:09 -08:00
|
|
|
printf("Usage: %s [Lcpsrnfvmt] -l TBS \n", prog);
|
|
|
|
printf("\t-L number of consequent TBS [Default 0]\n");
|
2014-06-27 09:36:25 -07:00
|
|
|
printf("\t-m modulation (1: BPSK, 2: QPSK, 3: QAM16, 4: QAM64) [Default BPSK]\n");
|
2014-06-29 10:51:25 -07:00
|
|
|
printf("\t-c cell id [Default %d]\n", cell.id);
|
2014-06-27 09:36:25 -07:00
|
|
|
printf("\t-s subframe [Default %d]\n", subframe);
|
2014-07-07 11:42:10 -07:00
|
|
|
printf("\t-r rv_idx [Default %d]\n", rv_idx);
|
2014-06-27 09:36:25 -07:00
|
|
|
printf("\t-f cfi [Default %d]\n", cfi);
|
2014-06-29 10:51:25 -07:00
|
|
|
printf("\t-p cell.nof_ports [Default %d]\n", cell.nof_ports);
|
|
|
|
printf("\t-n cell.nof_prb [Default %d]\n", cell.nof_prb);
|
2015-03-18 11:14:24 -07:00
|
|
|
printf("\t-v [set srslte_verbose to debug, default none]\n");
|
2014-06-17 03:44:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void parse_args(int argc, char **argv) {
|
2014-06-27 09:36:25 -07:00
|
|
|
int opt;
|
2015-01-29 16:15:09 -08:00
|
|
|
while ((opt = getopt(argc, argv, "lLcpnfvmtsr")) != -1) {
|
2014-06-27 09:36:25 -07:00
|
|
|
switch(opt) {
|
|
|
|
case 'm':
|
|
|
|
switch(atoi(argv[optind])) {
|
|
|
|
case 1:
|
2015-03-18 11:14:24 -07:00
|
|
|
modulation = SRSLTE_MOD_BPSK;
|
2014-06-27 09:36:25 -07:00
|
|
|
break;
|
|
|
|
case 2:
|
2015-03-18 11:14:24 -07:00
|
|
|
modulation = SRSLTE_MOD_QPSK;
|
2014-06-27 09:36:25 -07:00
|
|
|
break;
|
|
|
|
case 4:
|
2015-03-18 11:14:24 -07:00
|
|
|
modulation = SRSLTE_MOD_16QAM;
|
2014-06-27 09:36:25 -07:00
|
|
|
break;
|
|
|
|
case 6:
|
2015-03-18 11:14:24 -07:00
|
|
|
modulation = SRSLTE_MOD_64QAM;
|
2014-06-27 09:36:25 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Invalid modulation %d. Possible values: "
|
|
|
|
"(1: BPSK, 2: QPSK, 3: QAM16, 4: QAM64)\n", atoi(argv[optind]));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
subframe = atoi(argv[optind]);
|
|
|
|
break;
|
2014-07-07 11:42:10 -07:00
|
|
|
case 'r':
|
|
|
|
rv_idx = atoi(argv[optind]);
|
|
|
|
break;
|
2014-06-27 09:36:25 -07:00
|
|
|
case 'l':
|
|
|
|
tbs = atoi(argv[optind]);
|
|
|
|
break;
|
2015-01-29 16:15:09 -08:00
|
|
|
case 'L':
|
|
|
|
nof_tbs = atoi(argv[optind]);
|
|
|
|
break;
|
2014-06-27 09:36:25 -07:00
|
|
|
case 'p':
|
2014-06-29 10:51:25 -07:00
|
|
|
cell.nof_ports = atoi(argv[optind]);
|
2014-06-27 09:36:25 -07:00
|
|
|
break;
|
|
|
|
case 'n':
|
2014-06-29 10:51:25 -07:00
|
|
|
cell.nof_prb = atoi(argv[optind]);
|
2014-06-27 09:36:25 -07:00
|
|
|
break;
|
|
|
|
case 'c':
|
2014-06-29 10:51:25 -07:00
|
|
|
cell.id = atoi(argv[optind]);
|
2014-06-27 09:36:25 -07:00
|
|
|
break;
|
|
|
|
case 'v':
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_verbose++;
|
2014-06-27 09:36:25 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
2014-07-07 11:42:10 -07:00
|
|
|
if (tbs == 0) {
|
2014-06-27 09:36:25 -07:00
|
|
|
usage(argv[0]);
|
|
|
|
exit(-1);
|
|
|
|
}
|
2014-06-17 03:44:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_pdsch_t pdsch;
|
2014-07-07 11:42:10 -07:00
|
|
|
uint32_t i, j;
|
2014-10-17 11:44:01 -07:00
|
|
|
uint8_t *data = NULL;
|
2015-03-18 05:41:50 -07:00
|
|
|
cf_t *ce[SRSLTE_MAX_PORTS];
|
2014-07-07 11:42:10 -07:00
|
|
|
uint32_t nof_re;
|
2015-03-18 05:41:50 -07:00
|
|
|
cf_t *slot_symbols[SRSLTE_MAX_PORTS];
|
2014-06-27 09:36:25 -07:00
|
|
|
int ret = -1;
|
|
|
|
struct timeval t[3];
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_ra_mcs_t mcs;
|
2015-03-19 08:42:31 -07:00
|
|
|
srslte_ra_dl_alloc_t prb_alloc;
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_harq_t harq_process;
|
2014-07-07 11:42:10 -07:00
|
|
|
uint32_t rv;
|
2014-06-27 09:36:25 -07:00
|
|
|
|
|
|
|
parse_args(argc,argv);
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
bzero(&pdsch, sizeof(srslte_pdsch_t));
|
|
|
|
bzero(&harq_process, sizeof(srslte_harq_t));
|
2015-03-18 05:41:50 -07:00
|
|
|
bzero(ce, sizeof(cf_t*)*SRSLTE_MAX_PORTS);
|
|
|
|
bzero(slot_symbols, sizeof(cf_t*)*SRSLTE_MAX_PORTS);
|
2015-01-29 16:15:09 -08:00
|
|
|
|
2015-03-18 05:59:29 -07:00
|
|
|
nof_re = 2 * SRSLTE_SRSLTE_SRSLTE_CP_NORM_NSYMB * cell.nof_prb * SRSLTE_NRE;
|
2014-06-27 09:36:25 -07:00
|
|
|
|
|
|
|
mcs.mod = modulation;
|
2014-12-30 07:23:03 -08:00
|
|
|
|
2014-06-29 10:51:25 -07:00
|
|
|
prb_alloc.slot[0].nof_prb = cell.nof_prb;
|
2014-06-27 09:36:25 -07:00
|
|
|
for (i=0;i<prb_alloc.slot[0].nof_prb;i++) {
|
2015-01-21 05:55:09 -08:00
|
|
|
prb_alloc.slot[0].prb_idx[i] = true;
|
2014-06-27 09:36:25 -07:00
|
|
|
}
|
2015-03-18 11:14:24 -07:00
|
|
|
memcpy(&prb_alloc.slot[1], &prb_alloc.slot[0], sizeof(srslte_ra_prb_slot_t));
|
2014-06-27 09:36:25 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_ra_dl_alloc_re(&prb_alloc, cell.nof_prb, cell.nof_ports, cell.nof_prb<10?(cfi+1):cfi, cell.cp);
|
2015-01-21 05:55:09 -08:00
|
|
|
|
2014-06-27 09:36:25 -07:00
|
|
|
/* init memory */
|
2014-06-29 10:51:25 -07:00
|
|
|
for (i=0;i<cell.nof_ports;i++) {
|
2014-06-27 09:36:25 -07:00
|
|
|
ce[i] = malloc(sizeof(cf_t) * nof_re);
|
|
|
|
if (!ce[i]) {
|
|
|
|
perror("malloc");
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
for (j=0;j<nof_re;j++) {
|
|
|
|
ce[i][j] = 1;
|
|
|
|
}
|
|
|
|
slot_symbols[i] = calloc(sizeof(cf_t) , nof_re);
|
|
|
|
if (!slot_symbols[i]) {
|
|
|
|
perror("malloc");
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
}
|
2015-01-29 16:15:09 -08:00
|
|
|
|
|
|
|
data = malloc(sizeof(uint8_t) * (tbs+nof_tbs));
|
2014-06-27 09:36:25 -07:00
|
|
|
if (!data) {
|
|
|
|
perror("malloc");
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
if (srslte_pdsch_init(&pdsch, cell)) {
|
2014-06-27 09:36:25 -07:00
|
|
|
fprintf(stderr, "Error creating PDSCH object\n");
|
|
|
|
goto quit;
|
|
|
|
}
|
2014-07-07 11:42:10 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_pdsch_set_rnti(&pdsch, 1234);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
if (srslte_harq_init(&harq_process, cell)) {
|
2014-07-07 11:42:10 -07:00
|
|
|
fprintf(stderr, "Error initiating HARQ process\n");
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
2015-01-29 16:15:09 -08:00
|
|
|
for (mcs.tbs = tbs;mcs.tbs<=tbs+nof_tbs;mcs.tbs++) {
|
2015-03-18 11:14:24 -07:00
|
|
|
if (SRSLTE_VERBOSE_ISNONE()) {
|
2015-01-29 16:15:09 -08:00
|
|
|
printf("Decoding TBS: %d\r",mcs.tbs);
|
|
|
|
}
|
|
|
|
for (i=0;i<mcs.tbs;i++) {
|
|
|
|
data[i] = rand()%2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (rv=0;rv<=rv_idx;rv++) {
|
2015-03-18 11:14:24 -07:00
|
|
|
if (srslte_harq_setup_dl(&harq_process, mcs, rv, subframe, &prb_alloc)) {
|
2015-02-13 02:13:56 -08:00
|
|
|
fprintf(stderr, "Error configuring HARQ process\n");
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
if (srslte_pdsch_encode(&pdsch, &harq_process, data, slot_symbols)) {
|
2015-01-29 16:15:09 -08:00
|
|
|
fprintf(stderr, "Error encoding PDSCH\n");
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* combine outputs */
|
|
|
|
for (i=0;i<cell.nof_ports;i++) {
|
|
|
|
for (j=0;j<nof_re;j++) {
|
|
|
|
if (i > 0) {
|
|
|
|
slot_symbols[0][j] += slot_symbols[i][j];
|
|
|
|
}
|
|
|
|
ce[i][j] = 1;
|
2014-07-07 11:42:10 -07:00
|
|
|
}
|
2014-06-27 09:36:25 -07:00
|
|
|
}
|
2015-01-29 16:15:09 -08:00
|
|
|
|
|
|
|
gettimeofday(&t[1], NULL);
|
2015-03-18 11:14:24 -07:00
|
|
|
int r = srslte_pdsch_decode(&pdsch, &harq_process, slot_symbols[0], ce, 0, data);
|
2015-01-29 16:15:09 -08:00
|
|
|
gettimeofday(&t[2], NULL);
|
|
|
|
get_time_interval(t);
|
|
|
|
if (r) {
|
|
|
|
printf("Error decoding TBS: %d\n", mcs.tbs);
|
|
|
|
ret = -1;
|
|
|
|
goto quit;
|
|
|
|
} else {
|
|
|
|
if (nof_tbs == 0) {
|
|
|
|
printf("DECODED OK in %d:%d (%.2f Mbps)\n", (int) t[0].tv_sec, (int) t[0].tv_usec, (float) mcs.tbs/t[0].tv_usec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-27 09:36:25 -07:00
|
|
|
}
|
|
|
|
ret = 0;
|
2014-06-17 03:44:42 -07:00
|
|
|
quit:
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_pdsch_free(&pdsch);
|
|
|
|
srslte_harq_free(&harq_process);
|
2015-01-21 05:55:09 -08:00
|
|
|
|
2014-06-29 10:51:25 -07:00
|
|
|
for (i=0;i<cell.nof_ports;i++) {
|
2014-06-27 09:36:25 -07:00
|
|
|
if (ce[i]) {
|
|
|
|
free(ce[i]);
|
|
|
|
}
|
|
|
|
if (slot_symbols[i]) {
|
|
|
|
free(slot_symbols[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data) {
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
printf("Error\n");
|
|
|
|
} else {
|
|
|
|
printf("Ok\n");
|
|
|
|
}
|
|
|
|
exit(ret);
|
2014-06-17 03:44:42 -07:00
|
|
|
}
|