[srsran-users] Trying to write code for pssch_tx

Dr. Syed Talib Abbas Jafri syedtalibabbas at gmail.com
Tue Sep 24 09:50:57 UTC 2024


Dear Users,

I have tested pssch_ue successfully with USRP but need to write code for 
transmission side of sidelink channel. Though I have found that several 
functions are already made in header files but I am unable to transmit 
any data through USRP in the initial testing. USRP is opened but 
transmission through srsran_rf_send() function does not enable 
transmission channel as USRP light does not turn on. Source code is 
attached. Any guidance in this regard will be helpful.

-------------- next part --------------
#include<stdio.h>
#include<stdlib.h>
#include "srsran/phy/rf/rf.h"
#include "srsran/srsran.h"
#include "srsran/phy/phch/pscch.h"
#include "srsran/phy/phch/pssch.h"
#include "srsran/phy/phch/sci.h"
#include "srsran/phy/ch_estimation/chest_sl.h"

#define MAX_SRATE_DELTA 2 

//static srsran_ofdm_t            ifft;

typedef struct {
  bool     use_standard_lte_rates;
  bool     disable_plots;
  char*    input_file_name;
  uint32_t file_start_sf_idx;
  uint32_t nof_rx_antennas;
  char*    rf_dev;
  char*    rf_args;
  double   rf_freq;
  float    rf_gain;

  // Sidelink specific args
  uint32_t size_sub_channel;
  uint32_t num_sub_channel;
} prog_args_t;

static srsran_pscch_t pscch = {}; // Defined global for plotting thread
//static srsran_pssch_t pssch = {};

static srsran_cell_sl_t cell_sl = {.nof_prb = 50, .tm = SRSRAN_SIDELINK_TM4, .cp = SRSRAN_CP_NORM, .N_sl_id = 0};

void args_default(prog_args_t* args)
{
  args->use_standard_lte_rates = false;
  args->disable_plots          = false;
  args->input_file_name        = NULL;
  args->file_start_sf_idx      = 0;
  args->nof_rx_antennas        = 1;
  args->rf_dev                 = "";
  args->rf_args                = "";
  args->rf_freq                = 5.92e9;
  args->rf_gain                = 50;
  args->size_sub_channel       = 10;
  args->num_sub_channel        = 5;
}

static prog_args_t prog_args;

static srsran_cell_t cell = {
    25,                // nof_prb
    1,                 // nof_ports
    0,                 // cell_id
    SRSRAN_CP_NORM,    // cyclic prefix
    SRSRAN_PHICH_NORM, // PHICH length
    SRSRAN_PHICH_R_1,  // PHICH resources
    SRSRAN_FDD,
};

static int   sf_n_re = 0, sf_n_samples = 0;
static cf_t *sf_buffer = NULL, *output_buffer = NULL;

int main(void){
  // init memory
  sf_buffer = srsran_vec_cf_malloc(sf_n_re);
  if (!sf_buffer) {
    perror("Error: malloc for sf_buffer");
    exit(-1);
  }

  /*if (srsran_ofdm_tx_init(&ifft, SRSRAN_CP_NORM, sf_buffer, output_buffer, cell.nof_prb)) {
    fprintf(stderr, "Error creating iFFT object\n");
    exit(-1);
  }
  
  srsran_ofdm_set_normalize(&ifft, true);
  srsran_ofdm_set_freq_shift(&ifft, -SRSRAN_NBIOT_FREQ_SHIFT_FACTOR);
  */
  output_buffer = srsran_vec_cf_malloc(sf_n_samples);
  if (!output_buffer) {
    perror("Error: malloc for output buffer");
    exit(-1);
  }
    int srate = srsran_sampling_freq_hz(cell.nof_prb); //set sampling frequency
    srsran_rf_t rf = {};
    if (srsran_rf_open_multi(&rf, "", 1)) {
        printf("Error opening rf");
        exit(-1);
    }
    srsran_use_standard_symbol_size(prog_args.use_standard_lte_rates);
    srsran_rf_set_tx_gain(&rf, prog_args.rf_gain);
    srsran_rf_set_tx_freq(&rf, prog_args.nof_rx_antennas, prog_args.rf_freq);

    float srate_rf = srsran_rf_set_tx_srate(&rf, (double)srate);
    if (abs(srate - (int)srate_rf) > MAX_SRATE_DELTA) {
        ERROR("Could not set tx sampling rate : wanted %d got %f", srate, srate_rf);
        exit(-1);
      }
  
  
  srsran_sl_comm_resource_pool_t sl_comm_resource_pool;
  if (srsran_sl_comm_resource_pool_get_default_config(&sl_comm_resource_pool, cell_sl) != SRSRAN_SUCCESS) {
    ERROR("Error initializing sl_comm_resource_pool");
    return SRSRAN_ERROR;
  }
  
    // SCI
  srsran_sci_t sci;
  srsran_sci_init(&sci, &cell_sl, &sl_comm_resource_pool);

  // init PSCCH object
  if (srsran_pscch_init(&pscch, SRSRAN_MAX_PRB) != SRSRAN_SUCCESS) {
    ERROR("Error in PSCCH init");
    return SRSRAN_ERROR;
  }

  if (srsran_pscch_set_cell(&pscch, cell_sl) != SRSRAN_SUCCESS) {
    ERROR("Error in PSCCH set cell");
    return SRSRAN_ERROR;
  }
  //srsran_ofdm_tx_sf(&ifft);
  uint32_t pscch_prb_start_idx = 0;
  pscch_prb_start_idx = 25;
  while(1){
    //srsran_rf_timed(&rf,output_buffer,sf_n_samples,true,true,false);
    srsran_rf_send(&rf,output_buffer,2,false);

    //srsran_pscch_encode(&pscch,&sci,&sf_buffer,pscch_prb_start_idx);

  }
    
    srsran_rf_close(&rf);
    exit(0);
}


More information about the srsran-users mailing list