diff --git a/matlab/tests/ulsch_test.m b/matlab/tests/ulsch_test.m index 49537797c..04fe974e2 100644 --- a/matlab/tests/ulsch_test.m +++ b/matlab/tests/ulsch_test.m @@ -1,24 +1,25 @@ clear ueConfig=struct('NCellID',1,'CyclicPrefixUL','Normal','NTxAnts',1); -puschConfig=struct('NLayers',1,'OrthCover','Off','PRBSet',0,'Shortened',0); +puschConfig=struct('NLayers',1,'OrthCover','Off','PRBSet',(0:15)','Shortened',0); addpath('../../build/srslte/lib/phch/test') -TBs=40; + cqilen=0; mods={'QPSK'}; rvs=0; betas=0; -for i=1:length(TBs) +for i=0:26 for m=1:length(mods) for r=1:length(rvs) for bri=1:length(betas) for back=1:length(betas) for c=1:length(cqilen) - - trblkin=randi(2,TBs(i),1)-1; - + TBs=lteTBS(length(puschConfig.PRBSet),i); + + trblkin=randi(2,TBs,1)-1; + puschConfig.Modulation = mods{m}; puschConfig.RV = rvs(r); puschConfig.BetaCQI = 5; @@ -36,7 +37,7 @@ for i=1:length(TBs) ack_bit=[]; end - if (cqilen(c)>0 || TBs(i)>0) + if (cqilen(c)>0 || TBs>0) [lib]=srslte_ulsch_encode(ueConfig,puschConfig,trblkin,ones(1,cqilen(c)),ri_bit,ack_bit); lib(lib==192)=3; lib(lib==48)=2; diff --git a/srslte/include/srslte/utils/bit.h b/srslte/include/srslte/utils/bit.h index 992e56206..29155116f 100644 --- a/srslte/include/srslte/utils/bit.h +++ b/srslte/include/srslte/utils/bit.h @@ -58,16 +58,16 @@ SRSLTE_API void srslte_bit_interleave_w_offset(uint8_t *input, uint32_t nof_bits, uint32_t w_offset); -SRSLTE_API void srslte_bit_unpack_vector(uint8_t *srslte_bit_packed, - uint8_t *bits_packed, - int nof_bits); - -SRSLTE_API void srslte_bit_pack_vector(uint8_t *bits_packed, - uint8_t *srslte_bit_packed, +SRSLTE_API void srslte_bit_unpack_vector(uint8_t *packed, + uint8_t *unpacked, int nof_bits); + +SRSLTE_API void srslte_bit_pack_vector(uint8_t *unpacked, + uint8_t *packed, + int nof_bits); SRSLTE_API uint32_t srslte_bit_pack(uint8_t **bits, - int nof_bits); + int nof_bits); SRSLTE_API uint64_t srslte_bit_pack_l(uint8_t **bits, int nof_bits); diff --git a/srslte/lib/fec/src/turbocoder.c b/srslte/lib/fec/src/turbocoder.c index dc268f59d..a20d3b95a 100644 --- a/srslte/lib/fec/src/turbocoder.c +++ b/srslte/lib/fec/src/turbocoder.c @@ -200,14 +200,17 @@ int srslte_tcod_encode_lut(srslte_tcod_t *h, uint8_t *input, uint8_t *parity, ui parity[i] = tcod_lut_output[cblen_idx][state0][input[i]]; state0 = tcod_lut_next_state[cblen_idx][state0][input[i]] % 8; } - + parity[long_cb/8] = 0; // will put tail here later + /* Interleave input */ srslte_bit_interleave(input, h->temp, tcod_per_fw[cblen_idx], long_cb); /* Parity bits for the 2nd constituent encoders */ uint8_t state1 = 0; for (uint32_t i=0;itemp[i]]; + uint8_t out = tcod_lut_output[cblen_idx][state1][h->temp[i]]; + parity[long_cb/8+i] |= (out&0xf0)>>4; + parity[long_cb/8+i+1] = (out&0xf)<<4; state1 = tcod_lut_next_state[cblen_idx][state1][h->temp[i]] % 8; } @@ -268,11 +271,14 @@ int srslte_tcod_encode_lut(srslte_tcod_t *h, uint8_t *input, uint8_t *parity, ui } } uint8_t *x = tailv[0]; - input[long_cb/8] = srslte_bit_pack(&x, 4); + printf("tail0: "); + srslte_vec_fprint_b(stdout, tailv[0], 4); + input[long_cb/8] = (srslte_bit_pack(&x, 4)<<4); + printf("0x%x\n", input[long_cb/8]); x = tailv[1]; - parity[long_cb/8] = srslte_bit_pack(&x, 4); + parity[long_cb/8] |= (srslte_bit_pack(&x, 4)<<4); x = tailv[2]; - parity[2*long_cb/8] = srslte_bit_pack(&x, 4); + parity[2*long_cb/8] |= (srslte_bit_pack(&x, 4)&0xf); return 3*long_cb+TOTALTAIL; } else { diff --git a/srslte/lib/fec/test/rm_turbo_test.c b/srslte/lib/fec/test/rm_turbo_test.c index 6c9bfb881..628adece8 100644 --- a/srslte/lib/fec/test/rm_turbo_test.c +++ b/srslte/lib/fec/test/rm_turbo_test.c @@ -93,8 +93,8 @@ int main(int argc, char **argv) { srslte_rm_turbo_gentables(); - //for (cb_idx=0;cb_idx<188;cb_idx++) { - // for (rv_idx=0;rv_idx<4;rv_idx++) { + for (cb_idx=0;cb_idx<188;cb_idx++) { + for (rv_idx=0;rv_idx<4;rv_idx++) { printf("cb_len=%d, rv_idx=%d\n", cb_idx, rv_idx); @@ -197,8 +197,8 @@ int main(int argc, char **argv) { exit(-1); } } - //} - //} + } + } printf("OK\n"); exit(0); diff --git a/srslte/lib/phch/src/sch.c b/srslte/lib/phch/src/sch.c index 120f74445..e950c7fe8 100644 --- a/srslte/lib/phch/src/sch.c +++ b/srslte/lib/phch/src/sch.c @@ -109,11 +109,11 @@ int srslte_sch_init(srslte_sch_t *q) { srslte_rm_turbo_gentables(); // Allocate floats for reception (LLRs) - q->cb_in = srslte_vec_malloc(sizeof(uint8_t) * SRSLTE_TCOD_MAX_LEN_CB); + q->cb_in = srslte_vec_malloc(sizeof(uint8_t) * SRSLTE_TCOD_MAX_LEN_CB+4); if (!q->cb_in) { goto clean; } - q->cb_temp = srslte_vec_malloc(sizeof(uint8_t) * SRSLTE_TCOD_MAX_LEN_CB); + q->cb_temp = srslte_vec_malloc(sizeof(uint8_t) * SRSLTE_TCOD_MAX_LEN_CB+4); if (!q->cb_temp) { goto clean; } @@ -161,6 +161,7 @@ uint32_t srslte_sch_last_noi(srslte_sch_t *q) { } +uint8_t temp[64*1024]; /* Encode a transport block according to 36.212 5.3.2 * @@ -273,23 +274,25 @@ static int encode_tb(srslte_sch_t *q, if (SRSLTE_VERBOSE_ISDEBUG()) { DEBUG("CB#%d encoded: ", i); - srslte_vec_fprint_b(stdout, q->cb_out, 3*cb_len+12); + srslte_vec_fprint_byte(stdout, q->cb_out, 2*cb_len/8); } } /* Rate matching */ - if (srslte_rm_turbo_tx_lut(soft_buffer->buffer_b[i], q->cb_in, (uint8_t*) q->cb_out, &e_bits[wp], cblen_idx, n_e, rv)) + if (srslte_rm_turbo_tx_lut(soft_buffer->buffer_b[i], q->cb_in, (uint8_t*) q->cb_out, &temp[wp], cblen_idx, n_e, rv)) { fprintf(stderr, "Error in rate matching\n"); return SRSLTE_ERROR; } - + /* Set read/write pointers */ rp += rlen; wp += n_e; } INFO("END CB#%d: wp: %d, rp: %d\n", i, wp, rp); - + + srslte_bit_unpack_vector(temp, e_bits, nof_e_bits); + ret = SRSLTE_SUCCESS; } return ret; diff --git a/srslte/lib/utils/src/bit.c b/srslte/lib/utils/src/bit.c index df8dd583c..75281b090 100644 --- a/srslte/lib/utils/src/bit.c +++ b/srslte/lib/utils/src/bit.c @@ -53,13 +53,26 @@ void srslte_bit_interleave_w_offset(uint8_t *input, uint8_t *output, uint32_t *i w_offset_p=8-w_offset; } for (uint32_t i=st;i>(nof_bits%8), &unpacked, nof_bits%8); } } @@ -245,16 +258,16 @@ void srslte_bit_unpack(uint32_t value, uint8_t **bits, int nof_bits) *bits += nof_bits; } -void srslte_bit_pack_vector(uint8_t *bits_packed, uint8_t *bits_unpacked, int nof_bits) +void srslte_bit_pack_vector(uint8_t *unpacked, uint8_t *packed, int nof_bits) { uint32_t i, nbytes; nbytes = nof_bits/8; for (i=0;i