From 16a264e12d55261fe7967b232d968c79e70d6022 Mon Sep 17 00:00:00 2001 From: ismagom Date: Wed, 23 Sep 2015 16:07:37 +0100 Subject: [PATCH] Modulator now accepting non byte-multiple inputs --- srslte/examples/pdsch_enodeb.c | 5 -- srslte/include/srslte/phch/sch.h | 2 +- srslte/lib/modem/src/mod.c | 113 ++++++++++++++++++++++--------- 3 files changed, 81 insertions(+), 39 deletions(-) diff --git a/srslte/examples/pdsch_enodeb.c b/srslte/examples/pdsch_enodeb.c index eb7dc0625..621e4b634 100644 --- a/srslte/examples/pdsch_enodeb.c +++ b/srslte/examples/pdsch_enodeb.c @@ -337,11 +337,6 @@ int update_radl() { srslte_ra_dl_grant_fprint(stdout, &dummy_grant); printf("Type new MCS index and press Enter: "); fflush(stdout); - if (dummy_grant.mcs.tbs > dummy_nbits.nof_bits) { - fprintf(stderr, "Invalid code rate %d/%d=%.2f\n", dummy_grant.mcs.tbs, dummy_nbits.nof_bits, (float) dummy_grant.mcs.tbs / dummy_nbits.nof_bits); - return -1; - } - return 0; } diff --git a/srslte/include/srslte/phch/sch.h b/srslte/include/srslte/phch/sch.h index 95e8a9545..9fe0cb033 100644 --- a/srslte/include/srslte/phch/sch.h +++ b/srslte/include/srslte/phch/sch.h @@ -46,7 +46,7 @@ #include "srslte/phch/pusch_cfg.h" #include "srslte/phch/uci.h" -#define SRSLTE_PDSCH_MAX_TDEC_ITERS 2 +#define SRSLTE_PDSCH_MAX_TDEC_ITERS 6 #ifndef SRSLTE_RX_NULL diff --git a/srslte/lib/modem/src/mod.c b/srslte/lib/modem/src/mod.c index f282c9f5f..b097f0ec7 100644 --- a/srslte/lib/modem/src/mod.c +++ b/srslte/lib/modem/src/mod.c @@ -52,52 +52,99 @@ int srslte_mod_modulate(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, u return j; } -/* Assumes packet bits as input */ -int srslte_mod_modulate_bytes(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, uint32_t nbits) { - if (nbits%8) { - fprintf(stderr, "Warning: srslte_mod_modulate_bytes() accepts byte-aligned inputs only " - "(nbits=%d, bits_x_symbol=%d)\n", nbits, q->nbits_x_symbol); +void mod_bpsk_bytes(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, uint32_t nbits) { + uint8_t mask_bpsk[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; + uint8_t shift_bpsk[8] = {7, 6, 5, 4, 3, 2, 1, 0}; + + for (int i=0;isymbol_table_bpsk[bits[i]], sizeof(bpsk_packed_t)); + } + for (int i=0;isymbol_table[(bits[8*(nbits/8)+i]&mask_bpsk[i])>>shift_bpsk[i]]; + } +} + +void mod_qpsk_bytes(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, uint32_t nbits) { + uint8_t mask_qpsk[4] = {0xc0, 0x30, 0x0c, 0x03}; + uint8_t shift_qpsk[4] = {6, 4, 2, 0}; + for (int i=0;isymbol_table_qpsk[bits[i]], sizeof(qpsk_packed_t)); + } + for (int i=0;i<(nbits%8)/2;i++) { + symbols[8*(nbits/8)+i] = q->symbol_table[(bits[8*(nbits/8)]&mask_qpsk[i])>>shift_qpsk[i]]; + } +} + +void mod_16qam_bytes(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, uint32_t nbits) { + for (int i=0;isymbol_table_16qam[bits[i]], sizeof(qam16_packed_t)); + } + symbols[8*(nbits/8)] = q->symbol_table[(bits[8*(nbits/8)]&0xf0)>>4]; +} + +void mod_64qam_bytes(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, uint32_t nbits) { + uint8_t in0, in1, in2, in3; + uint32_t in80, in81, in82; + + for (int i=0;i>2; + in1 = (in80&0x03)<<4 | ((in81&0xf0)>>4); + in2 = (in81&0x0f)<<2 | ((in82&0xc0)>>6); + in3 = in82&0x3f; + + symbols[i*4+0] = q->symbol_table[in0]; + symbols[i*4+1] = q->symbol_table[in1]; + symbols[i*4+2] = q->symbol_table[in2]; + symbols[i*4+3] = q->symbol_table[in3]; + } + if (nbits%24 >= 6) { + in80 = bits[24*(nbits/24)+0]; + in0 = (in80&0xfc)>>2; + + symbols[24*(nbits/24)+0] = q->symbol_table[in0]; + } + if (nbits%24 >= 12) { + in81 = bits[24*(nbits/24)+1]; + in1 = (in80&0x03)<<4 | ((in81&0xf0)>>4); + + symbols[24*(nbits/24)+1] = q->symbol_table[in1]; } + if (nbits%24 >= 18) { + in82 = bits[24*(nbits/24)+2]; + in2 = (in81&0x0f)<<2 | ((in82&0xc0)>>6); + + symbols[24*(nbits/24)+2] = q->symbol_table[in2]; + } +} + +/* Assumes packet bits as input */ +int srslte_mod_modulate_bytes(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, uint32_t nbits) +{ + if (!q->byte_tables_init) { fprintf(stderr, "Error need to initiated modem tables for packeted bits before calling srslte_mod_modulate_bytes()\n"); return -1; } + if (nbits % q->nbits_x_symbol) { + fprintf(stderr, "Error modulator expects number of bits (%d) to be multiple of %d\n", nbits, q->nbits_x_symbol); + return -1; + } switch(q->nbits_x_symbol) { case 1: - for (int i=0;isymbol_table_bpsk[bits[i]], sizeof(bpsk_packed_t)); - } + mod_bpsk_bytes(q, bits, symbols, nbits); break; case 2: - for (int i=0;isymbol_table_qpsk[bits[i]], sizeof(qpsk_packed_t)); - } + mod_qpsk_bytes(q, bits, symbols, nbits); break; case 4: - for (int i=0;isymbol_table_16qam[bits[i]], sizeof(qam16_packed_t)); - } + mod_16qam_bytes(q, bits, symbols, nbits); break; case 6: - if (nbits%24) { - fprintf(stderr, "Warning: for 64QAM srslte_mod_modulate_bytes() accepts 24-bit aligned inputs only\n"); - } - - for (int i=0;i>2; - uint8_t in1 = (in80&0x03)<<4 | ((in81&0xf0)>>4); - uint8_t in2 = (in81&0x0f)<<2 | ((in82&0xc0)>>6); - uint8_t in3 = in82&0x3f; - - symbols[i*4+0] = q->symbol_table[in0]; - symbols[i*4+1] = q->symbol_table[in1]; - symbols[i*4+2] = q->symbol_table[in2]; - symbols[i*4+3] = q->symbol_table[in3]; - } + mod_64qam_bytes(q, bits, symbols, nbits); break; default: fprintf(stderr, "srslte_mod_modulate_bytes() accepts QPSK/16QAM/64QAM modulations only\n");