Merged pbch changes master

This commit is contained in:
ismagom 2015-04-08 19:53:32 +01:00
commit 1bc01bc131
11 changed files with 104 additions and 81 deletions

View File

@ -51,7 +51,8 @@ char *output_file_name = NULL;
srslte_cell_t cell = {
6, // nof_prb
1, // nof_ports
1, // cell_id
0, // bw idx
0, // cell_id
SRSLTE_CP_NORM, // cyclic prefix
SRSLTE_PHICH_R_1, // PHICH resources
SRSLTE_PHICH_NORM // PHICH length
@ -64,7 +65,7 @@ uint32_t mcs_idx = 1, last_mcs_idx = 1;
int nof_frames = -1;
char *uhd_args = "";
float uhd_amp = 0.03, uhd_gain = 70.0, uhd_freq = 2400000000;
float uhd_amp = 0.8, uhd_gain = 70.0, uhd_freq = 2400000000;
bool null_file_sink=false;
srslte_filesink_t fsink;
@ -588,9 +589,6 @@ int main(int argc, char **argv) {
/* Transform to OFDM symbols */
srslte_ofdm_tx_sf(&ifft, sf_buffer, output_buffer);
float norm_factor = (float) cell.nof_prb/15/sqrtf(ra_dl.prb_alloc.slot[0].nof_prb);
srslte_vec_sc_prod_cfc(output_buffer, uhd_amp*norm_factor, output_buffer, SRSLTE_SF_LEN_PRB(cell.nof_prb));
/* send to file or usrp */
if (output_file_name) {
if (!null_file_sink) {
@ -599,7 +597,9 @@ int main(int argc, char **argv) {
usleep(1000);
} else {
#ifndef DISABLE_UHD
srslte_vec_sc_prod_cfc(output_buffer, uhd_amp, output_buffer, sf_n_samples);
// FIXME
float norm_factor = (float) cell.nof_prb/15/sqrtf(ra_dl.prb_alloc.slot[0].nof_prb);
srslte_vec_sc_prod_cfc(output_buffer, uhd_amp*norm_factor, output_buffer, SRSLTE_SF_LEN_PRB(cell.nof_prb));
cuhd_send(uhd, output_buffer, sf_n_samples, true);
#endif
}

View File

@ -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);
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;
@ -501,8 +502,12 @@ int main(int argc, char **argv) {
sf_cnt++;
} // Main loop
pthread_cancel(plot_thread);
pthread_join(plot_thread, NULL);
if (!prog_args.disable_plots) {
if (!pthread_kill(plot_thread, 0)) {
pthread_kill(plot_thread, SIGHUP);
pthread_join(plot_thread, NULL);
}
}
srslte_ue_dl_free(&ue_dl);
srslte_ue_sync_free(&ue_sync);

View File

@ -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);
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;

View File

@ -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);

View File

@ -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
*****************************************************************************/
@ -80,37 +82,35 @@ typedef struct SRSLTE_API {
srslte_crc_t crc;
srslte_convcoder_t encoder;
srslte_precoding_t precoding;
bool search_all_ports;
} srslte_pbch_t;
SRSLTE_API int srslte_pbch_init(srslte_pbch_t *q,
srslte_cell_t cell);
srslte_cell_t cell);
SRSLTE_API void srslte_pbch_free(srslte_pbch_t *q);
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[SRSLTE_BCH_PAYLOAD_LEN],
uint32_t *nof_tx_ports,
uint32_t *sfn_offset);
cf_t *slot1_symbols,
cf_t *ce_slot1[SRSLTE_MAX_PORTS],
float noise_estimate,
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[SRSLTE_BCH_PAYLOAD_LEN],
cf_t *slot1_symbols[SRSLTE_MAX_PORTS]);
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);
SRSLTE_API void srslte_pbch_mib_unpack(uint8_t *msg,
srslte_cell_t *cell,
uint32_t *sfn);
srslte_cell_t *cell,
uint32_t *sfn);
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 sfn,
uint8_t *msg);
#endif // PBCH_

View File

@ -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,7 +66,7 @@ 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;
@ -96,6 +95,8 @@ SRSLTE_API int srslte_ue_mib_decode(srslte_ue_mib_t * q,
/* 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;

View File

@ -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) {

View File

@ -44,7 +44,8 @@
#define PBCH_RE_CP_NORM 240
#define PBCH_RE_CP_EXT 216
const uint8_t crc_mask[4][16] = {
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 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
@ -140,6 +141,14 @@ 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_CP_NORM : PBCH_RE_CP_EXT;
@ -329,42 +338,15 @@ 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) {
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;
}
void crc_set_mask(uint8_t *data, int nof_ports) {
void srslte_crc_set_mask(uint8_t *data, int nof_ports) {
int i;
for (i = 0; i < 16; i++) {
data[SRSLTE_BCH_PAYLOAD_LEN + i] = (data[SRSLTE_BCH_PAYLOAD_LEN + i] + 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.
@ -376,7 +358,7 @@ void crc_set_mask(uint8_t *data, int nof_ports) {
uint32_t srslte_pbch_crc_check(srslte_pbch_t *q, uint8_t *bits, uint32_t nof_ports) {
uint8_t data[SRSLTE_BCH_PAYLOADCRC_LEN];
memcpy(data, bits, SRSLTE_BCH_PAYLOADCRC_LEN * sizeof(uint8_t));
crc_set_mask(data, nof_ports);
srslte_crc_set_mask(data, nof_ports);
int ret = srslte_crc_checksum(&q->crc, data, SRSLTE_BCH_PAYLOADCRC_LEN);
if (ret == 0) {
uint32_t chkzeros=0;
@ -481,11 +463,16 @@ 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);
/* in conctrol channels, only diversity is supported */
/* in control channels, only diversity is supported */
if (nant == 1) {
/* no need for layer demapping */
srslte_predecoding_single(&q->precoding, q->symbols[0], q->ce[0], q->d,
@ -527,8 +514,9 @@ int srslte_pbch_decode(srslte_pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[SRS
}
}
}
}
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));
@ -567,12 +555,11 @@ int srslte_pbch_encode(srslte_pbch_t *q, uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_
/* encode & modulate */
srslte_crc_attach(&q->crc, q->data, SRSLTE_BCH_PAYLOAD_LEN);
crc_set_mask(q->data, q->cell.nof_ports);
srslte_crc_set_mask(q->data, q->cell.nof_ports);
srslte_convcoder_encode(&q->encoder, q->data, q->data_enc, SRSLTE_BCH_PAYLOADCRC_LEN);
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],

View File

@ -37,17 +37,26 @@
#include "srslte/utils/vector.h"
int srslte_ue_mib_init(srslte_ue_mib_t * q,
srslte_cell_t cell)
srslte_cell_t cell)
{
int ret = SRSLTE_ERROR_INVALID_INPUTS;
if (q != NULL &&
cell.nof_ports <= SRSLTE_UE_MIB_MAX_PORTS)
cell.nof_ports <= SRSLTE_MAX_PORTS)
{
ret = SRSLTE_ERROR;
bzero(q, sizeof(srslte_ue_mib_t));
if (srslte_pbch_init(&q->pbch, 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;i<SRSLTE_UE_MIB_MAX_PORTS;i++) {
for (int i=0;i<SRSLTE_MAX_PORTS;i++) {
if (q->ce[i]) {
free(q->ce[i]);
}
@ -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;

View File

@ -160,7 +160,7 @@ int main(int argc, char *argv[])
exit(-1);
}
// Print MIB
srslte_pbch_mib_fprint(stdout, &cell, phy.get_current_tti()/10);
srslte_cell_fprint(stdout, &cell, phy.get_current_tti()/10);
// Set the current PHY cell to the detected cell
if (!phy.set_cell(cell)) {

View File

@ -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);
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;