int srslte_ue_dl_decode_phich(srslte_ue_dl_t* q, srslte_dl_sf_cfg_t* sf, srslte_ue_dl_cfg_t* cfg, srslte_phich_grant_t* grant, srslte_phich_res_t* result) { srslte_phich_resource_t n_phich; uint32_t sf_idx = sf->tti % 10; set_mi_value(q, sf, cfg); srslte_phich_calc(&q->phich, grant, &n_phich); INFO("Decoding PHICH sf_idx=%d, n_prb_lowest=%d, n_dmrs=%d, I_phich=%d, n_group=%d, n_seq=%d, Ngroups=%d, Nsf=%d\n", sf_idx, grant->n_prb_lowest, grant->n_dmrs, grant->I_phich, n_phich.ngroup, n_phich.nseq, srslte_phich_ngroups(&q->phich), srslte_phich_nsf(&q->phich)); if (!srslte_phich_decode(&q->phich, sf, &q->chest_res, n_phich, q->sf_symbols, result)) { INFO("Decoded PHICH %d with distance %f\n", result->ack_value, result->distance); return 0; } else { ERROR("Error decoding PHICH\n"); return -1; } }
/* Computes n_group and n_seq according to Section 9.1.2 in 36.213 and calls phich processing function */ bool srslte_ue_dl_decode_phich(srslte_ue_dl_t *q, uint32_t sf_idx, uint32_t n_prb_lowest, uint32_t n_dmrs) { uint8_t ack_bit; float distance; uint32_t Ngroups = srslte_phich_ngroups(&q->phich); uint32_t ngroup = (n_prb_lowest+n_dmrs)%Ngroups; uint32_t nseq = ((n_prb_lowest/Ngroups)+n_dmrs)%(2*srslte_phich_nsf(&q->phich)); DEBUG("Decoding PHICH sf_idx=%d, n_prb_lowest=%d, n_dmrs=%d, n_group=%d, n_seq=%d\n", sf_idx, n_prb_lowest, n_dmrs, ngroup, nseq); if (!srslte_phich_decode(&q->phich, q->sf_symbols, q->ce, 0, ngroup, nseq, sf_idx, &ack_bit, &distance)) { INFO("Decoded PHICH %d with distance %f\n", ack_bit, distance); } else { fprintf(stderr, "Error decoding PHICH\n"); return false; } if (ack_bit && distance > 1.5) { return true; } else { return false; } }
bool srslte_ue_dl_decode_phich(srslte_ue_dl_t *q, uint32_t sf_idx, uint32_t n_prb_lowest, uint32_t n_dmrs) { uint8_t ack_bit; float distance; uint32_t ngroup, nseq; srslte_phich_calc(&q->phich, n_prb_lowest, n_dmrs, &ngroup, &nseq); INFO("Decoding PHICH sf_idx=%d, n_prb_lowest=%d, n_dmrs=%d, n_group=%d, n_seq=%d, Ngroups=%d, Nsf=%d\n", sf_idx, n_prb_lowest, n_dmrs, ngroup, nseq, srslte_phich_ngroups(&q->phich), srslte_phich_nsf(&q->phich)); if (!srslte_phich_decode(&q->phich, q->sf_symbols_m, q->ce_m, 0, ngroup, nseq, sf_idx, &ack_bit, &distance)) { q->last_phich_corr = distance; INFO("Decoded PHICH %d with distance %f\n", ack_bit, distance); } else { fprintf(stderr, "Error decoding PHICH\n"); return false; } if (ack_bit) { return true; } else { return false; } }
int main(int argc, char **argv) { srslte_phich_t phich; srslte_regs_t regs; int i, j; cf_t *ce[SRSLTE_MAX_PORTS]; int nof_re; cf_t *slot_symbols[SRSLTE_MAX_PORTS]; uint8_t ack[50][SRSLTE_PHICH_NORM_NSEQUENCES], ack_rx; uint32_t nsf; float distance; int cid, max_cid; uint32_t ngroup, nseq, max_nseq; parse_args(argc,argv); max_nseq = SRSLTE_CP_ISNORM(cell.cp)?SRSLTE_PHICH_NORM_NSEQUENCES:SRSLTE_PHICH_EXT_NSEQUENCES; nof_re = SRSLTE_CP_NORM_NSYMB * cell.nof_prb * SRSLTE_NRE; /* init memory */ for (i=0;i<SRSLTE_MAX_PORTS;i++) { ce[i] = malloc(sizeof(cf_t) * nof_re); if (!ce[i]) { perror("malloc"); exit(-1); } for (j=0;j<nof_re;j++) { ce[i][j] = 1; } slot_symbols[i] = malloc(sizeof(cf_t) * nof_re); if (!slot_symbols[i]) { perror("malloc"); exit(-1); } } if (cell.id == 1000) { cid = 0; max_cid = 503; } else { cid = cell.id; max_cid = cell.id; } while(cid <= max_cid) { cell.id = cid; printf("Testing CellID=%d...\n", cid); if (srslte_regs_init(®s, cell)) { fprintf(stderr, "Error initiating regs\n"); exit(-1); } if (srslte_phich_init(&phich, ®s, cell)) { fprintf(stderr, "Error creating PBCH object\n"); exit(-1); } for (nsf=0;nsf<10;nsf++) { srslte_phich_reset(&phich, slot_symbols); /* Transmit all PHICH groups and sequence numbers */ for (ngroup=0;ngroup<srslte_phich_ngroups(&phich);ngroup++) { for (nseq=0;nseq<max_nseq;nseq++) { ack[ngroup][nseq] = rand()%2; srslte_phich_encode(&phich, ack[ngroup][nseq], ngroup, nseq, nsf, slot_symbols); } } /* combine outputs */ for (i=1;i<cell.nof_ports;i++) { for (j=0;j<nof_re;j++) { slot_symbols[0][j] += slot_symbols[i][j]; } } /* Receive all PHICH groups and sequence numbers */ for (ngroup=0;ngroup<srslte_phich_ngroups(&phich);ngroup++) { for (nseq=0;nseq<max_nseq;nseq++) { if (srslte_phich_decode(&phich, slot_symbols[0], ce, 0, ngroup, nseq, nsf, &ack_rx, &distance)<0) { printf("Error decoding ACK\n"); exit(-1); } INFO("%d/%d, ack_tx: %d, ack_rx: %d, ns: %d, distance: %f\n", ngroup, nseq, ack[ngroup][nseq], ack_rx, nsf, distance); if (ack[ngroup][nseq] != ack_rx) { printf("Invalid received ACK: %d!=%d\n", ack[ngroup][nseq], ack_rx); exit(-1); } if (distance < 1.5) { printf("Error\n"); exit(-1); } } } } srslte_phich_free(&phich); srslte_regs_free(®s); cid++; } for (i=0;i<SRSLTE_MAX_PORTS;i++) { free(ce[i]); free(slot_symbols[i]); } printf("OK\n"); exit(0); }