Refactored decode_tb function

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

@ -504,7 +504,18 @@ static int decode_tb(srsran_sch_t* q,
int16_t* e_bits, int16_t* e_bits,
uint8_t* data) uint8_t* data)
{ {
if (q != NULL && data != NULL && softbuffer != NULL && e_bits != NULL && cb_segm != NULL && Qm != 0) { // 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;
}
// Check segmentation is valid
if (cb_segm->tbs == 0 || cb_segm->C == 0) { if (cb_segm->tbs == 0 || cb_segm->C == 0) {
return SRSRAN_SUCCESS; return SRSRAN_SUCCESS;
} }
@ -522,54 +533,32 @@ static int decode_tb(srsran_sch_t* q,
return SRSRAN_ERROR_INVALID_INPUTS; return SRSRAN_ERROR_INVALID_INPUTS;
} }
bool crc_ok = true;
data[cb_segm->tbs / 8 + 0] = 0;
data[cb_segm->tbs / 8 + 1] = 0;
data[cb_segm->tbs / 8 + 2] = 0;
// Process Codeblocks // Process Codeblocks
crc_ok = decode_tb_cb(q, softbuffer, cb_segm, Qm, rv, nof_e_bits, e_bits, data); 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;
// Compute transport block CRC
par_rx = srsran_crc_checksum_byte(&q->crc_tb, data, cb_segm->tbs);
// check parity bits // If any of the CBs CRC is KO
par_tx = ((uint32_t)data[cb_segm->tbs / 8 + 0]) << 16 | ((uint32_t)data[cb_segm->tbs / 8 + 1]) << 8 | if (!cb_crc_ok) {
((uint32_t)data[cb_segm->tbs / 8 + 2]); INFO("Error in CB parity");
// 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; return SRSRAN_ERROR;
} }
if (par_rx == par_tx) { // One CB CRC OK, means TB CRC is OK.
if (cb_segm->C == 1) {
INFO("TB decoded OK"); INFO("TB decoded OK");
return SRSRAN_SUCCESS; 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; // Check TB CRC for whole TB
} if (srsran_crc_match_byte(&q->crc_tb, data, cb_segm->tbs)) {
} else { INFO("TB decoded OK");
ERROR("Missing inputs: data=%d, softbuffer=%d, e_bits=%d, cb_segm=%d Qm=%d", return SRSRAN_SUCCESS;
data != 0,
softbuffer != 0,
e_bits != 0,
cb_segm != 0,
Qm);
return SRSRAN_ERROR_INVALID_INPUTS;
} }
// 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);
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) int srsran_dlsch_decode(srsran_sch_t* q, srsran_pdsch_cfg_t* cfg, int16_t* e_bits, uint8_t* data)

Loading…
Cancel
Save