コード例 #1
0
ファイル: pmch.c プロジェクト: mdasari823/srsLTE
int srslte_pmch_encode(srslte_pmch_t *q,
                       srslte_pdsch_cfg_t *cfg, srslte_softbuffer_tx_t *softbuffer,
                       uint8_t *data, uint16_t area_id, cf_t *sf_symbols[SRSLTE_MAX_PORTS])
{
  
  int i;
  /* Set pointers for layermapping & precoding */
  cf_t *x[SRSLTE_MAX_LAYERS];
  int ret = SRSLTE_ERROR_INVALID_INPUTS; 
   
  if (q != NULL && cfg != NULL)
  {
    for (i=0;i<q->cell.nof_ports;i++) {
      if (sf_symbols[i] == NULL) {
        return SRSLTE_ERROR_INVALID_INPUTS;
      }
    }
    
    if (cfg->grant.mcs[0].tbs == 0) {
      return SRSLTE_ERROR_INVALID_INPUTS;      
    }
    
    if (cfg->nbits[0].nof_re > q->max_re) {
      fprintf(stderr,
          "Error too many RE per subframe (%d). PMCH configured for %d RE (%d PRB)\n",
          cfg->nbits[0].nof_re, q->max_re, q->cell.nof_prb);
      return SRSLTE_ERROR_INVALID_INPUTS;
    }

    INFO("Encoding PMCH SF: %d, Mod %s, NofBits: %d, NofSymbols: %d, NofBitsE: %d, rv_idx: %d\n",
        cfg->sf_idx, srslte_mod_string(cfg->grant.mcs[0].mod), cfg->grant.mcs[0].tbs, 
         cfg->nbits[0].nof_re, cfg->nbits[0].nof_bits, 0);

    /* number of layers equals number of ports */
    for (i = 0; i < q->cell.nof_ports; i++) {
      x[i] = q->x[i];
    }
    memset(&x[q->cell.nof_ports], 0, sizeof(cf_t*) * (SRSLTE_MAX_LAYERS - q->cell.nof_ports));

    // TODO: use tb_encode directly
    if (srslte_dlsch_encode(&q->dl_sch, cfg, softbuffer, data, q->e)) {
      fprintf(stderr, "Error encoding TB\n");
      return SRSLTE_ERROR;
    }

    /* scramble */
    srslte_scrambling_bytes(&q->seqs[area_id]->seq[cfg->sf_idx], (uint8_t*) q->e, cfg->nbits[0].nof_bits);

    srslte_mod_modulate_bytes(&q->mod[cfg->grant.mcs[0].mod], (uint8_t*) q->e, q->d, cfg->nbits[0].nof_bits);
    
    /* No tx diversity in MBSFN */
    memcpy(q->symbols[0], q->d, cfg->nbits[0].nof_re * sizeof(cf_t));

    /* mapping to resource elements */
    for (i = 0; i < q->cell.nof_ports; i++) {
      srslte_pmch_put(q, q->symbols[i], sf_symbols[i], cfg->nbits[0].lstart);
    }
    
    ret = SRSLTE_SUCCESS;
  } 
  return ret; 
}
コード例 #2
0
ファイル: pdsch.c プロジェクト: sdnnfv/srsLTE
/** Converts the PDSCH data bits to symbols mapped to the slot ready for transmission
 */
int srslte_pdsch_encode_rnti(srslte_pdsch_t *q,
                             srslte_pdsch_cfg_t *cfg, srslte_softbuffer_tx_t *softbuffer,
                             uint8_t *data, uint16_t rnti, cf_t *sf_symbols[SRSLTE_MAX_PORTS])
{
    int i;
    /* Set pointers for layermapping & precoding */
    cf_t *x[SRSLTE_MAX_LAYERS];
    int ret = SRSLTE_ERROR_INVALID_INPUTS;

    if (q             != NULL &&
            data          != NULL &&
            cfg  != NULL)
    {

        for (i=0; i<q->cell.nof_ports; i++) {
            if (sf_symbols[i] == NULL) {
                return SRSLTE_ERROR_INVALID_INPUTS;
            }
        }

        if (cfg->grant.mcs.tbs == 0) {
            return SRSLTE_ERROR_INVALID_INPUTS;
        }

        if (cfg->nbits.nof_re > q->max_re) {
            fprintf(stderr,
                    "Error too many RE per subframe (%d). PDSCH configured for %d RE (%d PRB)\n",
                    cfg->nbits.nof_re, q->max_re, q->cell.nof_prb);
            return SRSLTE_ERROR_INVALID_INPUTS;
        }

        INFO("Encoding PDSCH SF: %d, Mod %s, NofBits: %d, NofSymbols: %d, NofBitsE: %d, rv_idx: %d\n",
             cfg->sf_idx, srslte_mod_string(cfg->grant.mcs.mod), cfg->grant.mcs.tbs,
             cfg->nbits.nof_re, cfg->nbits.nof_bits, cfg->rv);

        /* number of layers equals number of ports */
        for (i = 0; i < q->cell.nof_ports; i++) {
            x[i] = q->x[i];
        }
        memset(&x[q->cell.nof_ports], 0, sizeof(cf_t*) * (SRSLTE_MAX_LAYERS - q->cell.nof_ports));

        if (srslte_dlsch_encode(&q->dl_sch, cfg, softbuffer, data, q->e)) {
            fprintf(stderr, "Error encoding TB\n");
            return SRSLTE_ERROR;
        }

        if (rnti != q->rnti) {
            srslte_sequence_t seq;
            if (srslte_sequence_pdsch(&seq, rnti, 0, 2 * cfg->sf_idx, q->cell.id, cfg->nbits.nof_bits)) {
                return SRSLTE_ERROR;
            }
            srslte_scrambling_bytes_offset(&seq, (uint8_t*) q->e, 0, cfg->nbits.nof_bits);
            srslte_sequence_free(&seq);
        } else {
            srslte_scrambling_bytes_offset(&q->seq[cfg->sf_idx], (uint8_t*) q->e, 0, cfg->nbits.nof_bits);
        }

        srslte_mod_modulate_bytes(&q->mod[cfg->grant.mcs.mod], (uint8_t*) q->e, q->d, cfg->nbits.nof_bits);

        /* TODO: only diversity supported */
        if (q->cell.nof_ports > 1) {
            srslte_layermap_diversity(q->d, x, q->cell.nof_ports, cfg->nbits.nof_re);
            srslte_precoding_diversity(&q->precoding, x, q->symbols, q->cell.nof_ports,
                                       cfg->nbits.nof_re / q->cell.nof_ports);
        } else {
            memcpy(q->symbols[0], q->d, cfg->nbits.nof_re * sizeof(cf_t));
        }

        /* mapping to resource elements */
        for (i = 0; i < q->cell.nof_ports; i++) {
            srslte_pdsch_put(q, q->symbols[i], sf_symbols[i], &cfg->grant, cfg->nbits.lstart, cfg->sf_idx);
        }
        ret = SRSLTE_SUCCESS;
    }
    return ret;
}