chaned srslte_crc prefix in variable names

This commit is contained in:
ismagom 2015-04-08 16:22:09 +01:00
parent fe2fe70d48
commit 5a3c2b1a04
20 changed files with 220 additions and 118 deletions

View File

@ -84,7 +84,7 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
IF(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-format-extra-args -Winline -Wno-unused-result -Wno-format -std=c99 -D_GNU_SOURCE -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-write-strings -Wno-format-extra-args -Winline -Wno-unused-result -Wno-format -std=c99 -D_GNU_SOURCE -g")
# IF(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wno-error=implicit-function-declaration -Wno-error=unused-but-set-variable")
# ENDIF(${CMAKE_BUILD_TYPE} STREQUAL "Debug")

View File

@ -102,7 +102,7 @@ void args_default(prog_args_t *args) {
args->file_cell_id = 0;
args->uhd_args = "";
args->uhd_freq = -1.0;
args->uhd_freq = 8000000.0;
args->uhd_freq_offset = 8000000.0;
args->uhd_gain = 60.0;
args->net_port = -1;
args->net_address = "127.0.0.1";

View File

@ -131,12 +131,12 @@ SRSLTE_API int srslte_dci_msg_pack_pdsch(srslte_ra_pdsch_t *data,
srslte_dci_msg_t *msg,
srslte_dci_format_t format,
uint32_t nof_prb,
bool srslte_crc_is_crnti);
bool crc_is_crnti);
SRSLTE_API int srslte_dci_msg_unpack_pdsch(srslte_dci_msg_t *msg,
srslte_ra_pdsch_t *data,
uint32_t nof_prb,
bool srslte_crc_is_crnti);
bool crc_is_crnti);
SRSLTE_API uint32_t srslte_dci_format_sizeof(srslte_dci_format_t format,
uint32_t nof_prb);

View File

@ -115,7 +115,7 @@ SRSLTE_API int srslte_pdcch_decode_msg(srslte_pdcch_t *q,
srslte_dci_msg_t *msg,
srslte_dci_location_t *location,
srslte_dci_format_t format,
uint16_t *srslte_crc_rem);
uint16_t *crc_rem);
/* Function for generation of UE-specific search space DCI locations */
SRSLTE_API uint32_t srslte_pdcch_ue_locations(srslte_pdcch_t *q,

View File

@ -69,8 +69,8 @@ typedef struct SRSLTE_API {
srslte_tcod_t encoder;
srslte_tdec_t decoder;
srslte_crc_t srslte_crc_tb;
srslte_crc_t srslte_crc_cb;
srslte_crc_t crc_tb;
srslte_crc_t crc_cb;
srslte_uci_cqi_pusch_t uci_cqi;

View File

@ -32,7 +32,7 @@
#include "srslte/utils/bit.h"
#include "srslte/fec/crc.h"
void gen_srslte_crc_table(srslte_crc_t *h) {
void gen_crc_table(srslte_crc_t *h) {
int i, j, ord = (h->order - 8);
unsigned long bit, crc;
@ -74,21 +74,21 @@ unsigned long reversecrcbit(uint32_t crc, int nbits, srslte_crc_t *h) {
return (crc & h->crcmask);
}
int srslte_crc_set_init(srslte_crc_t *srslte_crc_par, unsigned long srslte_crc_init_value) {
int srslte_crc_set_init(srslte_crc_t *crc_par, unsigned long crc_init_value) {
srslte_crc_par->crcinit = srslte_crc_init_value;
if (srslte_crc_par->crcinit != (srslte_crc_par->crcinit & srslte_crc_par->crcmask)) {
printf("ERROR, invalid crcinit in srslte_crc_set_init().\n");
crc_par->crcinit = crc_init_value;
if (crc_par->crcinit != (crc_par->crcinit & crc_par->crcmask)) {
printf("ERROR, invalid crcinit in crc_set_init().\n");
return -1;
}
return 0;
}
int srslte_crc_init(srslte_crc_t *h, uint32_t srslte_crc_poly, int srslte_crc_order) {
int srslte_crc_init(srslte_crc_t *h, uint32_t crc_poly, int crc_order) {
// Set crc working default parameters
h->polynom = srslte_crc_poly;
h->order = srslte_crc_order;
h->polynom = crc_poly;
h->order = crc_order;
h->crcinit = 0x00000000;
// Compute bit masks for whole CRC and CRC high bit
@ -109,7 +109,7 @@ int srslte_crc_init(srslte_crc_t *h, uint32_t srslte_crc_poly, int srslte_crc_or
}
// generate lookup table
gen_srslte_crc_table(h);
gen_crc_table(h);
return 0;
}
@ -152,8 +152,8 @@ uint32_t srslte_crc_checksum(srslte_crc_t *h, uint8_t *data, int len) {
}
/** Appends srslte_crc_order checksum bits to the buffer data.
* The buffer data must be len + srslte_crc_order bytes
/** Appends crc_order checksum bits to the buffer data.
* The buffer data must be len + crc_order bytes
*/
void srslte_crc_attach(srslte_crc_t *h, uint8_t *data, int len) {
uint32_t checksum = srslte_crc_checksum(h, data, len);

View File

@ -36,15 +36,15 @@
#include "srslte/srslte.h"
#include "crc_test.h"
int num_bits = 5001, srslte_crc_length = 24;
uint32_t srslte_crc_poly = 0x1864CFB;
int num_bits = 5001, crc_length = 24;
uint32_t crc_poly = 0x1864CFB;
uint32_t seed = 1;
void usage(char *prog) {
printf("Usage: %s [nlps]\n", prog);
printf("\t-n num_bits [Default %d]\n", num_bits);
printf("\t-l srslte_crc_length [Default %d]\n", srslte_crc_length);
printf("\t-p srslte_crc_poly (Hex) [Default 0x%x]\n", srslte_crc_poly);
printf("\t-l crc_length [Default %d]\n", crc_length);
printf("\t-p crc_poly (Hex) [Default 0x%x]\n", crc_poly);
printf("\t-s seed [Default 0=time]\n");
}
@ -56,10 +56,10 @@ void parse_args(int argc, char **argv) {
num_bits = atoi(argv[optind]);
break;
case 'l':
srslte_crc_length = atoi(argv[optind]);
crc_length = atoi(argv[optind]);
break;
case 'p':
srslte_crc_poly = (uint32_t) strtoul(argv[optind], NULL, 16);
crc_poly = (uint32_t) strtoul(argv[optind], NULL, 16);
break;
case 's':
seed = (uint32_t) strtoul(argv[optind], NULL, 0);
@ -74,12 +74,12 @@ void parse_args(int argc, char **argv) {
int main(int argc, char **argv) {
int i;
uint8_t *data;
uint32_t srslte_crc_word, expected_word;
srslte_crc_t srslte_crc_p;
uint32_t crc_word, expected_word;
srslte_crc_t crc_p;
parse_args(argc, argv);
data = malloc(sizeof(uint8_t) * (num_bits + srslte_crc_length * 2));
data = malloc(sizeof(uint8_t) * (num_bits + crc_length * 2));
if (!data) {
perror("malloc");
exit(-1);
@ -96,20 +96,20 @@ int main(int argc, char **argv) {
}
//Initialize CRC params and tables
if (srslte_crc_init(&srslte_crc_p, srslte_crc_poly, srslte_crc_length)) {
if (srslte_crc_init(&crc_p, crc_poly, crc_length)) {
exit(-1);
}
// generate CRC word
srslte_crc_word = srslte_crc_checksum(&srslte_crc_p, data, num_bits);
crc_word = srslte_crc_checksum(&crc_p, data, num_bits);
free(data);
// check if generated word is as expected
if (get_expected_word(num_bits, srslte_crc_length, srslte_crc_poly, seed,
if (get_expected_word(num_bits, crc_length, crc_poly, seed,
&expected_word)) {
fprintf(stderr, "Test parameters not defined in test_results.h\n");
exit(-1);
}
exit(expected_word != srslte_crc_word);
exit(expected_word != crc_word);
}

View File

@ -70,11 +70,11 @@ int srslte_dci_msg_to_ra_dl(srslte_dci_msg_t *msg, uint16_t msg_rnti,
if (type.type == SRSLTE_DCI_MSG_TYPE_PDSCH_SCHED) {
bzero(ra_dl, sizeof(srslte_ra_pdsch_t));
bool srslte_crc_is_crnti = false;
bool crc_is_crnti = false;
if (msg_rnti >= SRSLTE_CRNTI_START && msg_rnti <= SRSLTE_CRNTI_END) {
srslte_crc_is_crnti = true;
crc_is_crnti = true;
}
if (srslte_dci_msg_unpack_pdsch(msg, ra_dl, cell.nof_prb, srslte_crc_is_crnti)) {
if (srslte_dci_msg_unpack_pdsch(msg, ra_dl, cell.nof_prb, crc_is_crnti)) {
fprintf(stderr, "Can't unpack PDSCH message\n");
return ret;
}
@ -516,7 +516,7 @@ int dci_format1_unpack(srslte_dci_msg_t *msg, srslte_ra_pdsch_t *data, uint32_t
* TODO: RA procedure initiated by PDCCH, TPC commands
*/
int dci_format1As_pack(srslte_ra_pdsch_t *data, srslte_dci_msg_t *msg, uint32_t nof_prb,
bool srslte_crc_is_crnti) {
bool crc_is_crnti) {
/* pack bits */
uint8_t *y = msg->data;
@ -538,7 +538,7 @@ int dci_format1As_pack(srslte_ra_pdsch_t *data, srslte_dci_msg_t *msg, uint32_t
}
} else {
uint32_t n_vrb_dl;
if (srslte_crc_is_crnti && nof_prb > 50) {
if (crc_is_crnti && nof_prb > 50) {
n_vrb_dl = 16;
} else {
n_vrb_dl = srslte_ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == SRSLTE_RA_TYPE2_NG1);
@ -559,7 +559,7 @@ int dci_format1As_pack(srslte_ra_pdsch_t *data, srslte_dci_msg_t *msg, uint32_t
riv = data->type2_alloc.riv;
}
uint32_t nb_gap = 0;
if (srslte_crc_is_crnti && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST && nof_prb >= 50) {
if (crc_is_crnti && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST && nof_prb >= 50) {
nb_gap = 1;
*y++ = data->type2_alloc.n_gap;
}
@ -570,7 +570,7 @@ int dci_format1As_pack(srslte_ra_pdsch_t *data, srslte_dci_msg_t *msg, uint32_t
srslte_bit_pack(data->harq_process, &y, 3);
if (!srslte_crc_is_crnti && nof_prb >= 50 && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST) {
if (!crc_is_crnti && nof_prb >= 50 && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST) {
*y++ = data->type2_alloc.n_gap;
} else {
y++; // bit reserved
@ -579,7 +579,7 @@ int dci_format1As_pack(srslte_ra_pdsch_t *data, srslte_dci_msg_t *msg, uint32_t
// rv version
srslte_bit_pack(data->rv_idx, &y, 2);
if (srslte_crc_is_crnti) {
if (crc_is_crnti) {
// TPC not implemented
*y++ = 0;
*y++ = 0;
@ -602,7 +602,7 @@ int dci_format1As_pack(srslte_ra_pdsch_t *data, srslte_dci_msg_t *msg, uint32_t
*
*/
int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_pdsch_t *data, uint32_t nof_prb,
bool srslte_crc_is_crnti) {
bool crc_is_crnti) {
/* pack bits */
uint8_t *y = msg->data;
@ -626,7 +626,7 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_pdsch_t *data, uint32_
/* unpack RIV according to 7.1.6.3 of 36.213 */
uint32_t nb_gap = 0;
if (srslte_crc_is_crnti && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST && nof_prb >= 50) {
if (crc_is_crnti && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST && nof_prb >= 50) {
nb_gap = 1;
data->type2_alloc.n_gap = *y++;
}
@ -646,7 +646,7 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_pdsch_t *data, uint32_
data->harq_process = srslte_bit_unpack(&y, 3);
if (!srslte_crc_is_crnti && nof_prb >= 50 && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST) {
if (!crc_is_crnti && nof_prb >= 50 && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST) {
data->type2_alloc.n_gap = *y++;
} else {
y++; // bit reserved
@ -655,7 +655,7 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_pdsch_t *data, uint32_
// rv version
srslte_bit_pack(data->rv_idx, &y, 2);
if (srslte_crc_is_crnti) {
if (crc_is_crnti) {
// TPC not implemented
y++;
y++;
@ -665,7 +665,7 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_pdsch_t *data, uint32_
}
uint32_t n_prb;
if (srslte_crc_is_crnti) {
if (crc_is_crnti) {
n_prb = srslte_ra_nprb_dl(data, nof_prb);
} else {
n_prb = data->type2_alloc.n_prb1a == SRSLTE_RA_TYPE2_NPRB1A_2 ? 2 : 3;
@ -765,12 +765,12 @@ int dci_format1Cs_unpack(srslte_dci_msg_t *msg, srslte_ra_pdsch_t *data, uint32_
}
int srslte_dci_msg_pack_pdsch(srslte_ra_pdsch_t *data, srslte_dci_msg_t *msg, srslte_dci_format_t format,
uint32_t nof_prb, bool srslte_crc_is_crnti) {
uint32_t nof_prb, bool crc_is_crnti) {
switch (format) {
case SRSLTE_DCI_FORMAT1:
return dci_format1_pack(data, msg, nof_prb);
case SRSLTE_DCI_FORMAT1A:
return dci_format1As_pack(data, msg, nof_prb, srslte_crc_is_crnti);
return dci_format1As_pack(data, msg, nof_prb, crc_is_crnti);
case SRSLTE_DCI_FORMAT1C:
return dci_format1Cs_pack(data, msg, nof_prb);
default:
@ -781,11 +781,11 @@ int srslte_dci_msg_pack_pdsch(srslte_ra_pdsch_t *data, srslte_dci_msg_t *msg, sr
}
int srslte_dci_msg_unpack_pdsch(srslte_dci_msg_t *msg, srslte_ra_pdsch_t *data, uint32_t nof_prb,
bool srslte_crc_is_crnti) {
bool crc_is_crnti) {
if (msg->nof_bits == srslte_dci_format_sizeof(SRSLTE_DCI_FORMAT1, nof_prb)) {
return dci_format1_unpack(msg, data, nof_prb);
} else if (msg->nof_bits == srslte_dci_format_sizeof(SRSLTE_DCI_FORMAT1A, nof_prb)) {
return dci_format1As_unpack(msg, data, nof_prb, srslte_crc_is_crnti);
return dci_format1As_unpack(msg, data, nof_prb, crc_is_crnti);
} else if (msg->nof_bits == srslte_dci_format_sizeof(SRSLTE_DCI_FORMAT1C, nof_prb)) {
return dci_format1Cs_unpack(msg, data, nof_prb);
} else {

View File

@ -44,7 +44,7 @@
#define PBCH_RE_CP_NORM 240
#define PBCH_RE_CP_EXT 216
const uint8_t srslte_crc_mask[4][16] = {
const uint8_t crc_mask[4][16] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
@ -359,10 +359,10 @@ void srslte_pbch_decode_reset(srslte_pbch_t *q) {
q->frame_idx = 0;
}
void srslte_crc_set_mask(uint8_t *data, int nof_ports) {
void crc_set_mask(uint8_t *data, int nof_ports) {
int i;
for (i = 0; i < 16; i++) {
data[SRSLTE_BCH_PAYLOAD_LEN + i] = (data[SRSLTE_BCH_PAYLOAD_LEN + i] + srslte_crc_mask[nof_ports - 1][i]) % 2;
data[SRSLTE_BCH_PAYLOAD_LEN + i] = (data[SRSLTE_BCH_PAYLOAD_LEN + i] + crc_mask[nof_ports - 1][i]) % 2;
}
}
@ -376,7 +376,7 @@ void srslte_crc_set_mask(uint8_t *data, int nof_ports) {
uint32_t srslte_pbch_crc_check(srslte_pbch_t *q, uint8_t *bits, uint32_t nof_ports) {
uint8_t data[SRSLTE_BCH_PAYLOADCRC_LEN];
memcpy(data, bits, SRSLTE_BCH_PAYLOADCRC_LEN * sizeof(uint8_t));
srslte_crc_set_mask(data, nof_ports);
crc_set_mask(data, nof_ports);
int ret = srslte_crc_checksum(&q->crc, data, SRSLTE_BCH_PAYLOADCRC_LEN);
if (ret == 0) {
uint32_t chkzeros=0;
@ -567,7 +567,7 @@ int srslte_pbch_encode(srslte_pbch_t *q, uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_
/* encode & modulate */
srslte_crc_attach(&q->crc, q->data, SRSLTE_BCH_PAYLOAD_LEN);
srslte_crc_set_mask(q->data, q->cell.nof_ports);
crc_set_mask(q->data, q->cell.nof_ports);
srslte_convcoder_encode(&q->encoder, q->data, q->data_enc, SRSLTE_BCH_PAYLOADCRC_LEN);

View File

@ -275,7 +275,7 @@ uint32_t srslte_pdcch_common_locations(srslte_pdcch_t *q, srslte_dci_location_t
*/
static int dci_decode(srslte_pdcch_t *q, float *e, uint8_t *data, uint32_t E, uint32_t nof_bits, uint16_t *crc) {
uint16_t p_bits, srslte_crc_res;
uint16_t p_bits, crc_res;
uint8_t *x;
if (q != NULL &&
@ -306,12 +306,12 @@ static int dci_decode(srslte_pdcch_t *q, float *e, uint8_t *data, uint32_t E, ui
x = &data[nof_bits];
p_bits = (uint16_t) srslte_bit_unpack(&x, 16);
srslte_crc_res = ((uint16_t) srslte_crc_checksum(&q->crc, data, nof_bits) & 0xffff);
INFO("p_bits: 0x%x, srslte_crc_checksum: 0x%x, srslte_crc_rem: 0x%x\n", p_bits, srslte_crc_res,
p_bits ^ srslte_crc_res);
crc_res = ((uint16_t) srslte_crc_checksum(&q->crc, data, nof_bits) & 0xffff);
INFO("p_bits: 0x%x, crc_checksum: 0x%x, crc_rem: 0x%x\n", p_bits, crc_res,
p_bits ^ crc_res);
if (crc) {
*crc = p_bits ^ srslte_crc_res;
*crc = p_bits ^ crc_res;
}
return SRSLTE_SUCCESS;
} else {
@ -322,16 +322,16 @@ static int dci_decode(srslte_pdcch_t *q, float *e, uint8_t *data, uint32_t E, ui
/** Tries to decode a DCI message from the LLRs stored in the srslte_pdcch_t structure by the function
* srslte_pdcch_extract_llr(). This function can be called multiple times.
* The decoded message is stored in msg and the CRC remainder in srslte_crc_rem pointer
* The decoded message is stored in msg and the CRC remainder in crc_rem pointer
*
*/
int srslte_pdcch_decode_msg(srslte_pdcch_t *q, srslte_dci_msg_t *msg, srslte_dci_location_t *location, srslte_dci_format_t format, uint16_t *srslte_crc_rem)
int srslte_pdcch_decode_msg(srslte_pdcch_t *q, srslte_dci_msg_t *msg, srslte_dci_location_t *location, srslte_dci_format_t format, uint16_t *crc_rem)
{
int ret = SRSLTE_ERROR_INVALID_INPUTS;
if (q != NULL &&
msg != NULL &&
srslte_dci_location_isvalid(location) &&
srslte_crc_rem != NULL)
crc_rem != NULL)
{
if (location->ncce * 72 + PDCCH_FORMAT_NOF_BITS(location->L) >
q->nof_cce*72) {
@ -345,7 +345,7 @@ int srslte_pdcch_decode_msg(srslte_pdcch_t *q, srslte_dci_msg_t *msg, srslte_dci
location->ncce * 72, e_bits, nof_bits, location->ncce, location->L);
ret = dci_decode(q, &q->llr[location->ncce * 72],
msg->data, e_bits, nof_bits, srslte_crc_rem);
msg->data, e_bits, nof_bits, crc_rem);
if (ret == SRSLTE_SUCCESS) {
msg->nof_bits = nof_bits;
}
@ -437,7 +437,7 @@ int srslte_pdcch_extract_llr(srslte_pdcch_t *q, cf_t *sf_symbols, cf_t *ce[SRSLT
static void srslte_crc_set_mask_rnti(uint8_t *crc, uint16_t rnti) {
static void crc_set_mask_rnti(uint8_t *crc, uint16_t rnti) {
uint32_t i;
uint8_t mask[16];
uint8_t *r = mask;
@ -472,7 +472,7 @@ static int dci_encode(srslte_pdcch_t *q, uint8_t *data, uint8_t *e, uint32_t nof
memcpy(encoder.poly, poly, 3 * sizeof(int));
srslte_crc_attach(&q->crc, data, nof_bits);
srslte_crc_set_mask_rnti(&data[nof_bits], rnti);
crc_set_mask_rnti(&data[nof_bits], rnti);
srslte_convcoder_encode(&encoder, data, tmp, nof_bits + 16);

View File

@ -302,9 +302,8 @@ void srslte_pdsch_free(srslte_pdsch_t *q) {
}
/* Precalculate the PUSCH scramble sequences for a given RNTI. This function takes a while
/* Precalculate the PDSCH scramble sequences for a given RNTI. This function takes a while
* to execute, so shall be called once the final C-RNTI has been allocated for the session.
* For the connection procedure, use srslte_pusch_encode_rnti() or srslte_pusch_decode_rnti() functions
*/
int srslte_pdsch_set_rnti(srslte_pdsch_t *q, uint16_t rnti) {
uint32_t i;

View File

@ -60,11 +60,11 @@ int srslte_sch_init(srslte_sch_t *q) {
if (q) {
bzero(q, sizeof(srslte_sch_t));
if (srslte_crc_init(&q->srslte_crc_tb, SRSLTE_LTE_CRC24A, 24)) {
if (srslte_crc_init(&q->crc_tb, SRSLTE_LTE_CRC24A, 24)) {
fprintf(stderr, "Error initiating CRC\n");
goto clean;
}
if (srslte_crc_init(&q->srslte_crc_cb, SRSLTE_LTE_CRC24B, 24)) {
if (srslte_crc_init(&q->crc_cb, SRSLTE_LTE_CRC24B, 24)) {
fprintf(stderr, "Error initiating CRC\n");
goto clean;
}
@ -152,7 +152,7 @@ static int encode_tb(srslte_sch_t *q, srslte_harq_t *harq, uint8_t *data, uint8_
if (harq->rv == 0) {
/* Compute transport block CRC */
par = srslte_crc_checksum(&q->srslte_crc_tb, data, harq->mcs.tbs);
par = srslte_crc_checksum(&q->crc_tb, data, harq->mcs.tbs);
/* parity bits will be appended later */
srslte_bit_pack(par, &p_parity, 24);
@ -213,7 +213,7 @@ static int encode_tb(srslte_sch_t *q, srslte_harq_t *harq, uint8_t *data, uint8_
}
/* Attach Codeblock CRC */
if (harq->cb_segm.C > 1) {
srslte_crc_attach(&q->srslte_crc_cb, q->cb_in, rlen);
srslte_crc_attach(&q->crc_cb, q->cb_in, rlen);
}
/* Set the filler bits to <NULL> */
for (int j = 0; j < F; j++) {
@ -325,7 +325,7 @@ static int decode_tb(srslte_sch_t *q, srslte_harq_t *harq, float *e_bits, uint8_
q->nof_iterations = 0;
uint32_t len_crc;
uint8_t *cb_in_ptr;
srslte_crc_t *srslte_crc_ptr;
srslte_crc_t *crc_ptr;
early_stop = false;
srslte_tdec_reset(&q->decoder, cb_len);
@ -337,17 +337,17 @@ static int decode_tb(srslte_sch_t *q, srslte_harq_t *harq, float *e_bits, uint8_
if (harq->cb_segm.C > 1) {
len_crc = cb_len;
cb_in_ptr = q->cb_in;
srslte_crc_ptr = &q->srslte_crc_cb;
crc_ptr = &q->crc_cb;
} else {
len_crc = harq->mcs.tbs+24;
cb_in_ptr = &q->cb_in[F];
srslte_crc_ptr = &q->srslte_crc_tb;
crc_ptr = &q->crc_tb;
}
srslte_tdec_decision(&q->decoder, q->cb_in, cb_len);
/* Check Codeblock CRC and stop early if incorrect */
if (!srslte_crc_checksum(srslte_crc_ptr, cb_in_ptr, len_crc)) {
if (!srslte_crc_checksum(crc_ptr, cb_in_ptr, len_crc)) {
early_stop = true;
}
@ -385,7 +385,7 @@ static int decode_tb(srslte_sch_t *q, srslte_harq_t *harq, float *e_bits, uint8_
INFO("END CB#%d: wp: %d, rp: %d\n", i, wp, rp);
// Compute transport block CRC
par_rx = srslte_crc_checksum(&q->srslte_crc_tb, data, harq->mcs.tbs);
par_rx = srslte_crc_checksum(&q->crc_tb, data, harq->mcs.tbs);
// check parity bits
par_tx = srslte_bit_unpack(&p_parity, 24);

View File

@ -232,7 +232,7 @@ int main(int argc, char **argv) {
/* Get channel estimates for each port */
srslte_chest_dl_estimate(&chest, fft_buffer, ce, frame_cnt %10);
uint16_t srslte_crc_rem = 0;
uint16_t crc_rem = 0;
if (srslte_pdcch_extract_llr(&pdcch, fft_buffer,
ce, srslte_chest_dl_get_noise_estimate(&chest),
frame_cnt %10, cfi)) {
@ -247,14 +247,14 @@ int main(int argc, char **argv) {
nof_locations = srslte_pdcch_ue_locations(&pdcch, locations, MAX_CANDIDATES, frame_cnt %10, cfi, rnti);
}
for (i=0;i<nof_locations && srslte_crc_rem != rnti;i++) {
if (srslte_pdcch_decode_msg(&pdcch, &dci_msg, &locations[i], dci_format, &srslte_crc_rem)) {
for (i=0;i<nof_locations && crc_rem != rnti;i++) {
if (srslte_pdcch_decode_msg(&pdcch, &dci_msg, &locations[i], dci_format, &crc_rem)) {
fprintf(stderr, "Error decoding DCI msg\n");
return -1;
}
}
if (srslte_crc_rem == rnti) {
if (crc_rem == rnti) {
srslte_dci_msg_type_t type;
if (srslte_dci_msg_get_type(&dci_msg, &type, cell.nof_prb, rnti)) {
fprintf(stderr, "Can't get DCI message type\n");

View File

@ -195,16 +195,16 @@ int main(int argc, char **argv) {
fprintf(stderr, "Error extracting LLRs\n");
goto quit;
}
uint16_t srslte_crc_rem;
if (srslte_pdcch_decode_msg(&pdcch, &dci_tmp, &dci_locations[i], SRSLTE_DCI_FORMAT1, &srslte_crc_rem)) {
uint16_t crc_rem;
if (srslte_pdcch_decode_msg(&pdcch, &dci_tmp, &dci_locations[i], SRSLTE_DCI_FORMAT1, &crc_rem)) {
fprintf(stderr, "Error decoding DCI message\n");
goto quit;
}
if (srslte_crc_rem >= 1234 && srslte_crc_rem < 1234 + nof_dcis) {
srslte_crc_rem -= 1234;
memcpy(&dci_rx[srslte_crc_rem], &dci_tmp, sizeof(srslte_dci_msg_t));
if (crc_rem >= 1234 && crc_rem < 1234 + nof_dcis) {
crc_rem -= 1234;
memcpy(&dci_rx[crc_rem], &dci_tmp, sizeof(srslte_dci_msg_t));
} else {
printf("Received invalid DCI CRC 0x%x\n", srslte_crc_rem);
printf("Received invalid DCI CRC 0x%x\n", crc_rem);
goto quit;
}
}

View File

@ -162,13 +162,13 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
formats = ue_formats;
nof_formats = nof_ue_formats;
}
uint16_t srslte_crc_rem=0;
uint16_t crc_rem=0;
srslte_dci_msg_t dci_msg;
bzero(&dci_msg, sizeof(srslte_dci_msg_t));
for (int f=0;f<nof_formats;f++) {
for (i=0;i<nof_locations && srslte_crc_rem != rnti;i++) {
if (srslte_pdcch_decode_msg(&pdcch, &dci_msg, &locations[i], formats[f], &srslte_crc_rem)) {
for (i=0;i<nof_locations && crc_rem != rnti;i++) {
if (srslte_pdcch_decode_msg(&pdcch, &dci_msg, &locations[i], formats[f], &crc_rem)) {
fprintf(stderr, "Error decoding DCI msg\n");
return;
}
@ -176,7 +176,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
}
if (nlhs >= 1) {
plhs[0] = mxCreateLogicalScalar(srslte_crc_rem == rnti);
plhs[0] = mxCreateLogicalScalar(crc_rem == rnti);
}
int nof_bits = (srslte_regs_pdcch_nregs(&regs, cfi) / 9) * 72;
if (nlhs >= 2) {

View File

@ -267,19 +267,19 @@ int main(int argc, char **argv) {
nof_locations = srslte_pdcch_ue_locations(&pdcch, locations, MAX_CANDIDATES, sf_idx, cfi, rnti);
}
uint16_t srslte_crc_rem = 0;
uint16_t crc_rem = 0;
if (srslte_pdcch_extract_llr(&pdcch, fft_buffer, ce, srslte_chest_dl_get_noise_estimate(&chest), sf_idx, cfi)) {
fprintf(stderr, "Error extracting LLRs\n");
return -1;
}
for (i=0;i<nof_locations && srslte_crc_rem != rnti;i++) {
if (srslte_pdcch_decode_msg(&pdcch, &dci_msg, &locations[i], dci_format, &srslte_crc_rem)) {
for (i=0;i<nof_locations && crc_rem != rnti;i++) {
if (srslte_pdcch_decode_msg(&pdcch, &dci_msg, &locations[i], dci_format, &crc_rem)) {
fprintf(stderr, "Error decoding DCI msg\n");
return -1;
}
}
if (srslte_crc_rem == rnti) {
if (crc_rem == rnti) {
if (srslte_dci_msg_to_ra_dl(&dci_msg, rnti, cell, cfi, &ra_dl)) {
fprintf(stderr, "Error unpacking PDSCH scheduling DCI message\n");
goto goout;

View File

@ -180,7 +180,7 @@ int srslte_ue_dl_decode_fft_estimate(srslte_ue_dl_t *q, cf_t *input, uint32_t sf
/* Get channel estimates for each port */
srslte_chest_dl_estimate(&q->chest, q->sf_symbols, q->ce, sf_idx);
/* First decode PCFICH and obtain CFI */
if (srslte_pcfich_decode(&q->pcfich, q->sf_symbols, q->ce,
srslte_chest_dl_get_noise_estimate(&q->chest), sf_idx, cfi, &cfi_corr)<0) {
@ -223,6 +223,7 @@ int srslte_ue_dl_decode_rnti_rv_packet(srslte_ue_dl_t *q, srslte_dci_msg_t *dci_
ret = srslte_pdsch_decode_rnti(&q->pdsch, &q->harq_process[0], q->sf_symbols,
q->ce, 0,
rnti, data);
if (ret == SRSLTE_ERROR) {
q->pkt_errors++;
} else if (ret == SRSLTE_ERROR_INVALID_INPUTS) {
@ -304,7 +305,7 @@ int srslte_ue_dl_decode_rnti_rv(srslte_ue_dl_t *q, cf_t *input, uint8_t *data, u
if (found_dci == 1) {
ret = srslte_ue_dl_decode_rnti_rv_packet(q, &dci_msg, data, q->cfi, sf_idx, rnti, rvidx);
}
if (found_dci == 1 && ret == SRSLTE_SUCCESS) {
return q->ra_dl.mcs.tbs;
} else {

View File

@ -66,7 +66,7 @@ void dl_buffer::free_cell()
bool dl_buffer::recv_ue_sync(uint32_t current_tti, srslte_ue_sync_t *ue_sync, srslte_timestamp_t *rx_time)
{
if (signal_buffer) {
printf("DL_buffer %d receiving tti %d...\n", buffer_id, current_tti);
INFO("DL Buffer TTI %d: Receiving packet\n", tti);
cf_t *sf_buffer = NULL;
tti = current_tti;
if (srslte_ue_sync_get_buffer(ue_sync, &sf_buffer) == 1) {
@ -111,31 +111,47 @@ bool dl_buffer::get_ul_grant(pdcch_ul_search_t mode, uint32_t rnti, sched_grant
}
uint8_t data[1024];
bool dl_buffer::get_dl_grant(pdcch_dl_search_t mode, uint32_t rnti, sched_grant *grant)
{
if (signal_buffer) {
INFO("DL Buffer TTI %d: Getting DL grant\n", tti);
if (!sf_symbols_and_ce_done) {
INFO("DL Buffer TTI %d: Getting DL grant. Calling fft estimate\n", tti);
if (srslte_ue_dl_decode_fft_estimate(&ue_dl, signal_buffer, tti%10, &cfi) < 0) {
return false;
}
sf_symbols_and_ce_done = true;
}
if (!pdcch_llr_extracted) {
INFO("DL Buffer TTI %d: Getting DL grant. extracting LLR\n", tti);
if (srslte_pdcch_extract_llr(&ue_dl.pdcch, ue_dl.sf_symbols, ue_dl.ce, 0, tti%10, cfi)) {
return false;
}
pdcch_llr_extracted = true;
}
if (SRSLTE_VERBOSE_ISINFO()) {
srslte_vec_save_file((char*) "ce1", ue_dl.ce[0], SRSLTE_SF_LEN_RE(ue_dl.cell.nof_prb, ue_dl.cell.cp)*sizeof(cf_t));
srslte_vec_save_file((char*) "ce2", ue_dl.ce[1], SRSLTE_SF_LEN_RE(ue_dl.cell.nof_prb, ue_dl.cell.cp)*sizeof(cf_t));
srslte_vec_save_file((char*) "pdcch_d", ue_dl.pdcch.d, 36*ue_dl.pdcch.nof_cce*sizeof(cf_t));
}
srslte_dci_msg_t dci_msg;
if (srslte_ue_dl_find_dl_dci(&ue_dl, &dci_msg, cfi, tti%10, rnti) != 1) {
return false;
}
if (srslte_dci_msg_to_ra_dl(&dci_msg, rnti, cell, cfi,
uint32_t sfn = tti/10;
uint32_t rvidx = ((uint32_t) ceilf((float)3*((sfn/2)%4)/2))%4;
srslte_ue_dl_decode_rnti_rv_packet(&ue_dl, &dci_msg, data, cfi, tti%10, rnti, rvidx);
/* if (srslte_dci_msg_to_ra_dl(&dci_msg, rnti, cell, cfi,
(srslte_ra_pdsch_t*) grant->get_grant_ptr())) {
return false;
}
*/
return true;
}
}
@ -156,21 +172,28 @@ bool dl_buffer::decode_phich(srslte_phich_alloc_t assignment)
bool dl_buffer::decode_pdsch(sched_grant pdsch_grant, uint8_t *payload)
{
if (signal_buffer) {
INFO("DL Buffer TTI %d: Decoding PDSCH\n", tti);
if (!sf_symbols_and_ce_done) {
INFO("DL Buffer TTI %d: Decoding PDSCH. Calling fft estimate\n", tti);
if (srslte_ue_dl_decode_fft_estimate(&ue_dl, signal_buffer, tti%10, &cfi) < 0) {
return false;
}
sf_symbols_and_ce_done = true;
}
srslte_ra_pdsch_t *ra_dl = (srslte_ra_pdsch_t*) pdsch_grant.get_grant_ptr();
if (srslte_harq_setup_dl(&ue_dl.harq_process[0], ra_dl->mcs,
pdsch_grant.get_rv(), tti%10, &ra_dl->prb_alloc)) {
ra_dl->rv_idx, tti%10, &ra_dl->prb_alloc)) {
fprintf(stderr, "Error configuring HARQ process\n");
return SRSLTE_ERROR;
}
if (ue_dl.harq_process[0].mcs.mod > 0 && ue_dl.harq_process[0].mcs.tbs >= 0) {
int ret = srslte_pdsch_decode_rnti(&ue_dl.pdsch, &ue_dl.harq_process[0], ue_dl.sf_symbols,
ue_dl.ce, 0, pdsch_grant.get_rnti(), payload);
if (SRSLTE_VERBOSE_ISINFO()) {
srslte_vec_save_file((char*) "pdsch_d", ue_dl.pdsch.d, ue_dl.harq_process[0].nof_re*sizeof(cf_t));
}
if (ret == SRSLTE_SUCCESS) {
return true;
}

View File

@ -65,7 +65,7 @@ bool phy::init(ue_phy_callback_tti_t tti_clock_callback_, ue_phy_callback_status
params_db.set_param(params::CELLSEARCH_TIMEOUT_MIB_NFRAMES, 100);
if (init_radio_handler("")) {
if (init_radio_handler((char*) "")) {
pthread_create(&radio_thread, NULL, radio_thread_fnc, this);
started = true;
}
@ -353,7 +353,6 @@ void phy::run_rx_tx_state()
{
int ret;
if (!is_sfn_synched) {
printf("Synchronising SFN...\n");
ret = sync_sfn();
switch(ret) {
default:
@ -386,15 +385,12 @@ void phy::run_rx_tx_state()
void phy::main_radio_loop() {
printf("PHY initiated\n");
while(started) {
switch(phy_state) {
case IDLE:
usleep(50000);
break;
case RXTX:
printf("Run RX_TX\n");
run_rx_tx_state();
break;
}

View File

@ -33,29 +33,104 @@
void tti_callback();
void status_change();
/**********************************************************************
* Program arguments processing
***********************************************************************/
typedef struct {
float uhd_freq;
float uhd_gain;
}prog_args_t;
void args_default(prog_args_t *args) {
args->uhd_freq = -1.0;
args->uhd_gain = 60.0;
}
void usage(prog_args_t *args, char *prog) {
printf("Usage: %s [gv] -f rx_frequency (in Hz)\n", prog);
printf("\t-g UHD RX gain [Default %.2f dB]\n", args->uhd_gain);
printf("\t-v [increase verbosity, default none]\n");
}
void parse_args(prog_args_t *args, int argc, char **argv) {
int opt;
args_default(args);
while ((opt = getopt(argc, argv, "gfv")) != -1) {
switch (opt) {
case 'g':
args->uhd_gain = atof(argv[optind]);
break;
case 'f':
args->uhd_freq = atof(argv[optind]);
break;
case 'v':
srslte_verbose++;
break;
default:
usage(args, argv[0]);
exit(-1);
}
}
if (args->uhd_freq < 0) {
usage(args, argv[0]);
exit(-1);
}
}
srslte::ue::phy phy;
uint32_t total_pkts=0;
uint32_t total_dci=0;
uint32_t total_errors=0;
uint8_t payload[1024];
// This is the MAC implementation
void tti_callback(uint32_t tti) {
printf("called tti: %d\n", tti);
srslte::ue::sched_grant grant;
INFO("called tti: %d\n", tti);
// This is the MAC implementation
// SIB1 is scheduled in subframe #5 of even frames
if ((phy.tti_to_SFN(tti)%2) == 0 && phy.tti_to_subf(tti) == 5) {
srslte::ue::sched_grant grant;
srslte_verbose = SRSLTE_VERBOSE_DEBUG;
if (phy.get_dl_buffer(tti)->get_dl_grant(srslte::ue::dl_buffer::PDCCH_DL_SEARCH_SIRNTI, SRSLTE_SIRNTI, &grant)) {
if (phy.get_dl_buffer(tti)->decode_pdsch(grant, payload)) {
// Get buffer
srslte::ue::dl_buffer *buffer = phy.get_dl_buffer(tti);
// Get DL grant
if (buffer->get_dl_grant(srslte::ue::dl_buffer::PDCCH_DL_SEARCH_SIRNTI, SRSLTE_SIRNTI, &grant))
{
// MAC sets RV
grant.set_rv(((uint32_t) ceilf((float)3*((phy.tti_to_SFN(tti)/2)%4)/2))%4);
// Decode packet
if (buffer->decode_pdsch(grant, payload)) {
printf("Decoded SIB1 ok TBS: %d\n", grant.get_tbs());
srslte_vec_fprint_hex(stdout, payload, grant.get_tbs());
exit(0);
} else {
fprintf(stderr, "Could not decode SIB\n");
}
} else {
fprintf(stderr, "Error getting DL grant\n");
}
exit(0);
total_errors++;
}
exit(0);
total_dci++;
}
total_pkts++;
if (total_pkts==4) {
exit(-1);
}
}
printf("PDCCH BLER %.3f \%% PDSCH BLER %.3f \%% (total pkts: %d) \r",
1-(float) total_dci/total_pkts,
(float) total_errors/total_pkts,
total_pkts);
}
void status_change() {
@ -66,18 +141,26 @@ int main(int argc, char *argv[])
{
srslte_cell_t cell;
uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
prog_args_t prog_args;
parse_args(&prog_args, argc, argv);
// Init PHY
phy.init(tti_callback, status_change);
// Give it time to create thread
sleep(1);
phy.set_rx_freq(1825000000);
phy.set_rx_gain(60.0);
// Set RX freq and gain
phy.set_rx_freq(prog_args.uhd_freq);
phy.set_rx_gain(prog_args.uhd_gain);
/* Instruct the PHY to decode BCH */
if (!phy.decode_mib_best(&cell, bch_payload)) {
exit(-1);
}
// Print MIB
srslte_pbch_mib_fprint(stdout, &cell, phy.get_current_tti()/10);
srslte_vec_fprint_hex(stdout, bch_payload, SRSLTE_BCH_PAYLOAD_LEN);
// Set the current PHY cell to the detected cell
if (!phy.set_cell(cell)) {