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.
161 lines
4.2 KiB
C
161 lines
4.2 KiB
C
11 years ago
|
/**
|
||
11 years ago
|
*
|
||
11 years ago
|
* \section COPYRIGHT
|
||
11 years ago
|
*
|
||
9 years ago
|
* Copyright 2013-2015 Software Radio Systems Limited
|
||
11 years ago
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
10 years ago
|
* This file is part of the srsLTE library.
|
||
11 years ago
|
*
|
||
10 years ago
|
* srsLTE is free software: you can redistribute it and/or modify
|
||
10 years ago
|
* it under the terms of the GNU Affero General Public License as
|
||
11 years ago
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
10 years ago
|
* srsLTE is distributed in the hope that it will be useful,
|
||
11 years ago
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
10 years ago
|
* GNU Affero General Public License for more details.
|
||
11 years ago
|
*
|
||
10 years ago
|
* A copy of the GNU Affero General Public License can be found in
|
||
11 years ago
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
|
*
|
||
11 years ago
|
*/
|
||
|
|
||
11 years ago
|
|
||
11 years ago
|
#include <stdbool.h>
|
||
|
#include <complex.h>
|
||
|
#include <stdint.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <strings.h>
|
||
|
|
||
10 years ago
|
#include "srslte/common/phy_common.h"
|
||
|
#include "srslte/modem/modem_table.h"
|
||
9 years ago
|
#include "srslte/utils/vector.h"
|
||
11 years ago
|
#include "lte_tables.h"
|
||
|
|
||
|
/** Internal functions */
|
||
10 years ago
|
static int table_create(srslte_modem_table_t* q) {
|
||
9 years ago
|
q->symbol_table = srslte_vec_malloc(q->nsymbols*sizeof(cf_t));
|
||
11 years ago
|
return q->symbol_table==NULL;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
void srslte_modem_table_init(srslte_modem_table_t* q) {
|
||
|
bzero((void*)q,sizeof(srslte_modem_table_t));
|
||
11 years ago
|
}
|
||
10 years ago
|
void srslte_modem_table_free(srslte_modem_table_t* q) {
|
||
11 years ago
|
if (q->symbol_table) {
|
||
|
free(q->symbol_table);
|
||
|
}
|
||
9 years ago
|
if (q->symbol_table_bpsk) {
|
||
|
free(q->symbol_table_bpsk);
|
||
|
}
|
||
9 years ago
|
if (q->symbol_table_qpsk) {
|
||
|
free(q->symbol_table_qpsk);
|
||
|
}
|
||
|
if (q->symbol_table_16qam) {
|
||
|
free(q->symbol_table_16qam);
|
||
|
}
|
||
10 years ago
|
bzero(q, sizeof(srslte_modem_table_t));
|
||
11 years ago
|
}
|
||
10 years ago
|
void srslte_modem_table_reset(srslte_modem_table_t* q) {
|
||
10 years ago
|
srslte_modem_table_free(q);
|
||
|
srslte_modem_table_init(q);
|
||
11 years ago
|
}
|
||
|
|
||
9 years ago
|
int srslte_modem_table_set(srslte_modem_table_t* q, cf_t* table, uint32_t nsymbols, uint32_t nbits_x_symbol) {
|
||
11 years ago
|
if (q->nsymbols) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
|
q->nsymbols = nsymbols;
|
||
|
if (table_create(q)) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
|
memcpy(q->symbol_table,table,q->nsymbols*sizeof(cf_t));
|
||
|
q->nbits_x_symbol = nbits_x_symbol;
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
|
|
||
9 years ago
|
int srslte_modem_table_lte(srslte_modem_table_t* q, srslte_mod_t modulation) {
|
||
9 years ago
|
srslte_modem_table_init(q);
|
||
11 years ago
|
switch(modulation) {
|
||
10 years ago
|
case SRSLTE_MOD_BPSK:
|
||
11 years ago
|
q->nbits_x_symbol = 1;
|
||
|
q->nsymbols = 2;
|
||
|
if (table_create(q)) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
9 years ago
|
set_BPSKtable(q->symbol_table);
|
||
11 years ago
|
break;
|
||
10 years ago
|
case SRSLTE_MOD_QPSK:
|
||
11 years ago
|
q->nbits_x_symbol = 2;
|
||
|
q->nsymbols = 4;
|
||
|
if (table_create(q)) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
9 years ago
|
set_QPSKtable(q->symbol_table);
|
||
11 years ago
|
break;
|
||
10 years ago
|
case SRSLTE_MOD_16QAM:
|
||
11 years ago
|
q->nbits_x_symbol = 4;
|
||
|
q->nsymbols = 16;
|
||
|
if (table_create(q)) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
9 years ago
|
set_16QAMtable(q->symbol_table);
|
||
11 years ago
|
break;
|
||
10 years ago
|
case SRSLTE_MOD_64QAM:
|
||
11 years ago
|
q->nbits_x_symbol = 6;
|
||
|
q->nsymbols = 64;
|
||
|
if (table_create(q)) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
9 years ago
|
set_64QAMtable(q->symbol_table);
|
||
11 years ago
|
break;
|
||
|
}
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
9 years ago
|
|
||
|
void srslte_modem_table_bytes(srslte_modem_table_t* q) {
|
||
|
uint8_t mask_qpsk[4] = {0xc0, 0x30, 0xc, 0x3};
|
||
|
uint8_t mask_16qam[2] = {0xf0, 0xf};
|
||
|
|
||
|
switch(q->nbits_x_symbol) {
|
||
9 years ago
|
case 1:
|
||
|
q->symbol_table_bpsk = srslte_vec_malloc(sizeof(bpsk_packed_t)*256);
|
||
|
for (uint32_t i=0;i<256;i++) {
|
||
|
for (int j=0;j<8;j++) {
|
||
|
q->symbol_table_bpsk[i].symbol[j] = q->symbol_table[(i&(1<<(7-j)))>>(7-j)];
|
||
|
}
|
||
|
}
|
||
|
q->byte_tables_init = true;
|
||
|
break;
|
||
9 years ago
|
case 2:
|
||
|
q->symbol_table_qpsk = srslte_vec_malloc(sizeof(qpsk_packed_t)*256);
|
||
|
for (uint32_t i=0;i<256;i++) {
|
||
|
for (int j=0;j<4;j++) {
|
||
|
q->symbol_table_qpsk[i].symbol[j] = q->symbol_table[(i&mask_qpsk[j])>>(6-j*2)];
|
||
|
}
|
||
|
}
|
||
|
q->byte_tables_init = true;
|
||
|
break;
|
||
|
case 4:
|
||
|
q->symbol_table_16qam = srslte_vec_malloc(sizeof(qam16_packed_t)*256);
|
||
|
for (uint32_t i=0;i<256;i++) {
|
||
|
for (int j=0;j<2;j++) {
|
||
|
q->symbol_table_16qam[i].symbol[j] = q->symbol_table[(i&mask_16qam[j])>>(4-j*4)];
|
||
|
}
|
||
|
}
|
||
|
q->byte_tables_init = true;
|
||
|
break;
|
||
|
case 6:
|
||
|
q->byte_tables_init = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|