|
|
@ -40,8 +40,10 @@
|
|
|
|
#include "srslte/fec/rm_conv.h"
|
|
|
|
#include "srslte/fec/rm_conv.h"
|
|
|
|
#include "srslte/common/phy_common.h"
|
|
|
|
#include "srslte/common/phy_common.h"
|
|
|
|
#include "srslte/utils/vector.h"
|
|
|
|
#include "srslte/utils/vector.h"
|
|
|
|
|
|
|
|
#include "srslte/utils/bit.h"
|
|
|
|
#include "srslte/utils/debug.h"
|
|
|
|
#include "srslte/utils/debug.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Table 5.2.2.6.4-1: Basis sequence for (32, O) code */
|
|
|
|
/* Table 5.2.2.6.4-1: Basis sequence for (32, O) code */
|
|
|
|
static uint8_t M_basis_seq[32][11]={
|
|
|
|
static uint8_t M_basis_seq[32][11]={
|
|
|
|
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
@ -102,15 +104,64 @@ static uint8_t M_basis_seq_pucch[20][13]={
|
|
|
|
{1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0},
|
|
|
|
{1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void encode_cqi_pusch_block(srslte_uci_cqi_pusch_t *q, uint8_t *data, uint32_t nof_bits, uint8_t output[32]) {
|
|
|
|
|
|
|
|
for (int i=0;i<32;i++) {
|
|
|
|
|
|
|
|
output[i] = 0;
|
|
|
|
|
|
|
|
for (int n=0;n<nof_bits;n++) {
|
|
|
|
|
|
|
|
output[i] = (output[i] + data[n] * M_basis_seq[i][n])%2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cqi_pusch_pregen(srslte_uci_cqi_pusch_t *q) {
|
|
|
|
|
|
|
|
uint8_t word[11];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<11;i++) {
|
|
|
|
|
|
|
|
uint32_t nwords = (1<<(i+1));
|
|
|
|
|
|
|
|
q->cqi_table[i] = srslte_vec_malloc(sizeof(uint8_t)*nwords*32);
|
|
|
|
|
|
|
|
q->cqi_table_s[i] = srslte_vec_malloc(sizeof(int16_t)*nwords*32);
|
|
|
|
|
|
|
|
for (uint32_t w=0;w<nwords;w++) {
|
|
|
|
|
|
|
|
uint8_t *ptr = word;
|
|
|
|
|
|
|
|
srslte_bit_unpack(w, &ptr, i);
|
|
|
|
|
|
|
|
encode_cqi_pusch_block(q, word, i, &q->cqi_table[i][32*w]);
|
|
|
|
|
|
|
|
for (int j=0;j<32;j++) {
|
|
|
|
|
|
|
|
q->cqi_table_s[i][32*w+j] = 2*q->cqi_table[i][32*w+j]-1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cqi_pusch_pregen_free(srslte_uci_cqi_pusch_t *q) {
|
|
|
|
|
|
|
|
for (int i=0;i<11;i++) {
|
|
|
|
|
|
|
|
if (q->cqi_table[i]) {
|
|
|
|
|
|
|
|
free(q->cqi_table[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (q->cqi_table_s[i]) {
|
|
|
|
|
|
|
|
free(q->cqi_table_s[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int srslte_uci_cqi_init(srslte_uci_cqi_pusch_t *q) {
|
|
|
|
int srslte_uci_cqi_init(srslte_uci_cqi_pusch_t *q) {
|
|
|
|
if (srslte_crc_init(&q->crc, SRSLTE_LTE_CRC8, 8)) {
|
|
|
|
if (srslte_crc_init(&q->crc, SRSLTE_LTE_CRC8, 8)) {
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t poly[3] = { 0x6D, 0x4F, 0x57 };
|
|
|
|
|
|
|
|
if (srslte_viterbi_init(&q->viterbi, SRSLTE_VITERBI_37, poly, SRSLTE_UCI_MAX_CQI_LEN_PUSCH, true)) {
|
|
|
|
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cqi_pusch_pregen(q);
|
|
|
|
|
|
|
|
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_uci_cqi_free(srslte_uci_cqi_pusch_t *q) {
|
|
|
|
void srslte_uci_cqi_free(srslte_uci_cqi_pusch_t *q)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
srslte_viterbi_free(&q->viterbi);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cqi_pusch_pregen_free(q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t Q_prime_cqi(srslte_pusch_cfg_t *cfg,
|
|
|
|
static uint32_t Q_prime_cqi(srslte_pusch_cfg_t *cfg,
|
|
|
@ -136,21 +187,58 @@ static uint32_t Q_prime_cqi(srslte_pusch_cfg_t *cfg,
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int encode_cqi_short(srslte_uci_cqi_pusch_t *q, uint8_t *data, uint32_t nof_bits, uint8_t *q_bits, uint32_t Q)
|
|
|
|
int encode_cqi_short(srslte_uci_cqi_pusch_t *q, uint8_t *data, uint32_t nof_bits, uint8_t *q_bits, uint32_t Q)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (nof_bits < SRSLTE_UCI_MAX_CQI_LEN_PUSCH &&
|
|
|
|
if (nof_bits <= 11 &&
|
|
|
|
q != NULL &&
|
|
|
|
nof_bits > 0 &&
|
|
|
|
data != NULL &&
|
|
|
|
q != NULL &&
|
|
|
|
|
|
|
|
data != NULL &&
|
|
|
|
|
|
|
|
q_bits != NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint8_t *ptr = data;
|
|
|
|
|
|
|
|
uint32_t w = srslte_bit_pack(&ptr, nof_bits);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<Q;i++) {
|
|
|
|
|
|
|
|
q_bits[i] = q->cqi_table[nof_bits-1][w*32+(i%32)];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For decoding the block-encoded CQI we use ML decoding
|
|
|
|
|
|
|
|
int decode_cqi_short(srslte_uci_cqi_pusch_t *q, int16_t *q_bits, uint32_t Q, uint8_t *data, uint32_t nof_bits)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (nof_bits <= 11 &&
|
|
|
|
|
|
|
|
nof_bits > 0 &&
|
|
|
|
|
|
|
|
q != NULL &&
|
|
|
|
|
|
|
|
data != NULL &&
|
|
|
|
q_bits != NULL)
|
|
|
|
q_bits != NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int i=0;i<32;i++) {
|
|
|
|
// Accumulate all copies of the 32-length sequence
|
|
|
|
q->encoded_cqi[i] = 0;
|
|
|
|
if (Q>32) {
|
|
|
|
for (int n=0;n<nof_bits;n++) {
|
|
|
|
int i=1;
|
|
|
|
q->encoded_cqi[i] += (data[n] * M_basis_seq[i][n]);
|
|
|
|
for (;i<Q/32;i++) {
|
|
|
|
|
|
|
|
srslte_vec_sum_sss(&q_bits[i*32], q_bits, q_bits, 32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
srslte_vec_sum_sss(&q_bits[i*32], q_bits, q_bits, Q%32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<Q;i++) {
|
|
|
|
uint32_t max_w = 0;
|
|
|
|
q_bits[i] = q->encoded_cqi[i%32]%2;
|
|
|
|
int32_t max_corr = INT32_MIN;
|
|
|
|
|
|
|
|
for (uint32_t w=0;w<(1<<nof_bits);w++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate correlation with pregenerated word and select maximum
|
|
|
|
|
|
|
|
int32_t corr = srslte_vec_dot_prod_sss(&q->cqi_table_s[nof_bits-1][w*32], q_bits, 32);
|
|
|
|
|
|
|
|
if (corr > max_corr) {
|
|
|
|
|
|
|
|
max_corr = corr;
|
|
|
|
|
|
|
|
max_w = w;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert word to bits again
|
|
|
|
|
|
|
|
uint8_t *ptr = data;
|
|
|
|
|
|
|
|
srslte_bit_unpack(max_w, &ptr, nof_bits);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INFO("Decoded CQI: w=%d, corr=%d\n", max_w, max_corr);
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
|
|
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
|
|
@ -168,8 +256,6 @@ int encode_cqi_long(srslte_uci_cqi_pusch_t *q, uint8_t *data, uint32_t nof_bits,
|
|
|
|
data != NULL &&
|
|
|
|
data != NULL &&
|
|
|
|
q_bits != NULL)
|
|
|
|
q_bits != NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int poly[3] = { 0x6D, 0x4F, 0x57 };
|
|
|
|
int poly[3] = { 0x6D, 0x4F, 0x57 };
|
|
|
|
encoder.K = 7;
|
|
|
|
encoder.K = 7;
|
|
|
|
encoder.R = 3;
|
|
|
|
encoder.R = 3;
|
|
|
@ -179,10 +265,14 @@ int encode_cqi_long(srslte_uci_cqi_pusch_t *q, uint8_t *data, uint32_t nof_bits,
|
|
|
|
memcpy(q->tmp_cqi, data, sizeof(uint8_t) * nof_bits);
|
|
|
|
memcpy(q->tmp_cqi, data, sizeof(uint8_t) * nof_bits);
|
|
|
|
srslte_crc_attach(&q->crc, q->tmp_cqi, nof_bits);
|
|
|
|
srslte_crc_attach(&q->crc, q->tmp_cqi, nof_bits);
|
|
|
|
|
|
|
|
|
|
|
|
srslte_convcoder_encode(&encoder, q->tmp_cqi, q->encoded_cqi, nof_bits + 8);
|
|
|
|
DEBUG("cqi_crc_tx=", 0);
|
|
|
|
|
|
|
|
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
|
|
|
|
|
|
|
srslte_vec_fprint_b(stdout, q->tmp_cqi, nof_bits+8);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG("CConv output: ", 0);
|
|
|
|
srslte_convcoder_encode(&encoder, q->tmp_cqi, q->encoded_cqi, nof_bits + 8);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG("cconv_tx=", 0);
|
|
|
|
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
|
|
|
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
|
|
|
srslte_vec_fprint_b(stdout, q->encoded_cqi, 3 * (nof_bits + 8));
|
|
|
|
srslte_vec_fprint_b(stdout, q->encoded_cqi, 3 * (nof_bits + 8));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -195,6 +285,45 @@ int encode_cqi_long(srslte_uci_cqi_pusch_t *q, uint8_t *data, uint32_t nof_bits,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int decode_cqi_long(srslte_uci_cqi_pusch_t *q, int16_t *q_bits, uint32_t Q,
|
|
|
|
|
|
|
|
uint8_t *data, uint32_t nof_bits)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
|
|
|
|
|
|
|
if (nof_bits + 8 < SRSLTE_UCI_MAX_CQI_LEN_PUSCH &&
|
|
|
|
|
|
|
|
q != NULL &&
|
|
|
|
|
|
|
|
data != NULL &&
|
|
|
|
|
|
|
|
q_bits != NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
srslte_rm_conv_rx_s(q_bits, Q, q->encoded_cqi_s, 3 * (nof_bits + 8));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set viterbi normalization based on amplitude
|
|
|
|
|
|
|
|
int16_t max = srslte_vec_max_star_si(q->encoded_cqi_s, 3 * (nof_bits + 8));
|
|
|
|
|
|
|
|
srslte_viterbi_set_gain_quant_s(&q->viterbi, max/36);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG("cconv_rx=", 0);
|
|
|
|
|
|
|
|
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
|
|
|
|
|
|
|
srslte_vec_fprint_s(stdout, q->encoded_cqi_s, 3 * (nof_bits + 8));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
srslte_viterbi_decode_s(&q->viterbi, q->encoded_cqi_s, q->tmp_cqi, nof_bits + 8);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG("cqi_crc_rx=", 0);
|
|
|
|
|
|
|
|
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
|
|
|
|
|
|
|
srslte_vec_fprint_b(stdout, q->tmp_cqi, nof_bits+8);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ret = srslte_crc_checksum(&q->crc, q->tmp_cqi, nof_bits + 8);
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
|
|
|
|
memcpy(data, q->tmp_cqi, nof_bits*sizeof(uint8_t));
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Encode UCI CQI/PMI as described in 5.2.3.3 of 36.212
|
|
|
|
/* Encode UCI CQI/PMI as described in 5.2.3.3 of 36.212
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int srslte_uci_encode_cqi_pucch(uint8_t *cqi_data, uint32_t cqi_len, uint8_t b_bits[SRSLTE_UCI_CQI_CODED_PUCCH_B])
|
|
|
|
int srslte_uci_encode_cqi_pucch(uint8_t *cqi_data, uint32_t cqi_len, uint8_t b_bits[SRSLTE_UCI_CQI_CODED_PUCCH_B])
|
|
|
@ -213,6 +342,44 @@ int srslte_uci_encode_cqi_pucch(uint8_t *cqi_data, uint32_t cqi_len, uint8_t b_b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Encode UCI CQI/PMI
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int srslte_uci_decode_cqi_pusch(srslte_uci_cqi_pusch_t *q, srslte_pusch_cfg_t *cfg,
|
|
|
|
|
|
|
|
int16_t *q_bits,
|
|
|
|
|
|
|
|
float beta, uint32_t Q_prime_ri, uint32_t cqi_len,
|
|
|
|
|
|
|
|
uint8_t *cqi_data, bool *cqi_ack)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (beta < 0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error beta is reserved\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Q_prime = Q_prime_cqi(cfg, cqi_len, beta, Q_prime_ri);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ret = SRSLTE_ERROR;
|
|
|
|
|
|
|
|
if (cqi_len <= 11) {
|
|
|
|
|
|
|
|
ret = decode_cqi_short(q, q_bits, Q_prime*cfg->grant.Qm, cqi_data, cqi_len);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ret = decode_cqi_long(q, q_bits, Q_prime*cfg->grant.Qm, cqi_data, cqi_len);
|
|
|
|
|
|
|
|
if (ret == 1) {
|
|
|
|
|
|
|
|
if (cqi_ack) {
|
|
|
|
|
|
|
|
*cqi_ack = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
} else if (ret == 0) {
|
|
|
|
|
|
|
|
if (cqi_ack) {
|
|
|
|
|
|
|
|
*cqi_ack = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return (int) Q_prime;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Q_prime;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Encode UCI CQI/PMI as described in 5.2.2.6 of 36.212
|
|
|
|
/* Encode UCI CQI/PMI as described in 5.2.2.6 of 36.212
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int srslte_uci_encode_cqi_pusch(srslte_uci_cqi_pusch_t *q, srslte_pusch_cfg_t *cfg,
|
|
|
|
int srslte_uci_encode_cqi_pusch(srslte_uci_cqi_pusch_t *q, srslte_pusch_cfg_t *cfg,
|
|
|
@ -240,22 +407,28 @@ int srslte_uci_encode_cqi_pusch(srslte_uci_cqi_pusch_t *q, srslte_pusch_cfg_t *c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void uci_ulsch_interleave_put(srslte_uci_bit_type_t ack_coded_bits[6], uint32_t Qm, srslte_uci_bit_t *ack_bits)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for(uint32_t k=0; k<Qm; k++) {
|
|
|
|
|
|
|
|
ack_bits[k].type = ack_coded_bits[k];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Generates UCI-ACK bits and computes position in q bits */
|
|
|
|
/* Generates UCI-ACK bits and computes position in q bits */
|
|
|
|
static int uci_ulsch_interleave_ack(srslte_uci_bit_type_t ack_coded_bits[6], uint32_t ack_q_bit_idx,
|
|
|
|
static int uci_ulsch_interleave_ack_gen(uint32_t ack_q_bit_idx,
|
|
|
|
uint32_t Qm, uint32_t H_prime_total, uint32_t N_pusch_symbs, srslte_cp_t cp,
|
|
|
|
uint32_t Qm, uint32_t H_prime_total, uint32_t N_pusch_symbs, srslte_cp_t cp,
|
|
|
|
srslte_uci_bit_t *ack_bits) {
|
|
|
|
srslte_uci_bit_t *ack_bits)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
const uint32_t ack_column_set_norm[4] = {2, 3, 8, 9};
|
|
|
|
const uint32_t ack_column_set_norm[4] = {2, 3, 8, 9};
|
|
|
|
const uint32_t ack_column_set_ext[4] = {1, 2, 6, 7};
|
|
|
|
const uint32_t ack_column_set_ext[4] = {1, 2, 6, 7};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (H_prime_total/N_pusch_symbs >= 1+ack_q_bit_idx/4) {
|
|
|
|
if (H_prime_total/N_pusch_symbs >= 1+ack_q_bit_idx/4) {
|
|
|
|
uint32_t row = H_prime_total/N_pusch_symbs-1-ack_q_bit_idx/4;
|
|
|
|
uint32_t row = H_prime_total/N_pusch_symbs-1-ack_q_bit_idx/4;
|
|
|
|
uint32_t colidx = (3*ack_q_bit_idx)%4;
|
|
|
|
uint32_t colidx = (3*ack_q_bit_idx)%4;
|
|
|
|
uint32_t col = SRSLTE_CP_ISNORM(cp)?ack_column_set_norm[colidx]:ack_column_set_ext[colidx];
|
|
|
|
uint32_t col = SRSLTE_CP_ISNORM(cp)?ack_column_set_norm[colidx]:ack_column_set_ext[colidx];
|
|
|
|
for(uint32_t k=0; k<Qm; k++) {
|
|
|
|
for(uint32_t k=0; k<Qm; k++) {
|
|
|
|
ack_bits[k].position = row *Qm + (H_prime_total/N_pusch_symbs)*col*Qm + k;
|
|
|
|
ack_bits[k].position = row *Qm + (H_prime_total/N_pusch_symbs)*col*Qm + k;
|
|
|
|
ack_bits[k].type = ack_coded_bits[k];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -266,9 +439,10 @@ static int uci_ulsch_interleave_ack(srslte_uci_bit_type_t ack_coded_bits[6], uin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Inserts UCI-RI bits into the correct positions in the g buffer before interleaving */
|
|
|
|
/* Inserts UCI-RI bits into the correct positions in the g buffer before interleaving */
|
|
|
|
static int uci_ulsch_interleave_ri(srslte_uci_bit_type_t ri_coded_bits[6], uint32_t ri_q_bit_idx,
|
|
|
|
static int uci_ulsch_interleave_ri_gen(uint32_t ri_q_bit_idx,
|
|
|
|
uint32_t Qm, uint32_t H_prime_total, uint32_t N_pusch_symbs, srslte_cp_t cp,
|
|
|
|
uint32_t Qm, uint32_t H_prime_total, uint32_t N_pusch_symbs, srslte_cp_t cp,
|
|
|
|
srslte_uci_bit_t *ri_bits) {
|
|
|
|
srslte_uci_bit_t *ri_bits)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t ri_column_set_norm[4] = {1, 4, 7, 10};
|
|
|
|
static uint32_t ri_column_set_norm[4] = {1, 4, 7, 10};
|
|
|
|
static uint32_t ri_column_set_ext[4] = {0, 3, 5, 8};
|
|
|
|
static uint32_t ri_column_set_ext[4] = {0, 3, 5, 8};
|
|
|
@ -280,7 +454,6 @@ static int uci_ulsch_interleave_ri(srslte_uci_bit_type_t ri_coded_bits[6], uint3
|
|
|
|
|
|
|
|
|
|
|
|
for(uint32_t k=0; k<Qm; k++) {
|
|
|
|
for(uint32_t k=0; k<Qm; k++) {
|
|
|
|
ri_bits[k].position = row *Qm + (H_prime_total/N_pusch_symbs)*col*Qm + k;
|
|
|
|
ri_bits[k].position = row *Qm + (H_prime_total/N_pusch_symbs)*col*Qm + k;
|
|
|
|
ri_bits[k].type = ri_coded_bits[k];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -317,7 +490,8 @@ static uint32_t Q_prime_ri_ack(srslte_pusch_cfg_t *cfg,
|
|
|
|
return Q_prime;
|
|
|
|
return Q_prime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void encode_ri_ack(uint8_t data, srslte_uci_bit_type_t q_encoded_bits[6], uint8_t Qm) {
|
|
|
|
static void encode_ri_ack(uint8_t data, srslte_uci_bit_type_t q_encoded_bits[6], uint8_t Qm)
|
|
|
|
|
|
|
|
{
|
|
|
|
q_encoded_bits[0] = data?UCI_BIT_1:UCI_BIT_0;
|
|
|
|
q_encoded_bits[0] = data?UCI_BIT_1:UCI_BIT_0;
|
|
|
|
q_encoded_bits[1] = UCI_BIT_REPETITION;
|
|
|
|
q_encoded_bits[1] = UCI_BIT_REPETITION;
|
|
|
|
for (uint32_t i=2;i<Qm;i++) {
|
|
|
|
for (uint32_t i=2;i<Qm;i++) {
|
|
|
@ -325,6 +499,46 @@ static void encode_ri_ack(uint8_t data, srslte_uci_bit_type_t q_encoded_bits[6],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int32_t decode_ri_ack(int16_t *q_bits, uint8_t *c_seq, srslte_uci_bit_t *pos)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t p0 = pos[0].position;
|
|
|
|
|
|
|
|
uint32_t p1 = pos[1].position;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t q0 = c_seq[p0]?q_bits[p0]:-q_bits[p0];
|
|
|
|
|
|
|
|
uint32_t q1 = c_seq[p0]?q_bits[p1]:-q_bits[p1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return -(q0+q1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Decode UCI HARQ/ACK bits as described in 5.2.2.6 of 36.212
|
|
|
|
|
|
|
|
* Currently only supporting 1-bit HARQ
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int srslte_uci_decode_ack(srslte_pusch_cfg_t *cfg, int16_t *q_bits, uint8_t *c_seq,
|
|
|
|
|
|
|
|
float beta, uint32_t H_prime_total,
|
|
|
|
|
|
|
|
uint32_t O_cqi, srslte_uci_bit_t *ack_bits, uint8_t *data)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int32_t rx_ack = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (beta < 0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error beta is reserved\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t Qprime = Q_prime_ri_ack(cfg, 1, O_cqi, beta);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Use the same interleaver function to get the HARQ bit position
|
|
|
|
|
|
|
|
for (uint32_t i=0;i<Qprime;i++) {
|
|
|
|
|
|
|
|
uci_ulsch_interleave_ack_gen(i, cfg->grant.Qm, H_prime_total, cfg->nbits.nof_symb, cfg->cp, &ack_bits[cfg->grant.Qm*i]);
|
|
|
|
|
|
|
|
rx_ack += (int32_t) decode_ri_ack(q_bits, c_seq, ack_bits);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
|
|
|
|
*data = rx_ack>0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int) Qprime;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Encode UCI HARQ/ACK bits as described in 5.2.2.6 of 36.212
|
|
|
|
/* Encode UCI HARQ/ACK bits as described in 5.2.2.6 of 36.212
|
|
|
|
* Currently only supporting 1-bit HARQ
|
|
|
|
* Currently only supporting 1-bit HARQ
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -343,7 +557,37 @@ int srslte_uci_encode_ack(srslte_pusch_cfg_t *cfg, uint8_t data,
|
|
|
|
encode_ri_ack(data, q_encoded_bits, cfg->grant.Qm);
|
|
|
|
encode_ri_ack(data, q_encoded_bits, cfg->grant.Qm);
|
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t i=0;i<Qprime;i++) {
|
|
|
|
for (uint32_t i=0;i<Qprime;i++) {
|
|
|
|
uci_ulsch_interleave_ack(q_encoded_bits, i, cfg->grant.Qm, H_prime_total, cfg->nbits.nof_symb, cfg->cp, &ack_bits[cfg->grant.Qm*i]);
|
|
|
|
uci_ulsch_interleave_ack_gen(i, cfg->grant.Qm, H_prime_total, cfg->nbits.nof_symb, cfg->cp, &ack_bits[cfg->grant.Qm*i]);
|
|
|
|
|
|
|
|
uci_ulsch_interleave_put(q_encoded_bits, cfg->grant.Qm, &ack_bits[cfg->grant.Qm*i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (int) Qprime;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Encode UCI RI bits as described in 5.2.2.6 of 36.212
|
|
|
|
|
|
|
|
* Currently only supporting 1-bit RI
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int srslte_uci_decode_ri(srslte_pusch_cfg_t *cfg, int16_t *q_bits, uint8_t *c_seq,
|
|
|
|
|
|
|
|
float beta, uint32_t H_prime_total,
|
|
|
|
|
|
|
|
uint32_t O_cqi, srslte_uci_bit_t *ri_bits, uint8_t *data)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int32_t rx_ri = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (beta < 0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error beta is reserved\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t Qprime = Q_prime_ri_ack(cfg, 1, O_cqi, beta);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Use the same interleaver function to get the HARQ bit position
|
|
|
|
|
|
|
|
for (uint32_t i=0;i<Qprime;i++) {
|
|
|
|
|
|
|
|
uci_ulsch_interleave_ri_gen(i, cfg->grant.Qm, H_prime_total, cfg->nbits.nof_symb, cfg->cp, &ri_bits[cfg->grant.Qm*i]);
|
|
|
|
|
|
|
|
rx_ri += (int32_t) decode_ri_ack(q_bits, c_seq, ri_bits);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
|
|
|
|
*data = rx_ri>0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (int) Qprime;
|
|
|
|
return (int) Qprime;
|
|
|
@ -368,7 +612,8 @@ int srslte_uci_encode_ri(srslte_pusch_cfg_t *cfg,
|
|
|
|
encode_ri_ack(data, q_encoded_bits, cfg->grant.Qm);
|
|
|
|
encode_ri_ack(data, q_encoded_bits, cfg->grant.Qm);
|
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t i=0;i<Qprime;i++) {
|
|
|
|
for (uint32_t i=0;i<Qprime;i++) {
|
|
|
|
uci_ulsch_interleave_ri(q_encoded_bits, i, cfg->grant.Qm, H_prime_total, cfg->nbits.nof_symb, cfg->cp, &ri_bits[cfg->grant.Qm*i]);
|
|
|
|
uci_ulsch_interleave_ri_gen(i, cfg->grant.Qm, H_prime_total, cfg->nbits.nof_symb, cfg->cp, &ri_bits[cfg->grant.Qm*i]);
|
|
|
|
|
|
|
|
uci_ulsch_interleave_put(q_encoded_bits, cfg->grant.Qm, &ri_bits[cfg->grant.Qm*i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (int) Qprime;
|
|
|
|
return (int) Qprime;
|
|
|
|