Changed pack/unpack bit functions

master
ismagom 9 years ago
parent bb14ee4fd6
commit d2a17a631b

@ -422,7 +422,7 @@ void *net_thread_fnc(void *arg) {
while (rpm >= nbytes) { while (rpm >= nbytes) {
// wait for packet to be transmitted // wait for packet to be transmitted
sem_wait(&net_sem); sem_wait(&net_sem);
srslte_bit_pack_vector(&data_unpacked[wpm], data, nbytes*8); srslte_bit_unpack_vector(&data_unpacked[wpm], data, nbytes*8);
INFO("Sent %d/%d bytes ready\n", nbytes, rpm); INFO("Sent %d/%d bytes ready\n", nbytes, rpm);
rpm -= nbytes; rpm -= nbytes;
wpm += nbytes; wpm += nbytes;
@ -590,7 +590,7 @@ int main(int argc, char **argv) {
} }
if (net_port > 0 && net_packet_ready) { if (net_port > 0 && net_packet_ready) {
if (null_file_sink) { if (null_file_sink) {
srslte_bit_unpack_vector(data, data_tmp, pdsch_cfg.grant.mcs.tbs); srslte_bit_pack_vector(data, data_tmp, pdsch_cfg.grant.mcs.tbs);
if (srslte_netsink_write(&net_sink, data_tmp, 1+(pdsch_cfg.grant.mcs.tbs-1)/8) < 0) { if (srslte_netsink_write(&net_sink, data_tmp, 1+(pdsch_cfg.grant.mcs.tbs-1)/8) < 0) {
fprintf(stderr, "Error sending data through UDP socket\n"); fprintf(stderr, "Error sending data through UDP socket\n");
} }

@ -264,20 +264,20 @@ int rar_unpack(uint8_t *buffer, rar_msg_t *msg)
msg->hdr_type = *ptr++; msg->hdr_type = *ptr++;
if(msg->hdr_type == rar_header_type_bi) { if(msg->hdr_type == rar_header_type_bi) {
ptr += 2; ptr += 2;
msg->BI = srslte_bit_unpack(&ptr, 4); msg->BI = srslte_bit_pack(&ptr, 4);
ret = SRSLTE_SUCCESS; ret = SRSLTE_SUCCESS;
} else if (msg->hdr_type == rar_header_type_rapid) { } else if (msg->hdr_type == rar_header_type_rapid) {
msg->RAPID = srslte_bit_unpack(&ptr, 6); msg->RAPID = srslte_bit_pack(&ptr, 6);
ptr++; ptr++;
msg->timing_adv_cmd = srslte_bit_unpack(&ptr, 11); msg->timing_adv_cmd = srslte_bit_pack(&ptr, 11);
msg->hopping_flag = *ptr++; msg->hopping_flag = *ptr++;
msg->rba = srslte_bit_unpack(&ptr, 10); msg->rba = srslte_bit_pack(&ptr, 10);
msg->mcs = srslte_bit_unpack(&ptr, 4); msg->mcs = srslte_bit_pack(&ptr, 4);
msg->tpc_command = (rar_tpc_command_t) srslte_bit_unpack(&ptr, 3); msg->tpc_command = (rar_tpc_command_t) srslte_bit_pack(&ptr, 3);
msg->ul_delay = *ptr++; msg->ul_delay = *ptr++;
msg->csi_req = *ptr++; msg->csi_req = *ptr++;
msg->temp_c_rnti = srslte_bit_unpack(&ptr, 16); msg->temp_c_rnti = srslte_bit_pack(&ptr, 16);
ret = SRSLTE_SUCCESS; ret = SRSLTE_SUCCESS;
} }
} }
@ -504,7 +504,7 @@ cell.nof_ports = 1;
srslte_ue_sync_get_last_timestamp(&ue_sync, &uhd_time); srslte_ue_sync_get_last_timestamp(&ue_sync, &uhd_time);
srslte_bit_pack_vector((uint8_t*) conn_request_msg, data, ra_grant.mcs.tbs); srslte_bit_unpack_vector((uint8_t*) conn_request_msg, data, ra_grant.mcs.tbs);
uint32_t n_ta = srslte_N_ta_new_rar(rar_msg.timing_adv_cmd); uint32_t n_ta = srslte_N_ta_new_rar(rar_msg.timing_adv_cmd);
printf("ta: %d, n_ta: %d\n", rar_msg.timing_adv_cmd, n_ta); printf("ta: %d, n_ta: %d\n", rar_msg.timing_adv_cmd, n_ta);

@ -41,25 +41,25 @@
#include "srslte/config.h" #include "srslte/config.h"
SRSLTE_API void srslte_bit_pack_vector(uint8_t *srslte_bit_unpacked, SRSLTE_API void srslte_bit_unpack_vector(uint8_t *srslte_bit_packed,
uint8_t *bits_packed, uint8_t *bits_packed,
int nof_bits); int nof_bits);
SRSLTE_API void srslte_bit_unpack_vector(uint8_t *bits_packed, SRSLTE_API void srslte_bit_pack_vector(uint8_t *bits_packed,
uint8_t *srslte_bit_unpacked, uint8_t *srslte_bit_packed,
int nof_bits); int nof_bits);
SRSLTE_API uint32_t srslte_bit_unpack(uint8_t **bits, SRSLTE_API uint32_t srslte_bit_pack(uint8_t **bits,
int nof_bits); int nof_bits);
SRSLTE_API uint64_t srslte_bit_unpack_l(uint8_t **bits, SRSLTE_API uint64_t srslte_bit_pack_l(uint8_t **bits,
int nof_bits); int nof_bits);
SRSLTE_API void srslte_bit_pack_l(uint64_t value, SRSLTE_API void srslte_bit_unpack_l(uint64_t value,
uint8_t **bits, uint8_t **bits,
int nof_bits); int nof_bits);
SRSLTE_API void srslte_bit_pack(uint32_t value, SRSLTE_API void srslte_bit_unpack(uint32_t value,
uint8_t **bits, uint8_t **bits,
int nof_bits); int nof_bits);

@ -136,7 +136,7 @@ uint32_t srslte_crc_checksum(srslte_crc_t *h, uint8_t *data, int len) {
byte |= ((uint8_t) *(pter + k)) << (7 - k); byte |= ((uint8_t) *(pter + k)) << (7 - k);
} }
} else { } else {
byte = (uint8_t) (srslte_bit_unpack(&pter, 8) & 0xFF); byte = (uint8_t) (srslte_bit_pack(&pter, 8) & 0xFF);
} }
crc = crctable(h, byte); crc = crctable(h, byte);
} }
@ -185,7 +185,7 @@ uint32_t srslte_crc_attach(srslte_crc_t *h, uint8_t *data, int len) {
// Add CRC // Add CRC
uint8_t *ptr = &data[len]; uint8_t *ptr = &data[len];
srslte_bit_pack(checksum, &ptr, h->order); srslte_bit_unpack(checksum, &ptr, h->order);
return checksum; return checksum;
} }

@ -265,7 +265,7 @@ int srslte_tcod_encode_lut(srslte_tcod_t *h, uint8_t *input, uint8_t *output, ui
k++; k++;
} }
srslte_bit_unpack_vector(tail, &output[2*(long_cb/8)], TOTALTAIL); srslte_bit_pack_vector(tail, &output[2*(long_cb/8)], TOTALTAIL);
return 2*long_cb+TOTALTAIL; return 2*long_cb+TOTALTAIL;
} }

@ -90,7 +90,7 @@ int main(int argc, char **argv) {
input_bytes[i] = rand()%256; input_bytes[i] = rand()%256;
} }
srslte_bit_pack_vector(input_bytes, input_bits, long_cb); srslte_bit_unpack_vector(input_bytes, input_bits, long_cb);
if (SRSLTE_VERBOSE_ISINFO()) { if (SRSLTE_VERBOSE_ISINFO()) {
printf("Input bits:\n"); printf("Input bits:\n");
@ -102,7 +102,7 @@ int main(int argc, char **argv) {
srslte_tcod_encode(&tcod, input_bits, output_bits, long_cb); srslte_tcod_encode(&tcod, input_bits, output_bits, long_cb);
srslte_tcod_encode_lut(&tcod, input_bytes, output_bytes, long_cb); srslte_tcod_encode_lut(&tcod, input_bytes, output_bytes, long_cb);
srslte_bit_pack_vector(output_bytes, output_bits2, 2*long_cb+12); srslte_bit_unpack_vector(output_bytes, output_bits2, 2*long_cb+12);
/* de-Interleace bits for comparison */ /* de-Interleace bits for comparison */
for (int i=0;i<long_cb;i++) { for (int i=0;i<long_cb;i++) {

@ -106,9 +106,9 @@ static int int_2_bits(uint32_t* src, uint8_t* dst, int nbits) {
int n; int n;
n=nbits/32; n=nbits/32;
for (int i=0;i<n;i++) { for (int i=0;i<n;i++) {
srslte_bit_pack(src[i],&dst,32); srslte_bit_unpack(src[i],&dst,32);
} }
srslte_bit_pack(src[n],&dst,nbits-n*32); srslte_bit_unpack(src[n],&dst,nbits-n*32);
return n; return n;
} }

@ -40,7 +40,7 @@ int srslte_mod_modulate(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, u
uint8_t *b_ptr=(uint8_t*) bits; uint8_t *b_ptr=(uint8_t*) bits;
j=0; j=0;
for (i=0;i<nbits;i+=q->nbits_x_symbol) { for (i=0;i<nbits;i+=q->nbits_x_symbol) {
idx = srslte_bit_unpack(&b_ptr,q->nbits_x_symbol); idx = srslte_bit_pack(&b_ptr,q->nbits_x_symbol);
if (idx < q->nsymbols) { if (idx < q->nsymbols) {
symbols[j] = q->symbol_table[idx]; symbols[j] = q->symbol_table[idx];
} else { } else {

@ -44,8 +44,8 @@
int srslte_cqi_hl_subband_pack(srslte_cqi_hl_subband_t *msg, uint8_t buff[SRSLTE_CQI_MAX_BITS]) int srslte_cqi_hl_subband_pack(srslte_cqi_hl_subband_t *msg, uint8_t buff[SRSLTE_CQI_MAX_BITS])
{ {
uint8_t *body_ptr = buff; uint8_t *body_ptr = buff;
srslte_bit_pack(msg->wideband_cqi, &body_ptr, 4); srslte_bit_unpack(msg->wideband_cqi, &body_ptr, 4);
srslte_bit_pack(msg->subband_diff_cqi, &body_ptr, 2*msg->N); srslte_bit_unpack(msg->subband_diff_cqi, &body_ptr, 2*msg->N);
return 4+2*msg->N; return 4+2*msg->N;
} }
@ -53,9 +53,9 @@ int srslte_cqi_hl_subband_pack(srslte_cqi_hl_subband_t *msg, uint8_t buff[SRSLTE
int srslte_cqi_ue_subband_pack(srslte_cqi_ue_subband_t *msg, uint8_t buff[SRSLTE_CQI_MAX_BITS]) int srslte_cqi_ue_subband_pack(srslte_cqi_ue_subband_t *msg, uint8_t buff[SRSLTE_CQI_MAX_BITS])
{ {
uint8_t *body_ptr = buff; uint8_t *body_ptr = buff;
srslte_bit_pack(msg->wideband_cqi, &body_ptr, 4); srslte_bit_unpack(msg->wideband_cqi, &body_ptr, 4);
srslte_bit_pack(msg->subband_diff_cqi, &body_ptr, 2); srslte_bit_unpack(msg->subband_diff_cqi, &body_ptr, 2);
srslte_bit_pack(msg->subband_diff_cqi, &body_ptr, msg->L); srslte_bit_unpack(msg->subband_diff_cqi, &body_ptr, msg->L);
return 4+2+msg->L; return 4+2+msg->L;
} }
@ -63,15 +63,15 @@ int srslte_cqi_ue_subband_pack(srslte_cqi_ue_subband_t *msg, uint8_t buff[SRSLTE
int srslte_cqi_format2_wideband_pack(srslte_cqi_format2_wideband_t *msg, uint8_t buff[SRSLTE_CQI_MAX_BITS]) int srslte_cqi_format2_wideband_pack(srslte_cqi_format2_wideband_t *msg, uint8_t buff[SRSLTE_CQI_MAX_BITS])
{ {
uint8_t *body_ptr = buff; uint8_t *body_ptr = buff;
srslte_bit_pack(msg->wideband_cqi, &body_ptr, 4); srslte_bit_unpack(msg->wideband_cqi, &body_ptr, 4);
return 4; return 4;
} }
int srslte_cqi_format2_subband_pack(srslte_cqi_format2_subband_t *msg, uint8_t buff[SRSLTE_CQI_MAX_BITS]) int srslte_cqi_format2_subband_pack(srslte_cqi_format2_subband_t *msg, uint8_t buff[SRSLTE_CQI_MAX_BITS])
{ {
uint8_t *body_ptr = buff; uint8_t *body_ptr = buff;
srslte_bit_pack(msg->subband_cqi, &body_ptr, 4); srslte_bit_unpack(msg->subband_cqi, &body_ptr, 4);
srslte_bit_pack(msg->subband_label, &body_ptr, msg->subband_label_2_bits?2:1); srslte_bit_unpack(msg->subband_label, &body_ptr, msg->subband_label_2_bits?2:1);
return 4+msg->subband_label_2_bits?2:1; return 4+msg->subband_label_2_bits?2:1;
} }

@ -141,12 +141,12 @@ int srslte_dci_rar_to_ul_grant(srslte_dci_rar_grant_t *rar, uint32_t nof_prb,
void srslte_dci_rar_grant_unpack(srslte_dci_rar_grant_t *rar, uint8_t grant[SRSLTE_RAR_GRANT_LEN]) void srslte_dci_rar_grant_unpack(srslte_dci_rar_grant_t *rar, uint8_t grant[SRSLTE_RAR_GRANT_LEN])
{ {
uint8_t *grant_ptr = grant; uint8_t *grant_ptr = grant;
rar->hopping_flag = srslte_bit_unpack(&grant_ptr, 1)?true:false; rar->hopping_flag = srslte_bit_pack(&grant_ptr, 1)?true:false;
rar->rba = srslte_bit_unpack(&grant_ptr, 10); rar->rba = srslte_bit_pack(&grant_ptr, 10);
rar->trunc_mcs = srslte_bit_unpack(&grant_ptr, 4); rar->trunc_mcs = srslte_bit_pack(&grant_ptr, 4);
rar->tpc_pusch = srslte_bit_unpack(&grant_ptr, 3); rar->tpc_pusch = srslte_bit_pack(&grant_ptr, 3);
rar->ul_delay = srslte_bit_unpack(&grant_ptr, 1)?true:false; rar->ul_delay = srslte_bit_pack(&grant_ptr, 1)?true:false;
rar->cqi_request = srslte_bit_unpack(&grant_ptr, 1)?true:false; rar->cqi_request = srslte_bit_pack(&grant_ptr, 1)?true:false;
} }
void srslte_dci_rar_grant_fprint(FILE *stream, srslte_dci_rar_grant_t *rar) { void srslte_dci_rar_grant_fprint(FILE *stream, srslte_dci_rar_grant_t *rar) {
@ -341,10 +341,10 @@ int dci_format0_pack(srslte_ra_ul_dci_t *data, srslte_dci_msg_t *msg, uint32_t n
riv = data->type2_alloc.riv; riv = data->type2_alloc.riv;
} }
srslte_bit_pack(riv, &y, riv_nbits(nof_prb) - n_ul_hop); srslte_bit_unpack(riv, &y, riv_nbits(nof_prb) - n_ul_hop);
/* pack MCS according to 8.6.1 of 36.213 */ /* pack MCS according to 8.6.1 of 36.213 */
srslte_bit_pack(data->mcs_idx, &y, 5); srslte_bit_unpack(data->mcs_idx, &y, 5);
*y++ = data->ndi; *y++ = data->ndi;
@ -402,21 +402,21 @@ int dci_format0_unpack(srslte_dci_msg_t *msg, srslte_ra_ul_dci_t *data, uint32_t
} }
} }
/* unpack RIV according to 8.1 of 36.213 */ /* unpack RIV according to 8.1 of 36.213 */
uint32_t riv = srslte_bit_unpack(&y, riv_nbits(nof_prb) - n_ul_hop); uint32_t riv = srslte_bit_pack(&y, riv_nbits(nof_prb) - n_ul_hop);
srslte_ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start, srslte_ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start,
nof_prb, nof_prb); nof_prb, nof_prb);
data->type2_alloc.riv = riv; data->type2_alloc.riv = riv;
/* unpack MCS according to 8.6 of 36.213 */ /* unpack MCS according to 8.6 of 36.213 */
data->mcs_idx = srslte_bit_unpack(&y, 5); data->mcs_idx = srslte_bit_pack(&y, 5);
data->ndi = *y++ ? true : false; data->ndi = *y++ ? true : false;
// TPC command for scheduled PUSCH // TPC command for scheduled PUSCH
data->tpc_pusch = srslte_bit_unpack(&y, 2); data->tpc_pusch = srslte_bit_pack(&y, 2);
// Cyclic shift for DMRS // Cyclic shift for DMRS
data->n_dmrs = srslte_bit_unpack(&y, 3); data->n_dmrs = srslte_bit_pack(&y, 3);
// CQI request // CQI request
data->cqi_request = *y++ ? true : false; data->cqi_request = *y++ ? true : false;
@ -444,12 +444,12 @@ int dci_format1_pack(srslte_ra_dl_dci_t *data, srslte_dci_msg_t *msg, uint32_t n
uint32_t alloc_size = (uint32_t) ceilf((float) nof_prb / P); uint32_t alloc_size = (uint32_t) ceilf((float) nof_prb / P);
switch (data->alloc_type) { switch (data->alloc_type) {
case SRSLTE_RA_ALLOC_TYPE0: case SRSLTE_RA_ALLOC_TYPE0:
srslte_bit_pack((uint32_t) data->type0_alloc.rbg_bitmask, &y, alloc_size); srslte_bit_unpack((uint32_t) data->type0_alloc.rbg_bitmask, &y, alloc_size);
break; break;
case SRSLTE_RA_ALLOC_TYPE1: case SRSLTE_RA_ALLOC_TYPE1:
srslte_bit_pack((uint32_t) data->type1_alloc.rbg_subset, &y, (int) ceilf(log2f(P))); srslte_bit_unpack((uint32_t) data->type1_alloc.rbg_subset, &y, (int) ceilf(log2f(P)));
*y++ = data->type1_alloc.shift ? 1 : 0; *y++ = data->type1_alloc.shift ? 1 : 0;
srslte_bit_pack((uint32_t) data->type1_alloc.vrb_bitmask, &y, srslte_bit_unpack((uint32_t) data->type1_alloc.vrb_bitmask, &y,
alloc_size - (int) ceilf(log2f(P)) - 1); alloc_size - (int) ceilf(log2f(P)) - 1);
break; break;
default: default:
@ -459,15 +459,15 @@ int dci_format1_pack(srslte_ra_dl_dci_t *data, srslte_dci_msg_t *msg, uint32_t n
} }
/* pack MCS */ /* pack MCS */
srslte_bit_pack(data->mcs_idx, &y, 5); srslte_bit_unpack(data->mcs_idx, &y, 5);
/* harq process number */ /* harq process number */
srslte_bit_pack(data->harq_process, &y, 3); srslte_bit_unpack(data->harq_process, &y, 3);
*y++ = data->ndi; *y++ = data->ndi;
// rv version // rv version
srslte_bit_pack(data->rv_idx, &y, 2); srslte_bit_unpack(data->rv_idx, &y, 2);
// TPC not implemented // TPC not implemented
*y++ = 0; *y++ = 0;
@ -505,12 +505,12 @@ int dci_format1_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32_t
uint32_t alloc_size = (uint32_t) ceilf((float) nof_prb / P); uint32_t alloc_size = (uint32_t) ceilf((float) nof_prb / P);
switch (data->alloc_type) { switch (data->alloc_type) {
case SRSLTE_RA_ALLOC_TYPE0: case SRSLTE_RA_ALLOC_TYPE0:
data->type0_alloc.rbg_bitmask = srslte_bit_unpack(&y, alloc_size); data->type0_alloc.rbg_bitmask = srslte_bit_pack(&y, alloc_size);
break; break;
case SRSLTE_RA_ALLOC_TYPE1: case SRSLTE_RA_ALLOC_TYPE1:
data->type1_alloc.rbg_subset = srslte_bit_unpack(&y, (int) ceilf(log2f(P))); data->type1_alloc.rbg_subset = srslte_bit_pack(&y, (int) ceilf(log2f(P)));
data->type1_alloc.shift = *y++ ? true : false; data->type1_alloc.shift = *y++ ? true : false;
data->type1_alloc.vrb_bitmask = srslte_bit_unpack(&y, data->type1_alloc.vrb_bitmask = srslte_bit_pack(&y,
alloc_size - (int) ceilf(log2f(P)) - 1); alloc_size - (int) ceilf(log2f(P)) - 1);
break; break;
default: default:
@ -519,14 +519,14 @@ int dci_format1_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32_t
} }
/* unpack MCS according to 7.1.7 of 36.213 */ /* unpack MCS according to 7.1.7 of 36.213 */
data->mcs_idx = srslte_bit_unpack(&y, 5); data->mcs_idx = srslte_bit_pack(&y, 5);
/* harq process number */ /* harq process number */
data->harq_process = srslte_bit_unpack(&y, 3); data->harq_process = srslte_bit_pack(&y, 3);
data->ndi = *y++ ? true : false; data->ndi = *y++ ? true : false;
// rv version // rv version
data->rv_idx = srslte_bit_unpack(&y, 2); data->rv_idx = srslte_bit_pack(&y, 2);
// TPC not implemented // TPC not implemented
@ -588,12 +588,12 @@ int dci_format1As_pack(srslte_ra_dl_dci_t *data, srslte_dci_msg_t *msg, uint32_t
nb_gap = 1; nb_gap = 1;
*y++ = data->type2_alloc.n_gap; *y++ = data->type2_alloc.n_gap;
} }
srslte_bit_pack(riv, &y, riv_nbits(nof_prb) - nb_gap); srslte_bit_unpack(riv, &y, riv_nbits(nof_prb) - nb_gap);
// in format1A, MCS = TBS according to 7.1.7.2 of 36.213 // in format1A, MCS = TBS according to 7.1.7.2 of 36.213
srslte_bit_pack(data->mcs_idx, &y, 5); srslte_bit_unpack(data->mcs_idx, &y, 5);
srslte_bit_pack(data->harq_process, &y, 3); srslte_bit_unpack(data->harq_process, &y, 3);
if (!crc_is_crnti && nof_prb >= 50 && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST) { if (!crc_is_crnti && nof_prb >= 50 && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST) {
*y++ = data->type2_alloc.n_gap; *y++ = data->type2_alloc.n_gap;
@ -602,7 +602,7 @@ int dci_format1As_pack(srslte_ra_dl_dci_t *data, srslte_dci_msg_t *msg, uint32_t
} }
// rv version // rv version
srslte_bit_pack(data->rv_idx, &y, 2); srslte_bit_unpack(data->rv_idx, &y, 2);
if (crc_is_crnti) { if (crc_is_crnti) {
// TPC not implemented // TPC not implemented
@ -661,15 +661,15 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32
} else { } else {
nof_vrb = srslte_ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == SRSLTE_RA_TYPE2_NG1); nof_vrb = srslte_ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == SRSLTE_RA_TYPE2_NG1);
} }
uint32_t riv = srslte_bit_unpack(&y, riv_nbits(nof_prb) - nb_gap); uint32_t riv = srslte_bit_pack(&y, riv_nbits(nof_prb) - nb_gap);
srslte_ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start, srslte_ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start,
nof_prb, nof_vrb); nof_prb, nof_vrb);
data->type2_alloc.riv = riv; data->type2_alloc.riv = riv;
// unpack MCS // unpack MCS
data->mcs_idx = srslte_bit_unpack(&y, 5); data->mcs_idx = srslte_bit_pack(&y, 5);
data->harq_process = srslte_bit_unpack(&y, 3); data->harq_process = srslte_bit_pack(&y, 3);
if (!crc_is_crnti) { if (!crc_is_crnti) {
if (nof_prb >= 50 && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST) { if (nof_prb >= 50 && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST) {
@ -682,7 +682,7 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32
} }
// rv version // rv version
data->rv_idx = srslte_bit_unpack(&y, 2); data->rv_idx = srslte_bit_pack(&y, 2);
if (crc_is_crnti) { if (crc_is_crnti) {
// TPC not implemented // TPC not implemented
@ -741,10 +741,10 @@ int dci_format1Cs_pack(srslte_ra_dl_dci_t *data, srslte_dci_msg_t *msg, uint32_t
} else { } else {
riv = data->type2_alloc.riv; riv = data->type2_alloc.riv;
} }
srslte_bit_pack(riv, &y, riv_nbits((int) n_vrb_dl / n_step)); srslte_bit_unpack(riv, &y, riv_nbits((int) n_vrb_dl / n_step));
// in format1C, MCS = TBS according to 7.1.7.2 of 36.213 // in format1C, MCS = TBS according to 7.1.7.2 of 36.213
srslte_bit_pack(data->mcs_idx, &y, 5); srslte_bit_unpack(data->mcs_idx, &y, 5);
msg->nof_bits = (y - msg->data); msg->nof_bits = (y - msg->data);
@ -769,7 +769,7 @@ int dci_format1Cs_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32
uint32_t n_step = srslte_ra_type2_n_rb_step(nof_prb); uint32_t n_step = srslte_ra_type2_n_rb_step(nof_prb);
uint32_t n_vrb_dl = srslte_ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == SRSLTE_RA_TYPE2_NG1); uint32_t n_vrb_dl = srslte_ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == SRSLTE_RA_TYPE2_NG1);
uint32_t riv = srslte_bit_unpack(&y, riv_nbits((int) n_vrb_dl / n_step)); uint32_t riv = srslte_bit_pack(&y, riv_nbits((int) n_vrb_dl / n_step));
uint32_t n_vrb_p = (uint32_t) n_vrb_dl / n_step; uint32_t n_vrb_p = (uint32_t) n_vrb_dl / n_step;
srslte_ra_type2_from_riv(riv, &L_p, &RB_p, n_vrb_p, n_vrb_p); srslte_ra_type2_from_riv(riv, &L_p, &RB_p, n_vrb_p, n_vrb_p);
@ -777,7 +777,7 @@ int dci_format1Cs_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32
data->type2_alloc.RB_start = RB_p * n_step; data->type2_alloc.RB_start = RB_p * n_step;
data->type2_alloc.riv = riv; data->type2_alloc.riv = riv;
data->mcs_idx = srslte_bit_unpack(&y, 5); data->mcs_idx = srslte_bit_pack(&y, 5);
data->dci_format = SRSLTE_RA_DCI_FORMAT1C; data->dci_format = SRSLTE_RA_DCI_FORMAT1C;

@ -261,7 +261,7 @@ void srslte_pbch_free(srslte_pbch_t *q) {
void srslte_pbch_mib_unpack(uint8_t *msg, srslte_cell_t *cell, uint32_t *sfn) { void srslte_pbch_mib_unpack(uint8_t *msg, srslte_cell_t *cell, uint32_t *sfn) {
int phich_res; int phich_res;
cell->bw_idx = srslte_bit_unpack(&msg, 3); cell->bw_idx = srslte_bit_pack(&msg, 3);
switch (cell->bw_idx) { switch (cell->bw_idx) {
case 0: case 0:
cell->nof_prb = 6; cell->nof_prb = 6;
@ -280,7 +280,7 @@ void srslte_pbch_mib_unpack(uint8_t *msg, srslte_cell_t *cell, uint32_t *sfn) {
} }
msg++; msg++;
phich_res = srslte_bit_unpack(&msg, 2); phich_res = srslte_bit_pack(&msg, 2);
switch (phich_res) { switch (phich_res) {
case 0: case 0:
cell->phich_resources = SRSLTE_PHICH_SRSLTE_PHICH_R_1_6; cell->phich_resources = SRSLTE_PHICH_SRSLTE_PHICH_R_1_6;
@ -296,7 +296,7 @@ void srslte_pbch_mib_unpack(uint8_t *msg, srslte_cell_t *cell, uint32_t *sfn) {
break; break;
} }
if (sfn) { if (sfn) {
*sfn = srslte_bit_unpack(&msg, 8) << 2; *sfn = srslte_bit_pack(&msg, 8) << 2;
} }
} }
@ -315,7 +315,7 @@ void srslte_pbch_mib_pack(srslte_cell_t *cell, uint32_t sfn, uint8_t *msg) {
} else { } else {
bw = 1 + cell->nof_prb / 25; bw = 1 + cell->nof_prb / 25;
} }
srslte_bit_pack(bw, &msg, 3); srslte_bit_unpack(bw, &msg, 3);
*msg = cell->phich_length == SRSLTE_PHICH_EXT; *msg = cell->phich_length == SRSLTE_PHICH_EXT;
msg++; msg++;
@ -334,8 +334,8 @@ void srslte_pbch_mib_pack(srslte_cell_t *cell, uint32_t sfn, uint8_t *msg) {
phich_res = 3; phich_res = 3;
break; break;
} }
srslte_bit_pack(phich_res, &msg, 2); srslte_bit_unpack(phich_res, &msg, 2);
srslte_bit_pack(sfn >> 2, &msg, 8); srslte_bit_unpack(sfn >> 2, &msg, 8);
} }
void srslte_pbch_decode_reset(srslte_pbch_t *q) { void srslte_pbch_decode_reset(srslte_pbch_t *q) {

@ -296,7 +296,7 @@ static int dci_decode(srslte_pdcch_t *q, float *e, uint8_t *data, uint32_t E, ui
} }
x = &data[nof_bits]; x = &data[nof_bits];
p_bits = (uint16_t) srslte_bit_unpack(&x, 16); p_bits = (uint16_t) srslte_bit_pack(&x, 16);
crc_res = ((uint16_t) srslte_crc_checksum(&q->crc, data, nof_bits) & 0xffff); crc_res = ((uint16_t) srslte_crc_checksum(&q->crc, data, nof_bits) & 0xffff);
DEBUG("p_bits: 0x%x, crc_checksum: 0x%x, crc_rem: 0x%x\n", p_bits, crc_res, DEBUG("p_bits: 0x%x, crc_checksum: 0x%x, crc_rem: 0x%x\n", p_bits, crc_res,
p_bits ^ crc_res); p_bits ^ crc_res);
@ -444,7 +444,7 @@ static void crc_set_mask_rnti(uint8_t *crc, uint16_t rnti) {
DEBUG("Mask CRC with RNTI 0x%x\n", rnti); DEBUG("Mask CRC with RNTI 0x%x\n", rnti);
srslte_bit_pack(rnti, &r, 16); srslte_bit_unpack(rnti, &r, 16);
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
crc[i] = (crc[i] + mask[i]) % 2; crc[i] = (crc[i] + mask[i]) % 2;
} }

@ -260,7 +260,7 @@ static int encode_tb(srslte_sch_t *q,
} }
/* pack bits to temporal buffer for encoding */ /* pack bits to temporal buffer for encoding */
srslte_bit_pack_vector(q->cb_in, q->cb_temp, cb_len); srslte_bit_unpack_vector(q->cb_in, q->cb_temp, cb_len);
/* Set the filler bits to <NULL> */ /* Set the filler bits to <NULL> */
for (int j = 0; j < F; j++) { for (int j = 0; j < F; j++) {

@ -67,9 +67,9 @@ int main(int argc, char **argv) {
for (i = 0; i < nwords; i++) { for (i = 0; i < nwords; i++) {
x = strtoul(argv[i + 3], NULL, 16); x = strtoul(argv[i + 3], NULL, 16);
if (len - rlen < 32) { if (len - rlen < 32) {
srslte_bit_pack(x, &y, len - rlen); srslte_bit_unpack(x, &y, len - rlen);
} else { } else {
srslte_bit_pack(x, &y, 32); srslte_bit_unpack(x, &y, 32);
} }
} }

@ -69,7 +69,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
return; return;
} }
uint8_t *trblkin = srslte_vec_malloc(cfg.grant.mcs.tbs/8); uint8_t *trblkin = srslte_vec_malloc(cfg.grant.mcs.tbs/8);
srslte_bit_unpack_vector(trblkin_bits, trblkin, cfg.grant.mcs.tbs); srslte_bit_pack_vector(trblkin_bits, trblkin, cfg.grant.mcs.tbs);
free(trblkin_bits); free(trblkin_bits);
if (mexutils_read_uint32_struct(PUSCHCFG, "RV", &cfg.rv)) { if (mexutils_read_uint32_struct(PUSCHCFG, "RV", &cfg.rv)) {

@ -217,7 +217,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
free(data_bytes); free(data_bytes);
uint8_t *data = malloc(grant.mcs.tbs); uint8_t *data = malloc(grant.mcs.tbs);
srslte_bit_pack_vector(data_bytes, data, grant.mcs.tbs); srslte_bit_unpack_vector(data_bytes, data, grant.mcs.tbs);
if (nlhs >= 1) { if (nlhs >= 1) {
plhs[0] = mxCreateLogicalScalar(r == 0); plhs[0] = mxCreateLogicalScalar(r == 0);

@ -128,7 +128,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
grant.mcs.tbs = mexutils_read_uint8(TRBLKIN, &trblkin_bits); grant.mcs.tbs = mexutils_read_uint8(TRBLKIN, &trblkin_bits);
uint8_t *trblkin = srslte_vec_malloc(grant.mcs.tbs/8); uint8_t *trblkin = srslte_vec_malloc(grant.mcs.tbs/8);
srslte_bit_unpack_vector(trblkin_bits, trblkin, grant.mcs.tbs); srslte_bit_pack_vector(trblkin_bits, trblkin, grant.mcs.tbs);
free(trblkin_bits); free(trblkin_bits);
grant.M_sc = grant.L_prb*SRSLTE_NRE; grant.M_sc = grant.L_prb*SRSLTE_NRE;

@ -78,7 +78,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
cfg.grant.mcs.tbs = mexutils_read_uint8(TRBLKIN, &trblkin_bits); cfg.grant.mcs.tbs = mexutils_read_uint8(TRBLKIN, &trblkin_bits);
uint8_t *trblkin = srslte_vec_malloc(cfg.grant.mcs.tbs/8); uint8_t *trblkin = srslte_vec_malloc(cfg.grant.mcs.tbs/8);
srslte_bit_unpack_vector(trblkin_bits, trblkin, cfg.grant.mcs.tbs); srslte_bit_pack_vector(trblkin_bits, trblkin, cfg.grant.mcs.tbs);
free(trblkin_bits); free(trblkin_bits);

@ -31,19 +31,19 @@
#include "srslte/utils/bit.h" #include "srslte/utils/bit.h"
void srslte_bit_pack_vector(uint8_t *bits_unpacked, uint8_t *bits_packed, int nof_bits) void srslte_bit_unpack_vector(uint8_t *bits_unpacked, uint8_t *bits_packed, int nof_bits)
{ {
uint32_t i, nbytes; uint32_t i, nbytes;
nbytes = nof_bits/8; nbytes = nof_bits/8;
for (i=0;i<nbytes;i++) { for (i=0;i<nbytes;i++) {
srslte_bit_pack(bits_unpacked[i], &bits_packed, 8); srslte_bit_unpack(bits_unpacked[i], &bits_packed, 8);
} }
if (nof_bits%8) { if (nof_bits%8) {
srslte_bit_pack(bits_unpacked[i], &bits_packed, nof_bits%8); srslte_bit_unpack(bits_unpacked[i], &bits_packed, nof_bits%8);
} }
} }
void srslte_bit_pack_l(uint64_t value, uint8_t **bits, int nof_bits) void srslte_bit_unpack_l(uint64_t value, uint8_t **bits, int nof_bits)
{ {
int i; int i;
@ -53,7 +53,7 @@ void srslte_bit_pack_l(uint64_t value, uint8_t **bits, int nof_bits)
*bits += nof_bits; *bits += nof_bits;
} }
void srslte_bit_pack(uint32_t value, uint8_t **bits, int nof_bits) void srslte_bit_unpack(uint32_t value, uint8_t **bits, int nof_bits)
{ {
int i; int i;
@ -63,19 +63,19 @@ void srslte_bit_pack(uint32_t value, uint8_t **bits, int nof_bits)
*bits += nof_bits; *bits += nof_bits;
} }
void srslte_bit_unpack_vector(uint8_t *bits_packed, uint8_t *bits_unpacked, int nof_bits) void srslte_bit_pack_vector(uint8_t *bits_packed, uint8_t *bits_unpacked, int nof_bits)
{ {
uint32_t i, nbytes; uint32_t i, nbytes;
nbytes = nof_bits/8; nbytes = nof_bits/8;
for (i=0;i<nbytes;i++) { for (i=0;i<nbytes;i++) {
bits_unpacked[i] = srslte_bit_unpack(&bits_packed, 8); bits_unpacked[i] = srslte_bit_pack(&bits_packed, 8);
} }
if (nof_bits%8) { if (nof_bits%8) {
bits_unpacked[i] = srslte_bit_unpack(&bits_packed, nof_bits%8); bits_unpacked[i] = srslte_bit_pack(&bits_packed, nof_bits%8);
} }
} }
uint32_t srslte_bit_unpack(uint8_t **bits, int nof_bits) uint32_t srslte_bit_pack(uint8_t **bits, int nof_bits)
{ {
int i; int i;
uint32_t value=0; uint32_t value=0;
@ -87,7 +87,7 @@ uint32_t srslte_bit_unpack(uint8_t **bits, int nof_bits)
return value; return value;
} }
uint64_t srslte_bit_unpack_l(uint8_t **bits, int nof_bits) uint64_t srslte_bit_pack_l(uint8_t **bits, int nof_bits)
{ {
int i; int i;
uint64_t value=0; uint64_t value=0;

@ -326,11 +326,11 @@ void srslte_vec_fprint_hex(FILE *stream, uint8_t *x, uint32_t len) {
nbytes = len/8; nbytes = len/8;
fprintf(stream, "[", len); fprintf(stream, "[", len);
for (i=0;i<nbytes;i++) { for (i=0;i<nbytes;i++) {
byte = (uint8_t) srslte_bit_unpack(&x, 8); byte = (uint8_t) srslte_bit_pack(&x, 8);
fprintf(stream, "%02x ", byte); fprintf(stream, "%02x ", byte);
} }
if (len%8) { if (len%8) {
byte = (uint8_t) srslte_bit_unpack(&x, len%8); byte = (uint8_t) srslte_bit_pack(&x, len%8);
fprintf(stream, "%02x ", byte); fprintf(stream, "%02x ", byte);
} }
fprintf(stream, "];\n"); fprintf(stream, "];\n");

Loading…
Cancel
Save