Refactored decode_tb function

master
Xavier Arteaga 3 years ago committed by Xavier Arteaga
parent 22b1673b36
commit 49d857cd17

@ -504,72 +504,61 @@ static int decode_tb(srsran_sch_t* q,
int16_t* e_bits,
uint8_t* data)
{
if (q != NULL && data != NULL && softbuffer != NULL && e_bits != NULL && cb_segm != NULL && Qm != 0) {
if (cb_segm->tbs == 0 || cb_segm->C == 0) {
return SRSRAN_SUCCESS;
}
if (cb_segm->F) {
fprintf(stderr, "Error filler bits are not supported. Use standard TBS\n");
return SRSRAN_ERROR_INVALID_INPUTS;
}
// Check inputs
if (q == NULL || data == NULL || softbuffer == NULL || e_bits == NULL || cb_segm == NULL || Qm == 0) {
ERROR("Missing inputs: data=%d, softbuffer=%d, e_bits=%d, cb_segm=%d Qm=%d",
data != 0,
softbuffer != 0,
e_bits != 0,
cb_segm != 0,
Qm);
return SRSRAN_ERROR_INVALID_INPUTS;
}
if (cb_segm->C > softbuffer->max_cb) {
fprintf(stderr,
"Error number of CB to decode (%d) exceeds soft buffer size (%d CBs)\n",
cb_segm->C,
softbuffer->max_cb);
return SRSRAN_ERROR_INVALID_INPUTS;
}
// Check segmentation is valid
if (cb_segm->tbs == 0 || cb_segm->C == 0) {
return SRSRAN_SUCCESS;
}
bool crc_ok = true;
if (cb_segm->F) {
fprintf(stderr, "Error filler bits are not supported. Use standard TBS\n");
return SRSRAN_ERROR_INVALID_INPUTS;
}
data[cb_segm->tbs / 8 + 0] = 0;
data[cb_segm->tbs / 8 + 1] = 0;
data[cb_segm->tbs / 8 + 2] = 0;
if (cb_segm->C > softbuffer->max_cb) {
fprintf(stderr,
"Error number of CB to decode (%d) exceeds soft buffer size (%d CBs)\n",
cb_segm->C,
softbuffer->max_cb);
return SRSRAN_ERROR_INVALID_INPUTS;
}
// Process Codeblocks
crc_ok = decode_tb_cb(q, softbuffer, cb_segm, Qm, rv, nof_e_bits, e_bits, data);
// Process Codeblocks
bool cb_crc_ok = decode_tb_cb(q, softbuffer, cb_segm, Qm, rv, nof_e_bits, e_bits, data);
if (crc_ok) {
uint32_t par_rx = 0, par_tx = 0;
// If any of the CBs CRC is KO
if (!cb_crc_ok) {
INFO("Error in CB parity");
return SRSRAN_ERROR;
}
// Compute transport block CRC
par_rx = srsran_crc_checksum_byte(&q->crc_tb, data, cb_segm->tbs);
// One CB CRC OK, means TB CRC is OK.
if (cb_segm->C == 1) {
INFO("TB decoded OK");
return SRSRAN_SUCCESS;
}
// check parity bits
par_tx = ((uint32_t)data[cb_segm->tbs / 8 + 0]) << 16 | ((uint32_t)data[cb_segm->tbs / 8 + 1]) << 8 |
((uint32_t)data[cb_segm->tbs / 8 + 2]);
// Check TB CRC for whole TB
if (srsran_crc_match_byte(&q->crc_tb, data, cb_segm->tbs)) {
INFO("TB decoded OK");
return SRSRAN_SUCCESS;
}
// Check if all the bytes are zeros
bool all_zeros = true;
for (uint32_t i = 0; i < cb_segm->tbs / 8 && all_zeros; i++) {
all_zeros = (data[i] == 0);
}
if (all_zeros) {
INFO("Error in TB decode: it is all zeros!");
return SRSRAN_ERROR;
}
// TB CRC check failed, as at least one CB had a false alarm, reset all CB CRC flags in the softbuffer
srsran_softbuffer_rx_reset_cb_crc(softbuffer, cb_segm->C);
if (par_rx == par_tx) {
INFO("TB decoded OK");
return SRSRAN_SUCCESS;
} else {
INFO("Error in TB parity: par_tx=0x%x, par_rx=0x%x", par_tx, par_rx);
return SRSRAN_ERROR;
}
} else {
return SRSRAN_ERROR;
}
} else {
ERROR("Missing inputs: data=%d, softbuffer=%d, e_bits=%d, cb_segm=%d Qm=%d",
data != 0,
softbuffer != 0,
e_bits != 0,
cb_segm != 0,
Qm);
return SRSRAN_ERROR_INVALID_INPUTS;
}
INFO("Error in TB parity");
return SRSRAN_ERROR;
}
int srsran_dlsch_decode(srsran_sch_t* q, srsran_pdsch_cfg_t* cfg, int16_t* e_bits, uint8_t* data)

Loading…
Cancel
Save