compute_tbs_common formatting

This commit is contained in:
francescomani
2025-02-04 08:21:11 +01:00
parent d791d03e05
commit fc52fb8d24
@@ -66,10 +66,8 @@ uint32_t nr_compute_tbs(uint16_t Qm,
const uint32_t R_5 = R / 5; // R can be fractional so we can't divide by 10 const uint32_t R_5 = R / 5; // R can be fractional so we can't divide by 10
// So we ned to right shift by 11 (10 for x1024 and 1 additional as above) // So we ned to right shift by 11 (10 for x1024 and 1 additional as above)
const uint32_t Ninfo = ((nb_re * R_5 * Qm * Nl) >> 11) >> tb_scaling; const uint32_t Ninfo = ((nb_re * R_5 * Qm * Nl) >> 11) >> tb_scaling;
uint32_t nr_tbs = 0; uint32_t nr_tbs = 0;
uint32_t Np_info, C, n; uint32_t Np_info, C, n;
if (Ninfo <= NR_MAX_PDSCH_TBS) { if (Ninfo <= NR_MAX_PDSCH_TBS) {
n = max(3, floor(log2(Ninfo)) - 6); n = max(3, floor(log2(Ninfo)) - 6);
Np_info = max(24, (Ninfo >> n) << n); Np_info = max(24, (Ninfo >> n) << n);
@@ -97,37 +95,28 @@ uint32_t nr_compute_tbs(uint16_t Qm,
} }
LOG_D(NR_MAC, "Ninfo %u nbp_re %d nb_re %d Qm %d, R %d, tbs %d bits\n", Ninfo, nbp_re, nb_re, Qm, R, nr_tbs); LOG_D(NR_MAC, "Ninfo %u nbp_re %d nb_re %d Qm %d, R %d, tbs %d bits\n", Ninfo, nbp_re, nb_re, Qm, R, nr_tbs);
return nr_tbs; return nr_tbs;
} }
//tbslbrm calculation according to 5.4.2.1 of 38.212 //tbslbrm calculation according to 5.4.2.1 of 38.212
uint32_t nr_compute_tbslbrm(uint16_t table, uint32_t nr_compute_tbslbrm(uint16_t table, uint16_t nb_rb, uint8_t Nl)
uint16_t nb_rb, {
uint8_t Nl) {
uint16_t R, nb_re;
uint16_t nb_rb_lbrm = 0; uint16_t nb_rb_lbrm = 0;
uint8_t Qm; for (int i = 0; i < 7; i++) {
int i;
uint32_t nr_tbs=0;
uint32_t Ninfo, Np_info, C;
uint8_t n;
for (i=0; i<7; i++) {
if (NPRB_LBRM[i] >= nb_rb){ if (NPRB_LBRM[i] >= nb_rb){
nb_rb_lbrm = NPRB_LBRM[i]; nb_rb_lbrm = NPRB_LBRM[i];
break; break;
} }
} }
Qm = ((table == 1)? 8 : 6); int Qm = (table == 1) ? 8 : 6;
R = 948; uint32_t R = 948;
nb_re = 156 * nb_rb_lbrm; uint32_t nb_re = 156 * nb_rb_lbrm;
// Intermediate number of information bits // Intermediate number of information bits
Ninfo = (nb_re * R * Qm * Nl)>>10; uint32_t Ninfo = (nb_re * R * Qm * Nl) >> 10;
uint32_t nr_tbs = 0;
uint32_t Np_info, n;
if (Ninfo <= NR_MAX_PDSCH_TBS) { if (Ninfo <= NR_MAX_PDSCH_TBS) {
n = max(3, floor(log2(Ninfo)) - 6); n = max(3, floor(log2(Ninfo)) - 6);
Np_info = max(24, (Ninfo >> n) << n); Np_info = max(24, (Ninfo >> n) << n);
@@ -140,7 +129,7 @@ uint32_t nr_compute_tbslbrm(uint16_t table,
} else { } else {
n = log2(Ninfo - 24) - 5; n = log2(Ninfo - 24) - 5;
Np_info = max(3840, (ROUNDIDIV((Ninfo - 24), (1 << n))) << n); Np_info = max(3840, (ROUNDIDIV((Ninfo - 24), (1 << n))) << n);
int C;
if (R <= 256) { if (R <= 256) {
C = CEILIDIV((Np_info + 24), 3816); C = CEILIDIV((Np_info + 24), 3816);
nr_tbs = (C << 3) * CEILIDIV((Np_info + 24), (C << 3)) - 24; nr_tbs = (C << 3) * CEILIDIV((Np_info + 24), (C << 3)) - 24;