From 94f2e84f0997d15fe4061db3157c3d69060c33ef Mon Sep 17 00:00:00 2001 From: ismagom Date: Wed, 8 Apr 2015 19:47:52 +0100 Subject: [PATCH] PBCH decoding assumes number of ports when they are known --- srslte/examples/cell_measurement.c | 2 +- srslte/examples/cuhd_utils.c | 2 +- srslte/examples/pdsch_enodeb.c | 2 +- srslte/examples/pdsch_ue.c | 5 +- srslte/examples/prach_ue.c | 4 +- srslte/include/srslte/common/phy_common.h | 3 +- srslte/include/srslte/phch/pbch.h | 29 ++++---- srslte/include/srslte/ue/ue_mib.h | 13 ++-- srslte/lib/common/src/phy_common.c | 27 +++++++- srslte/lib/phch/src/pbch.c | 81 ++++++++++------------- srslte/lib/phch/test/pbch_file_test.c | 8 +-- srslte/lib/phch/test/pbch_test.c | 10 +-- srslte/lib/ue/src/ue_mib.c | 26 +++++--- srslte/tutorial_examples/ue_rx.c | 4 +- 14 files changed, 117 insertions(+), 99 deletions(-) diff --git a/srslte/examples/cell_measurement.c b/srslte/examples/cell_measurement.c index 132c46854..3f0edb044 100644 --- a/srslte/examples/cell_measurement.c +++ b/srslte/examples/cell_measurement.c @@ -145,7 +145,7 @@ int main(int argc, char **argv) { uint32_t nof_trials = 0; uint32_t sfn = 0; // system frame number int n; - uint8_t bch_payload[BCH_PAYLOAD_LEN]; + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; uint32_t sfn_offset; float rssi_utra=0,rssi=0, rsrp=0, rsrq=0, snr=0; cf_t *ce[SRSLTE_MAX_PORTS]; diff --git a/srslte/examples/cuhd_utils.c b/srslte/examples/cuhd_utils.c index 2a3f27ccb..ab709593f 100644 --- a/srslte/examples/cuhd_utils.c +++ b/srslte/examples/cuhd_utils.c @@ -53,7 +53,7 @@ int cuhd_recv_wrapper_cs(void *h, void *data, uint32_t nsamples, srslte_timestam int cuhd_mib_decoder(void *uhd, uint32_t max_nof_frames, srslte_cell_t *cell) { int ret = SRSLTE_ERROR; srslte_ue_mib_sync_t ue_mib; - uint8_t bch_payload[BCH_PAYLOAD_LEN]; + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; if (srslte_ue_mib_sync_init(&ue_mib, cell->id, cell->cp, cuhd_recv_wrapper_cs, uhd)) { fprintf(stderr, "Error initiating srslte_ue_mib_sync\n"); diff --git a/srslte/examples/pdsch_enodeb.c b/srslte/examples/pdsch_enodeb.c index cdac42bcc..9eaeec9da 100644 --- a/srslte/examples/pdsch_enodeb.c +++ b/srslte/examples/pdsch_enodeb.c @@ -442,7 +442,7 @@ int main(int argc, char **argv) { cf_t pss_signal[SRSLTE_PSS_LEN]; float sss_signal0[SRSLTE_SSS_LEN]; // for subframe 0 float sss_signal5[SRSLTE_SSS_LEN]; // for subframe 5 - uint8_t bch_payload[BCH_PAYLOAD_LEN]; + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; int i; cf_t *sf_symbols[SRSLTE_MAX_PORTS]; cf_t *slot1_symbols[SRSLTE_MAX_PORTS]; diff --git a/srslte/examples/pdsch_ue.c b/srslte/examples/pdsch_ue.c index ecb1af658..32187a323 100644 --- a/srslte/examples/pdsch_ue.c +++ b/srslte/examples/pdsch_ue.c @@ -247,7 +247,7 @@ int main(int argc, char **argv) { #endif uint32_t nof_trials = 0; int n; - uint8_t bch_payload[BCH_PAYLOAD_LEN]; + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; uint32_t sfn_offset; parse_args(&prog_args, argc, argv); @@ -369,6 +369,7 @@ int main(int argc, char **argv) { bool decode_pdsch; int pdcch_tx=0; + INFO("\nEntering main loop...\n\n", 0); /* Main loop */ while (!go_exit && (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1)) { @@ -389,7 +390,7 @@ int main(int argc, char **argv) { exit(-1); } else if (n == SRSLTE_UE_MIB_FOUND) { srslte_pbch_mib_unpack(bch_payload, &cell, &sfn); - srslte_pbch_mib_fprint(stdout, &cell, sfn, cell.id); + srslte_cell_fprint(stdout, &cell, sfn); printf("Decoded MIB. SFN: %d, offset: %d\n", sfn, sfn_offset); sfn = (sfn + sfn_offset)%1024; state = DECODE_PDSCH; diff --git a/srslte/examples/prach_ue.c b/srslte/examples/prach_ue.c index cb9401bd3..c2f87a268 100644 --- a/srslte/examples/prach_ue.c +++ b/srslte/examples/prach_ue.c @@ -295,7 +295,7 @@ int main(int argc, char **argv) { srslte_ue_mib_t ue_mib; void *uhd; int n; - uint8_t bch_payload[BCH_PAYLOAD_LEN]; + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; uint32_t sfn_offset; rar_msg_t rar_msg; srslte_ra_pusch_t ra_pusch; @@ -476,7 +476,7 @@ int main(int argc, char **argv) { exit(-1); } else if (n == SRSLTE_UE_MIB_FOUND) { srslte_pbch_mib_unpack(bch_payload, &cell, &sfn); - srslte_pbch_mib_fprint(stdout, &cell, sfn, cell.id); + srslte_cell_fprint(stdout, &cell, sfn); printf("Decoded MIB. SFN: %d, offset: %d\n", sfn, sfn_offset); sfn = (sfn + sfn_offset)%1024; state = SEND_PRACH; diff --git a/srslte/include/srslte/common/phy_common.h b/srslte/include/srslte/common/phy_common.h index b95d271fb..aafa98134 100644 --- a/srslte/include/srslte/common/phy_common.h +++ b/srslte/include/srslte/common/phy_common.h @@ -182,7 +182,8 @@ enum band_geographical_area { SRSLTE_API bool srslte_cell_isvalid(srslte_cell_t *cell); SRSLTE_API void srslte_cell_fprint(FILE *stream, - srslte_cell_t *cell); + srslte_cell_t *cell, + uint32_t sfn); SRSLTE_API bool srslte_cellid_isvalid(uint32_t cell_id); diff --git a/srslte/include/srslte/phch/pbch.h b/srslte/include/srslte/phch/pbch.h index cafeaa5e2..63b38c5ad 100644 --- a/srslte/include/srslte/phch/pbch.h +++ b/srslte/include/srslte/phch/pbch.h @@ -28,7 +28,9 @@ /****************************************************************************** * File: pbch.h * - * Description: Physical broadcast channel. + * Description: Physical broadcast channel. If cell.nof_ports = 0, the number + * of ports is blindly determined using the CRC of the received + * codeword for 1, 2 and 4 ports * * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.6 *****************************************************************************/ @@ -48,12 +50,9 @@ #include "srslte/fec/viterbi.h" #include "srslte/fec/crc.h" -#define BCH_PAYLOAD_LEN 24 -#define BCH_PAYLOADCRC_LEN (BCH_PAYLOAD_LEN+16) -#define BCH_ENCODED_LEN 3*(BCH_PAYLOADCRC_LEN) - -#define PBCH_RE_SRSLTE_CP_NORM 240 -#define PBCH_RE_SRSLTE_CP_EXT 216 +#define SRSLTE_BCH_PAYLOAD_LEN 24 +#define SRSLTE_BCH_PAYLOADCRC_LEN (SRSLTE_BCH_PAYLOAD_LEN+16) +#define SRSLTE_BCH_ENCODED_LEN 3*(SRSLTE_BCH_PAYLOADCRC_LEN) /* PBCH object */ typedef struct SRSLTE_API { @@ -68,10 +67,10 @@ typedef struct SRSLTE_API { cf_t *d; float *llr; float *temp; - float rm_f[BCH_ENCODED_LEN]; + float rm_f[SRSLTE_BCH_ENCODED_LEN]; uint8_t *rm_b; - uint8_t data[BCH_PAYLOADCRC_LEN]; - uint8_t data_enc[BCH_ENCODED_LEN]; + uint8_t data[SRSLTE_BCH_PAYLOADCRC_LEN]; + uint8_t data_enc[SRSLTE_BCH_ENCODED_LEN]; uint32_t frame_idx; @@ -83,6 +82,7 @@ typedef struct SRSLTE_API { srslte_crc_t crc; srslte_convcoder_t encoder; srslte_precoding_t precoding; + bool search_all_ports; } srslte_pbch_t; @@ -94,12 +94,12 @@ SRSLTE_API int srslte_pbch_decode(srslte_pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[SRSLTE_MAX_PORTS], float noise_estimate, - uint8_t bch_payload[BCH_PAYLOAD_LEN], + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, uint32_t *sfn_offset); SRSLTE_API int srslte_pbch_encode(srslte_pbch_t *q, - uint8_t bch_payload[BCH_PAYLOAD_LEN], + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], cf_t *slot1_symbols[SRSLTE_MAX_PORTS]); SRSLTE_API void srslte_pbch_decode_reset(srslte_pbch_t *q); @@ -112,9 +112,4 @@ SRSLTE_API void srslte_pbch_mib_pack(srslte_cell_t *cell, uint32_t sfn, uint8_t *msg); -SRSLTE_API void srslte_pbch_mib_fprint(FILE *stream, - srslte_cell_t *cell, - uint32_t sfn, - uint32_t cell_id); - #endif // PBCH_ diff --git a/srslte/include/srslte/ue/ue_mib.h b/srslte/include/srslte/ue/ue_mib.h index ef77cadc5..6d363a155 100644 --- a/srslte/include/srslte/ue/ue_mib.h +++ b/srslte/include/srslte/ue/ue_mib.h @@ -36,7 +36,7 @@ * * The function uses the sync_t object to find the PSS sequence and * decode the PBCH to obtain the MIB. - * + * * The function returns 0 until the MIB is decoded. * * See ue_cell_detect.c for an example. @@ -57,7 +57,6 @@ #include "srslte/dft/ofdm.h" -#define SRSLTE_UE_MIB_MAX_PORTS 4 #define SRSLTE_UE_MIB_NOF_PRB 6 #define SRSLTE_UE_MIB_FOUND 1 @@ -67,13 +66,13 @@ typedef struct SRSLTE_API { srslte_sync_t sfind; cf_t *sf_symbols; - cf_t *ce[SRSLTE_UE_MIB_MAX_PORTS]; + cf_t *ce[SRSLTE_MAX_PORTS]; srslte_ofdm_t fft; srslte_chest_dl_t chest; srslte_pbch_t pbch; - uint8_t bch_payload[BCH_PAYLOAD_LEN]; + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; uint32_t nof_tx_ports; uint32_t sfn_offset; @@ -89,13 +88,15 @@ SRSLTE_API void srslte_ue_mib_reset(srslte_ue_mib_t * q); SRSLTE_API int srslte_ue_mib_decode(srslte_ue_mib_t * q, cf_t *input, - uint8_t bch_payload[BCH_PAYLOAD_LEN], + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, uint32_t *sfn_offset); /* This interface uses ue_mib and ue_sync to first get synchronized subframes * and then decode MIB + * + * This object calls the pbch object with nof_ports=0 for blind nof_ports determination */ typedef struct { srslte_ue_mib_t ue_mib; @@ -114,7 +115,7 @@ SRSLTE_API void srslte_ue_mib_sync_reset(srslte_ue_mib_sync_t * q); SRSLTE_API int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t * q, uint32_t max_frames_timeout, - uint8_t bch_payload[BCH_PAYLOAD_LEN], + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, uint32_t *sfn_offset); diff --git a/srslte/lib/common/src/phy_common.c b/srslte/lib/common/src/phy_common.c index 2faadb5eb..c14c9df4d 100644 --- a/srslte/lib/common/src/phy_common.c +++ b/srslte/lib/common/src/phy_common.c @@ -75,8 +75,31 @@ bool srslte_cell_isvalid(srslte_cell_t *cell) { srslte_nofprb_isvalid(cell->nof_prb); } -void srslte_cell_fprint(FILE *stream, srslte_cell_t *cell) { - fprintf(stream, "PCI: %d, CP: %s, PRB: %d, Ports: %d\n", cell->id, srslte_cp_string(cell->cp), cell->nof_prb, cell->nof_ports); +void srslte_cell_fprint(FILE *stream, srslte_cell_t *cell, uint32_t sfn) { + fprintf(stream, " - Cell ID: %d\n", cell->id); + fprintf(stream, " - Nof ports: %d\n", cell->nof_ports); + fprintf(stream, " - CP: %s\n", srslte_cp_string(cell->cp)); + fprintf(stream, " - PRB: %d\n", cell->nof_prb); + fprintf(stream, " - PHICH Length: %s\n", + cell->phich_length == SRSLTE_PHICH_EXT ? "Extended" : "Normal"); + fprintf(stream, " - PHICH Resources: "); + switch (cell->phich_resources) { + case SRSLTE_PHICH_SRSLTE_PHICH_R_1_6: + fprintf(stream, "1/6"); + break; + case SRSLTE_PHICH_SRSLTE_PHICH_R_1_2: + fprintf(stream, "1/2"); + break; + case SRSLTE_PHICH_R_1: + fprintf(stream, "1"); + break; + case SRSLTE_PHICH_R_2: + fprintf(stream, "2"); + break; + } + fprintf(stream, "\n"); + fprintf(stream, " - SFN: %d\n", sfn); + } bool srslte_sfidx_isvalid(uint32_t sf_idx) { diff --git a/srslte/lib/phch/src/pbch.c b/srslte/lib/phch/src/pbch.c index 5cdd0247f..6587bb2f7 100644 --- a/srslte/lib/phch/src/pbch.c +++ b/srslte/lib/phch/src/pbch.c @@ -41,6 +41,10 @@ #include "srslte/utils/vector.h" #include "srslte/utils/debug.h" +#define PBCH_RE_CP_NORM 240 +#define PBCH_RE_CP_EXT 216 + + const uint8_t srslte_crc_mask[4][16] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, @@ -137,8 +141,16 @@ int srslte_pbch_init(srslte_pbch_t *q, srslte_cell_t cell) { ret = SRSLTE_ERROR; bzero(q, sizeof(srslte_pbch_t)); + + if (cell.nof_ports == 0) { + q->search_all_ports = true; + cell.nof_ports = SRSLTE_MAX_PORTS; + } else { + q->search_all_ports = false; + } + q->cell = cell; - q->nof_symbols = (SRSLTE_CP_ISNORM(q->cell.cp)) ? PBCH_RE_SRSLTE_CP_NORM : PBCH_RE_SRSLTE_CP_EXT; + q->nof_symbols = (SRSLTE_CP_ISNORM(q->cell.cp)) ? PBCH_RE_CP_NORM : PBCH_RE_CP_EXT; if (srslte_precoding_init(&q->precoding, SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp))) { fprintf(stderr, "Error initializing precoding\n"); @@ -326,32 +338,6 @@ void srslte_pbch_mib_pack(srslte_cell_t *cell, uint32_t sfn, uint8_t *msg) { srslte_bit_pack(sfn >> 2, &msg, 8); } -void srslte_pbch_mib_fprint(FILE *stream, srslte_cell_t *cell, uint32_t sfn, uint32_t cell_id) { - printf(" - Cell ID: %d\n", cell_id); - printf(" - Nof ports: %d\n", cell->nof_ports); - printf(" - PRB: %d\n", cell->nof_prb); - printf(" - PHICH Length: %s\n", - cell->phich_length == SRSLTE_PHICH_EXT ? "Extended" : "Normal"); - printf(" - PHICH Resources: "); - switch (cell->phich_resources) { - case SRSLTE_PHICH_SRSLTE_PHICH_R_1_6: - printf("1/6"); - break; - case SRSLTE_PHICH_SRSLTE_PHICH_R_1_2: - printf("1/2"); - break; - case SRSLTE_PHICH_R_1: - printf("1"); - break; - case SRSLTE_PHICH_R_2: - printf("2"); - break; - } - printf("\n"); - printf(" - SFN: %d\n", sfn); -} - - void srslte_pbch_decode_reset(srslte_pbch_t *q) { q->frame_idx = 0; } @@ -359,9 +345,8 @@ void srslte_pbch_decode_reset(srslte_pbch_t *q) { void srslte_crc_set_mask(uint8_t *data, int nof_ports) { int i; for (i = 0; i < 16; i++) { - data[BCH_PAYLOAD_LEN + i] = (data[BCH_PAYLOAD_LEN + i] + srslte_crc_mask[nof_ports - 1][i]) % 2; + data[SRSLTE_BCH_PAYLOAD_LEN + i] = (data[SRSLTE_BCH_PAYLOAD_LEN + i] + srslte_crc_mask[nof_ports - 1][i]) % 2; } - } /* Checks CRC after applying the mask for the given number of ports. @@ -371,13 +356,13 @@ void srslte_crc_set_mask(uint8_t *data, int nof_ports) { * Returns 0 if the data is correct, -1 otherwise */ uint32_t srslte_pbch_crc_check(srslte_pbch_t *q, uint8_t *bits, uint32_t nof_ports) { - uint8_t data[BCH_PAYLOADCRC_LEN]; - memcpy(data, bits, BCH_PAYLOADCRC_LEN * sizeof(uint8_t)); + uint8_t data[SRSLTE_BCH_PAYLOADCRC_LEN]; + memcpy(data, bits, SRSLTE_BCH_PAYLOADCRC_LEN * sizeof(uint8_t)); srslte_crc_set_mask(data, nof_ports); - int ret = srslte_crc_checksum(&q->crc, data, BCH_PAYLOADCRC_LEN); + int ret = srslte_crc_checksum(&q->crc, data, SRSLTE_BCH_PAYLOADCRC_LEN); if (ret == 0) { uint32_t chkzeros=0; - for (int i=0;itemp, 4 * nof_bits, q->rm_f, BCH_ENCODED_LEN); + srslte_rm_conv_rx(q->temp, 4 * nof_bits, q->rm_f, SRSLTE_BCH_ENCODED_LEN); /* decode */ - srslte_viterbi_decode_f(&q->decoder, q->rm_f, q->data, BCH_PAYLOADCRC_LEN); + srslte_viterbi_decode_f(&q->decoder, q->rm_f, q->data, SRSLTE_BCH_PAYLOADCRC_LEN); if (!srslte_pbch_crc_check(q, q->data, nof_ports)) { return 1; @@ -432,7 +417,7 @@ int decode_frame(srslte_pbch_t *q, uint32_t src, uint32_t dst, uint32_t n, * Returns 1 if successfully decoded MIB, 0 if not and -1 on error */ int srslte_pbch_decode(srslte_pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[SRSLTE_MAX_PORTS], float noise_estimate, - uint8_t bch_payload[BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, uint32_t *sfn_offset) + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, uint32_t *sfn_offset) { uint32_t src, dst, nb; uint32_t nant; @@ -478,7 +463,12 @@ int srslte_pbch_decode(srslte_pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[SRS ret = 0; /* Try decoding for 1 to cell.nof_ports antennas */ - for (nant = 1; nant <= q->cell.nof_ports && !ret; nant++) { + if (q->search_all_ports) { + nant = 1; + } else { + nant = q->cell.nof_ports; + } + do { if (nant != 3) { DEBUG("Trying %d TX antennas with %d frames\n", nant, q->frame_idx); @@ -517,15 +507,16 @@ int srslte_pbch_decode(srslte_pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[SRS *nof_tx_ports = nant; } if (bch_payload) { - memcpy(bch_payload, q->data, sizeof(uint8_t) * BCH_PAYLOAD_LEN); + memcpy(bch_payload, q->data, sizeof(uint8_t) * SRSLTE_BCH_PAYLOAD_LEN); } } } } } } - } - + nant++; + } while(nant <= q->cell.nof_ports && !ret); + /* If not found, make room for the next packet of radio frame symbols */ if (q->frame_idx == 4) { memmove(q->llr, &q->llr[nof_bits], nof_bits * 3 * sizeof(float)); @@ -537,7 +528,7 @@ int srslte_pbch_decode(srslte_pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[SRS /** Converts the MIB message to symbols mapped to SLOT #1 ready for transmission */ -int srslte_pbch_encode(srslte_pbch_t *q, uint8_t bch_payload[BCH_PAYLOAD_LEN], cf_t *slot1_symbols[SRSLTE_MAX_PORTS]) { +int srslte_pbch_encode(srslte_pbch_t *q, uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], cf_t *slot1_symbols[SRSLTE_MAX_PORTS]) { int i; int nof_bits; cf_t *x[SRSLTE_MAX_LAYERS]; @@ -560,15 +551,15 @@ int srslte_pbch_encode(srslte_pbch_t *q, uint8_t bch_payload[BCH_PAYLOAD_LEN], c memset(&x[q->cell.nof_ports], 0, sizeof(cf_t*) * (SRSLTE_MAX_LAYERS - q->cell.nof_ports)); if (q->frame_idx == 0) { - memcpy(q->data, bch_payload, sizeof(uint8_t) * BCH_PAYLOAD_LEN); + memcpy(q->data, bch_payload, sizeof(uint8_t) * SRSLTE_BCH_PAYLOAD_LEN); /* encode & modulate */ - srslte_crc_attach(&q->crc, q->data, BCH_PAYLOAD_LEN); + srslte_crc_attach(&q->crc, q->data, SRSLTE_BCH_PAYLOAD_LEN); srslte_crc_set_mask(q->data, q->cell.nof_ports); - srslte_convcoder_encode(&q->encoder, q->data, q->data_enc, BCH_PAYLOADCRC_LEN); + srslte_convcoder_encode(&q->encoder, q->data, q->data_enc, SRSLTE_BCH_PAYLOADCRC_LEN); - srslte_rm_conv_tx(q->data_enc, BCH_ENCODED_LEN, q->rm_b, 4 * nof_bits); + srslte_rm_conv_tx(q->data_enc, SRSLTE_BCH_ENCODED_LEN, q->rm_b, 4 * nof_bits); } srslte_scrambling_b_offset(&q->seq, &q->rm_b[q->frame_idx * nof_bits], diff --git a/srslte/lib/phch/test/pbch_file_test.c b/srslte/lib/phch/test/pbch_file_test.c index 09e71c946..439fe0103 100644 --- a/srslte/lib/phch/test/pbch_file_test.c +++ b/srslte/lib/phch/test/pbch_file_test.c @@ -47,7 +47,7 @@ srslte_cell_t cell = { int nof_frames = 1; -uint8_t bch_payload_file[BCH_PAYLOAD_LEN] = {0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +uint8_t bch_payload_file[SRSLTE_BCH_PAYLOAD_LEN] = {0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; #define FLEN (10*SRSLTE_SF_LEN(srslte_symbol_sz(cell.nof_prb))) @@ -171,7 +171,7 @@ void base_free() { } int main(int argc, char **argv) { - uint8_t bch_payload[BCH_PAYLOAD_LEN]; + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; int n; uint32_t nof_tx_ports, sfn_offset; cf_t *ce_slot1[SRSLTE_MAX_PORTS]; @@ -231,8 +231,8 @@ int main(int argc, char **argv) { exit(-1); } else { printf("MIB decoded OK. Nof ports: %d. SFN offset: %d Payload: ", nof_tx_ports, sfn_offset); - srslte_vec_fprint_hex(stdout, bch_payload, BCH_PAYLOAD_LEN); - if (nof_tx_ports == 2 && sfn_offset == 0 && !memcmp(bch_payload, bch_payload_file, BCH_PAYLOAD_LEN)) { + srslte_vec_fprint_hex(stdout, bch_payload, SRSLTE_BCH_PAYLOAD_LEN); + if (nof_tx_ports == 2 && sfn_offset == 0 && !memcmp(bch_payload, bch_payload_file, SRSLTE_BCH_PAYLOAD_LEN)) { printf("This is the signal.1.92M.dat file\n"); exit(0); } else { diff --git a/srslte/lib/phch/test/pbch_test.c b/srslte/lib/phch/test/pbch_test.c index ceee176ea..0a7b12941 100644 --- a/srslte/lib/phch/test/pbch_test.c +++ b/srslte/lib/phch/test/pbch_test.c @@ -77,7 +77,7 @@ void parse_args(int argc, char **argv) { int main(int argc, char **argv) { srslte_pbch_t pbch; - uint8_t bch_payload_tx[BCH_PAYLOAD_LEN], bch_payload_rx[BCH_PAYLOAD_LEN]; + uint8_t bch_payload_tx[SRSLTE_BCH_PAYLOAD_LEN], bch_payload_rx[SRSLTE_BCH_PAYLOAD_LEN]; int i, j; cf_t *ce[SRSLTE_MAX_PORTS]; int nof_re; @@ -111,7 +111,7 @@ int main(int argc, char **argv) { } srand(time(NULL)); - for (i=0;ipbch, cell)) { + fprintf(stderr, "Error initiating PBCH\n"); + goto clean_exit; + } + + if (cell.nof_ports == 0) { + cell.nof_ports = SRSLTE_MAX_PORTS; + } + q->sf_symbols = srslte_vec_malloc(SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t)); if (!q->sf_symbols) { perror("malloc"); @@ -70,10 +79,6 @@ int srslte_ue_mib_init(srslte_ue_mib_t * q, fprintf(stderr, "Error initializing reference signal\n"); goto clean_exit; } - if (srslte_pbch_init(&q->pbch, cell)) { - fprintf(stderr, "Error initiating PBCH\n"); - goto clean_exit; - } srslte_ue_mib_reset(q); ret = SRSLTE_SUCCESS; @@ -91,7 +96,7 @@ void srslte_ue_mib_free(srslte_ue_mib_t * q) if (q->sf_symbols) { free(q->sf_symbols); } - for (int i=0;ice[i]) { free(q->ce[i]); } @@ -113,7 +118,7 @@ void srslte_ue_mib_reset(srslte_ue_mib_t * q) } int srslte_ue_mib_decode(srslte_ue_mib_t * q, cf_t *input, - uint8_t bch_payload[BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, uint32_t *sfn_offset) + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, uint32_t *sfn_offset) { int ret = SRSLTE_SUCCESS; cf_t *ce_slot1[SRSLTE_MAX_PORTS]; @@ -163,7 +168,8 @@ int srslte_ue_mib_sync_init(srslte_ue_mib_sync_t *q, void *stream_handler) { srslte_cell_t cell; - cell.nof_ports = SRSLTE_UE_MIB_MAX_PORTS; + // If the ports are set to 0, ue_mib goes through 1, 2 and 4 ports to blindly detect nof_ports + cell.nof_ports = 0; cell.id = cell_id; cell.cp = cp; cell.nof_prb = SRSLTE_UE_MIB_NOF_PRB; @@ -193,7 +199,7 @@ void srslte_ue_mib_sync_reset(srslte_ue_mib_sync_t * q) { int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t * q, uint32_t max_frames_timeout, - uint8_t bch_payload[BCH_PAYLOAD_LEN], + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, uint32_t *sfn_offset) { diff --git a/srslte/tutorial_examples/ue_rx.c b/srslte/tutorial_examples/ue_rx.c index 5d6dcbd1d..3e8cfc69b 100644 --- a/srslte/tutorial_examples/ue_rx.c +++ b/srslte/tutorial_examples/ue_rx.c @@ -247,7 +247,7 @@ int main(int argc, char **argv) { #endif uint32_t nof_trials = 0; int n; - uint8_t bch_payload[BCH_PAYLOAD_LEN]; + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; uint32_t sfn_offset; parse_args(&prog_args, argc, argv); @@ -393,7 +393,7 @@ int main(int argc, char **argv) { exit(-1); } else if (n == SRSLTE_UE_MIB_FOUND) { srslte_pbch_mib_unpack(bch_payload, &cell, &sfn); - srslte_pbch_mib_fprint(stdout, &cell, sfn, cell.id); + srslte_cell_fprint(stdout, &cell, sfn); printf("Decoded MIB. SFN: %d, offset: %d\n", sfn, sfn_offset); sfn = (sfn + sfn_offset)%1024; state = DECODE_PDSCH;