/* the gateway function */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { srslte_cell_t cell; srslte_pss_synch_t pss; cf_t *input_symbols; int frame_len; if (nrhs < NOF_INPUTS) { help(); return; } srslte_use_standard_symbol_size(true); if (mexutils_read_cell(ENBCFG, &cell)) { help(); return; } /* Allocate input buffers */ frame_len = mexutils_read_cf(INPUT, &input_symbols); if (frame_len < 0) { mexErrMsgTxt("Error reading input symbols\n"); return; } if (nrhs == NOF_INPUTS+1) { frame_len = (int) mxGetScalar(prhs[NOF_INPUTS]); } if (srslte_pss_synch_init_fft(&pss, frame_len, srslte_symbol_sz(cell.nof_prb))) { fprintf(stderr, "Error initiating PSS\n"); exit(-1); } if (srslte_pss_synch_set_N_id_2(&pss, cell.id%3)) { fprintf(stderr, "Error setting N_id_2=%d\n",cell.id%3); exit(-1); } srslte_pss_synch_set_ema_alpha(&pss, 1.0); int peak_idx = srslte_pss_synch_find_pss(&pss, input_symbols, NULL); if (nlhs >= 1) { plhs[0] = mxCreateDoubleScalar(peak_idx); } if (nlhs >= 2) { mexutils_write_cf(pss.conv_output, &plhs[1], frame_len, 1); } srslte_pss_synch_free(&pss); free(input_symbols); return; }
int cuhd_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_rx) { *h = NULL; /* Set priority to UHD threads */ uhd::set_thread_priority_safe(); /* Get multiusrp handler */ cuhd_handler *handler = new cuhd_handler(); std::string _args = std::string(args); handler->usrp = uhd::usrp::multi_usrp::make(_args);// + ", recv_frame_size=9232,num_recv_frames=64,send_frame_size=9232,num_send_frames=64"); /* Initialize rx and tx stremers */ std::string otw, cpu; otw = "sc16"; cpu = "fc32"; uhd::stream_args_t stream_args(cpu, otw); handler->rx_stream = handler->usrp->get_rx_stream(stream_args); handler->tx_stream = handler->usrp->get_tx_stream(stream_args); handler->rx_nof_samples = handler->rx_stream->get_max_num_samps(); handler->tx_nof_samples = handler->tx_stream->get_max_num_samps(); handler->tx_gain_same_rx = tx_gain_same_rx; handler->tx_rx_gain_offset = 0.0; handler->rx_gain_range = handler->usrp->get_rx_gain_range(); handler->tx_gain_range = handler->usrp->get_tx_gain_range(); /* Create auxiliary thread and mutexes for AGC */ if (create_thread_gain) { if (pthread_mutex_init(&handler->mutex, NULL)) { return -1; } if (pthread_cond_init(&handler->cond, NULL)) { return -1; } if (pthread_create(&handler->thread_gain, NULL, thread_gain_fcn, handler)) { perror("pthread_create"); return -1; } } /* Find out if the master clock rate is configurable */ double cur_clock = handler->usrp->get_master_clock_rate(); printf("Trying to dynamically change Master clock...\n"); handler->usrp->set_master_clock_rate(cur_clock/2); if (handler->usrp->get_master_clock_rate() == cur_clock) { handler->dynamic_rate = false; /* Master clock rate is not configurable. Check if it is compatible with LTE */ int cur_clock_i = (int) cur_clock; if (cur_clock_i % 1920000) { fprintf(stderr, "Error: LTE sampling rates are not supported. Master clock rate is %.1f MHz\n", cur_clock/1e6); return -1; } else { printf("Master clock is not configurable. Using standard symbol sizes and sampling rates.\n"); srslte_use_standard_symbol_size(true); } } else { printf("Master clock is configurable. Using reduced symbol sizes and sampling rates.\n"); handler->dynamic_rate = true; } *h = handler; return 0; }