From 4cdbed47f23dbcc331351d76c621b7639d96f6ee Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Thu, 20 Oct 2016 11:57:59 +0200 Subject: [PATCH] pucch receiver tested --- srslte/include/srslte/enb/enb_ul.h | 6 +- srslte/include/srslte/phch/pucch.h | 11 +-- srslte/lib/enb/enb_ul.c | 110 +++++++++++++++++++---------- srslte/lib/phch/pucch.c | 19 ++++- 4 files changed, 98 insertions(+), 48 deletions(-) diff --git a/srslte/include/srslte/enb/enb_ul.h b/srslte/include/srslte/enb/enb_ul.h index 59fd02065..8c1af2eea 100644 --- a/srslte/include/srslte/enb/enb_ul.h +++ b/srslte/include/srslte/enb/enb_ul.h @@ -81,6 +81,7 @@ typedef struct SRSLTE_API { bool *srs_cfg_en; srslte_uci_cfg_t *uci_cfg; srslte_refsignal_srs_cfg_t *srs_cfg; + srslte_pucch_sched_t *pucch_sched; } srslte_enb_ul_t; @@ -113,6 +114,7 @@ SRSLTE_API int srslte_enb_ul_cfg_rnti(srslte_enb_ul_t *q, SRSLTE_API int srslte_enb_ul_cfg_ue(srslte_enb_ul_t *q, uint32_t idx, srslte_uci_cfg_t *uci_cfg, + srslte_pucch_sched_t *pucch_sched, srslte_refsignal_srs_cfg_t *srs_cfg); @@ -124,10 +126,10 @@ SRSLTE_API void srslte_enb_ul_fft(srslte_enb_ul_t *q, SRSLTE_API int srslte_enb_ul_get_pucch(srslte_enb_ul_t *q, srslte_pucch_format_t format, - uint32_t n_pucch, + uint32_t pdcch_n_cce, uint32_t rnti_idx, srslte_uci_data_t *uci_data, - uint32_t tti); + uint32_t sf_rx); SRSLTE_API int srslte_enb_ul_get_pusch(srslte_enb_ul_t *q, srslte_ra_ul_grant_t *grant, diff --git a/srslte/include/srslte/phch/pucch.h b/srslte/include/srslte/phch/pucch.h index 66062b057..4c7921dea 100644 --- a/srslte/include/srslte/phch/pucch.h +++ b/srslte/include/srslte/phch/pucch.h @@ -43,7 +43,7 @@ #define SRSLTE_PUCCH_N_SEQ 12 #define SRSLTE_PUCCH_MAX_BITS SRSLTE_CQI_MAX_BITS -#define SRSLTE_PUCCH_MAX_SYMBOLS 120 +#define SRSLTE_PUCCH_MAX_SYMBOLS 120 typedef enum SRSLTE_API { SRSLTE_PUCCH_FORMAT_1 = 0, @@ -68,6 +68,7 @@ typedef struct SRSLTE_API { uint32_t delta_pucch_shift; uint32_t n_rb_2; uint32_t N_cs; + uint32_t n1_pucch_an; // SRS configuration bool srs_configured; @@ -87,9 +88,11 @@ typedef struct SRSLTE_API { uint32_t n_cs_cell[SRSLTE_NSLOTS_X_FRAME][SRSLTE_CP_NORM_NSYMB]; uint32_t f_gh[SRSLTE_NSLOTS_X_FRAME]; float tmp_arg[SRSLTE_PUCCH_N_SEQ]; - cf_t z[SRSLTE_PUCCH_MAX_SYMBOLS]; - cf_t z_tmp[SRSLTE_PUCCH_MAX_SYMBOLS]; - cf_t ce[SRSLTE_PUCCH_MAX_SYMBOLS]; + + cf_t *z; + cf_t *z_tmp; + cf_t *ce; + bool rnti_is_set; bool shortened; bool group_hopping_en; diff --git a/srslte/lib/enb/enb_ul.c b/srslte/lib/enb/enb_ul.c index a558b28e7..64679fc1b 100644 --- a/srslte/lib/enb/enb_ul.c +++ b/srslte/lib/enb/enb_ul.c @@ -62,11 +62,12 @@ int srslte_enb_ul_init(srslte_enb_ul_t *q, srslte_cell_t cell, memcpy(&q->hopping_cfg, hopping_cfg, sizeof(srslte_pusch_hopping_cfg_t)); } - q->uci_cfg_en = calloc(sizeof(bool),nof_rnti); - q->srs_cfg_en = calloc(sizeof(bool),nof_rnti); + q->uci_cfg_en = calloc(sizeof(bool), nof_rnti); + q->srs_cfg_en = calloc(sizeof(bool), nof_rnti); - q->uci_cfg = calloc(sizeof(srslte_uci_cfg_t),nof_rnti); - q->srs_cfg = calloc(sizeof(srslte_refsignal_srs_cfg_t),nof_rnti); + q->uci_cfg = calloc(sizeof(srslte_uci_cfg_t), nof_rnti); + q->srs_cfg = calloc(sizeof(srslte_refsignal_srs_cfg_t), nof_rnti); + q->pucch_sched = calloc(sizeof(srslte_pucch_sched_t), nof_rnti); if (srslte_ofdm_rx_init(&q->fft, q->cell.cp, q->cell.nof_prb)) { fprintf(stderr, "Error initiating FFT\n"); @@ -97,6 +98,8 @@ int srslte_enb_ul_init(srslte_enb_ul_t *q, srslte_cell_t cell, srslte_prach_set_detect_factor(&q->prach, 60); + srslte_pucch_set_threshold(&q->pucch, 0.5, 0.5); + if (srslte_chest_ul_init(&q->chest, cell)) { fprintf(stderr, "Error initiating channel estimator\n"); goto clean_exit; @@ -150,6 +153,9 @@ void srslte_enb_ul_free(srslte_enb_ul_t *q) if (q->srs_cfg_en) { free(q->srs_cfg_en); } + if (q->pucch_sched) { + free(q->pucch_sched); + } srslte_prach_free(&q->prach); srslte_ofdm_rx_free(&q->fft); @@ -173,6 +179,7 @@ int srslte_enb_ul_cfg_rnti(srslte_enb_ul_t *q, uint32_t idx, uint16_t rnti) int srslte_enb_ul_cfg_ue(srslte_enb_ul_t *q, uint32_t idx, srslte_uci_cfg_t *uci_cfg, + srslte_pucch_sched_t *pucch_sched, srslte_refsignal_srs_cfg_t *srs_cfg) { if (idx < q->nof_rnti) { @@ -182,6 +189,10 @@ int srslte_enb_ul_cfg_ue(srslte_enb_ul_t *q, uint32_t idx, } else { q->uci_cfg_en[idx] = false; } + if (pucch_sched) { + printf("saving sched for idx=%d, N_pucch_1=%d\n", idx, pucch_sched->N_pucch_1); + memcpy(&q->pucch_sched[idx], pucch_sched, sizeof(srslte_pucch_sched_t)); + } if (srs_cfg) { memcpy(&q->srs_cfg[idx], srs_cfg, sizeof(srslte_refsignal_srs_cfg_t)); q->srs_cfg_en[idx] = true; @@ -205,44 +216,65 @@ void srslte_enb_ul_fft(srslte_enb_ul_t *q, cf_t *signal_buffer) srslte_ofdm_rx_sf(&q->fft, signal_buffer, q->sf_symbols); } -int srslte_enb_ul_get_pucch(srslte_enb_ul_t *q, srslte_pucch_format_t format, uint32_t n_pucch, - uint32_t rnti_idx, srslte_uci_data_t *uci_data, uint32_t tti) +int srslte_enb_ul_get_pucch(srslte_enb_ul_t *q, srslte_pucch_format_t format, uint32_t pdcch_n_cce, + uint32_t rnti_idx, srslte_uci_data_t *uci_data, uint32_t sf_rx) { - - if (srslte_chest_ul_estimate_pucch(&q->chest, q->sf_symbols, q->ce, format, n_pucch, tti%10)) { - fprintf(stderr,"Error estimating PUCCH DMRS\n"); - return SRSLTE_ERROR; - } - - float noise_power = srslte_chest_ul_get_noise_estimate(&q->chest); - - uint8_t bits[SRSLTE_PUCCH_MAX_BITS]; - if (srslte_pucch_decode(&q->pucch, format, n_pucch, tti%10, q->sf_symbols, q->ce, noise_power, bits)) { - fprintf(stderr,"Error decoding PUCCH\n"); + + if (rnti_idx < q->nof_rnti) { + uint32_t n_pucch = 0; + switch(format) { + case SRSLTE_PUCCH_FORMAT_1: + n_pucch = q->pucch_sched[rnti_idx].n_pucch_sr; + break; + case SRSLTE_PUCCH_FORMAT_1A: + case SRSLTE_PUCCH_FORMAT_1B: + n_pucch = pdcch_n_cce + q->pucch_sched[rnti_idx].N_pucch_1; + break; + default: + fprintf(stderr, "Error getting PUCCH format %d not supported\n", format); + return SRSLTE_ERROR; + } + + if (srslte_chest_ul_estimate_pucch(&q->chest, q->sf_symbols, q->ce, format, n_pucch, sf_rx)) { + fprintf(stderr,"Error estimating PUCCH DMRS\n"); + return SRSLTE_ERROR; + } + + float noise_power = srslte_chest_ul_get_noise_estimate(&q->chest); + + uint8_t bits[SRSLTE_PUCCH_MAX_BITS]; + if (srslte_pucch_decode(&q->pucch, format, n_pucch, sf_rx, q->sf_symbols, q->ce, noise_power, bits)) { + fprintf(stderr,"Error decoding PUCCH\n"); + return SRSLTE_ERROR; + } + + switch(format) { + case SRSLTE_PUCCH_FORMAT_1: + if (bits[0]) { + uci_data->scheduling_request = true; + } else { + uci_data->scheduling_request = false; + } + break; + case SRSLTE_PUCCH_FORMAT_1A: + case SRSLTE_PUCCH_FORMAT_1B: + uci_data->uci_ack = bits[0]; + uci_data->uci_ack_len = 1; + if (format == SRSLTE_PUCCH_FORMAT_1B) { + uci_data->uci_ack_2 = bits[0]; + uci_data->uci_ack_len = 2; + } + break; + default: + fprintf(stderr, "Error getting PUCCH format %d not supported\n", format); + return SRSLTE_ERROR; + } + + return SRSLTE_SUCCESS; + } else { + fprintf(stderr, "Invalid rnti_idx=%d\n", rnti_idx); return SRSLTE_ERROR; } - - switch(format) { - case SRSLTE_PUCCH_FORMAT_1: - if (bits[0]) { - uci_data->scheduling_request = true; - } - break; - case SRSLTE_PUCCH_FORMAT_1A: - case SRSLTE_PUCCH_FORMAT_1B: - uci_data->uci_ack = bits[0]; - uci_data->uci_ack_len = 1; - if (format == SRSLTE_PUCCH_FORMAT_1B) { - uci_data->uci_ack_2 = bits[0]; - uci_data->uci_ack_len = 2; - } - break; - default: - fprintf(stderr, "Error getting PUCCH format %d not supported\n", format); - return SRSLTE_ERROR; - } - - return SRSLTE_SUCCESS; } int srslte_enb_ul_get_pusch(srslte_enb_ul_t *q, srslte_ra_ul_grant_t *grant, srslte_softbuffer_rx_t *softbuffer, diff --git a/srslte/lib/phch/pucch.c b/srslte/lib/phch/pucch.c index 30fdb66b7..b066f337a 100644 --- a/srslte/lib/phch/pucch.c +++ b/srslte/lib/phch/pucch.c @@ -370,6 +370,10 @@ int srslte_pucch_init(srslte_pucch_t *q, srslte_cell_t cell) { if (srslte_pucch_n_cs_cell(q->cell, q->n_cs_cell)) { return SRSLTE_ERROR; } + + q->z = srslte_vec_malloc(sizeof(cf_t)*SRSLTE_PUCCH_MAX_SYMBOLS); + q->z_tmp = srslte_vec_malloc(sizeof(cf_t)*SRSLTE_PUCCH_MAX_SYMBOLS); + q->ce = srslte_vec_malloc(sizeof(cf_t)*SRSLTE_PUCCH_MAX_SYMBOLS); ret = SRSLTE_SUCCESS; } @@ -382,6 +386,16 @@ void srslte_pucch_free(srslte_pucch_t *q) { srslte_sequence_free(&q->seq_f2[sf_idx]); } } + if (q->z) { + free(q->z); + } + if (q->z_tmp) { + free(q->z_tmp); + } + if (q->ce) { + free(q->ce); + } + srslte_modem_table_free(&q->mod); bzero(q, sizeof(srslte_pucch_t)); } @@ -645,7 +659,7 @@ int srslte_pucch_decode(srslte_pucch_t* q, srslte_pucch_format_t format, } else { bits[0] = 0; } - printf("format1 corr=%f, nof_re=%d, th=%f\n", corr, nof_re, q->threshold_format1); + DEBUG("format1 corr=%f, nof_re=%d, th=%f\n", corr, nof_re, q->threshold_format1); break; case SRSLTE_PUCCH_FORMAT_1A: bzero(bits, SRSLTE_PUCCH_MAX_BITS*sizeof(uint8_t)); @@ -658,7 +672,7 @@ int srslte_pucch_decode(srslte_pucch_t* q, srslte_pucch_format_t format, corr_max = corr; b_max = b; } - DEBUG("format1a b=%d, corr=%f, nof_re=%d, th=%f\n", b, corr, nof_re, q->threshold_format1); + DEBUG("format1a b=%d, corr=%f, nof_re=%d, th=%f\n", b, corr, nof_re, q->threshold_format1a); } bits[0] = b_max; break; @@ -666,7 +680,6 @@ int srslte_pucch_decode(srslte_pucch_t* q, srslte_pucch_format_t format, fprintf(stderr, "Error decoding PUCCH: Format %d not supported\n", format); break; } - ret = SRSLTE_SUCCESS; }