prach examples now uses ue_ul. Fixed timing advance for RAR
This commit is contained in:
parent
6fe535f8a4
commit
335e3bae83
|
@ -161,11 +161,9 @@ enum receiver_state { DECODE_MIB, SEND_PRACH, RECV_RAR} state;
|
|||
#define NOF_PRACH_SEQUENCES 52
|
||||
|
||||
ue_dl_t ue_dl;
|
||||
ue_ul_t ue_ul;
|
||||
ue_sync_t ue_sync;
|
||||
prach_t prach;
|
||||
pusch_t pusch;
|
||||
lte_fft_t fft;
|
||||
harq_t pusch_harq;
|
||||
cf_t *prach_buffers[NOF_PRACH_SEQUENCES];
|
||||
int prach_buffer_len;
|
||||
|
||||
|
@ -274,30 +272,6 @@ int rar_unpack(uint8_t *buffer, rar_msg_t *msg)
|
|||
return(ret);
|
||||
}
|
||||
|
||||
int rar_to_ra_pusch(rar_msg_t *rar, ra_pusch_t *ra, uint32_t nof_prb) {
|
||||
bzero(ra, sizeof(ra_pusch_t));
|
||||
if (!rar->hopping_flag) {
|
||||
ra->freq_hop_fl = hop_disabled;
|
||||
} else {
|
||||
fprintf(stderr, "FIXME: Frequency hopping in RAR not implemented\n");
|
||||
ra->freq_hop_fl = 1;
|
||||
}
|
||||
uint32_t riv = rar->rba;
|
||||
// Truncate resource block assignment
|
||||
uint32_t b = 0;
|
||||
if (nof_prb <= 44) {
|
||||
b = (uint32_t) (ceilf(log2((float) nof_prb*(nof_prb+1)/2)));
|
||||
riv = riv & ((1<<(b+1))-1);
|
||||
}
|
||||
ra->type2_alloc.riv = riv;
|
||||
ra->mcs_idx = rar->mcs;
|
||||
|
||||
ra_type2_from_riv(riv, &ra->type2_alloc.L_crb, &ra->type2_alloc.RB_start,
|
||||
nof_prb, nof_prb);
|
||||
|
||||
ra_mcs_from_idx_ul(ra->mcs_idx, ra_nprb_ul(ra, nof_prb), &ra->mcs);
|
||||
return LIBLTE_SUCCESS;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int ret;
|
||||
|
@ -310,7 +284,6 @@ int main(int argc, char **argv) {
|
|||
uint32_t sfn_offset;
|
||||
rar_msg_t rar_msg;
|
||||
ra_pusch_t ra_pusch;
|
||||
ra_ul_alloc_t prb_alloc;
|
||||
uint32_t rar_window_start = 0, rar_trials = 0, rar_window_stop = 0;
|
||||
timestamp_t uhd_time;
|
||||
timestamp_t next_tx_time;
|
||||
|
@ -380,33 +353,18 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
generate_prach_sequences();
|
||||
|
||||
refsignal_ul_t drms;
|
||||
if (refsignal_ul_init(&drms, cell)) {
|
||||
fprintf(stderr, "Error initiating refsignal_ul\n");
|
||||
exit(-1);
|
||||
}
|
||||
cf_t *drms_signal = vec_malloc(2*RE_X_RB*cell.nof_prb*sizeof(cf_t));
|
||||
if (!drms_signal) {
|
||||
perror("malloc");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (pusch_init(&pusch, cell)) {
|
||||
fprintf(stderr, "Error initiating PUSCH\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (harq_init(&pusch_harq, cell)) {
|
||||
fprintf(stderr, "Error initiating HARQ process\n");
|
||||
if (ue_ul_init(&ue_ul, cell)) {
|
||||
fprintf(stderr, "Error initiating UE UL\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (lte_ifft_init(&fft, cell.cp, cell.nof_prb)) {
|
||||
fprintf(stderr, "Error initiating SC-FDMA modulator\n");
|
||||
exit(-1);
|
||||
}
|
||||
lte_fft_set_freq_shift(&fft, 0.5);
|
||||
pusch_hopping_cfg_t hop_cfg;
|
||||
bzero(&hop_cfg, sizeof(pusch_hopping_cfg_t));
|
||||
refsignal_drms_pusch_cfg_t drms_cfg;
|
||||
bzero(&drms_cfg, sizeof(refsignal_drms_pusch_cfg_t));
|
||||
drms_cfg.beta_pusch = 1.0;
|
||||
ue_ul_set_pusch_cfg(&ue_ul, &drms_cfg, &hop_cfg);
|
||||
|
||||
cf_t *ul_signal = vec_malloc(sizeof(cf_t) * SF_LEN_PRB(cell.nof_prb));
|
||||
if (!ul_signal) {
|
||||
|
@ -415,13 +373,6 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
bzero(ul_signal, sizeof(cf_t) * SF_LEN_PRB(cell.nof_prb));
|
||||
|
||||
cf_t *sf_symbols = vec_malloc(sizeof(cf_t) * SF_LEN_PRB(cell.nof_prb));
|
||||
if (!sf_symbols) {
|
||||
perror("malloc");
|
||||
exit(-1);
|
||||
}
|
||||
bzero(sf_symbols, sizeof(cf_t) * SF_LEN_PRB(cell.nof_prb));
|
||||
|
||||
state = DECODE_MIB;
|
||||
if (ue_sync_init(&ue_sync, cell, cuhd_recv_wrapper_timed, uhd)) {
|
||||
fprintf(stderr, "Error initiating ue_sync\n");
|
||||
|
@ -507,44 +458,21 @@ int main(int argc, char **argv) {
|
|||
rar_unpack(data_rx, &rar_msg);
|
||||
rar_msg_fprint(stdout, &rar_msg);
|
||||
|
||||
rar_to_ra_pusch(&rar_msg, &ra_pusch, cell.nof_prb);
|
||||
dci_rar_to_ra_ul(rar_msg.rba, rar_msg.mcs, rar_msg.hopping_flag, cell.nof_prb, &ra_pusch);
|
||||
ra_pusch_fprint(stdout, &ra_pusch, cell.nof_prb);
|
||||
|
||||
ra_ul_alloc(&prb_alloc, &ra_pusch, 0, cell.nof_prb);
|
||||
ra_ul_alloc(&ra_pusch.prb_alloc, &ra_pusch, 0, cell.nof_prb);
|
||||
|
||||
uint32_t ul_sf_idx = (ue_sync_get_sfidx(&ue_sync)+6)%10;
|
||||
if (harq_setup_ul(&pusch_harq, ra_pusch.mcs, 0, ul_sf_idx, &prb_alloc)) {
|
||||
fprintf(stderr, "Error configuring HARQ process\n");
|
||||
exit(-1);;
|
||||
}
|
||||
|
||||
bit_pack_vector((uint8_t*) conn_request_msg, data, ra_pusch.mcs.tbs);
|
||||
if (pusch_encode_rnti(&pusch, &pusch_harq, data, rar_msg.temp_c_rnti, sf_symbols)) {
|
||||
fprintf(stderr, "Error encoding TB\n");
|
||||
n = ue_ul_pusch_encode_rnti(&ue_ul, &ra_pusch, data, ul_sf_idx, rar_msg.temp_c_rnti, ul_signal);
|
||||
if (n < 0) {
|
||||
fprintf(stderr, "Error encoding PUSCH\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
refsignal_drms_pusch_cfg_t pusch_cfg;
|
||||
bzero(&pusch_cfg, sizeof(refsignal_drms_pusch_cfg_t));
|
||||
pusch_cfg.nof_prb = prb_alloc.L_prb;
|
||||
pusch_cfg.beta_pusch = 1.0;
|
||||
|
||||
for (uint32_t i=0;i<2;i++) {
|
||||
if (refsignal_dmrs_pusch_gen(&drms, &pusch_cfg, 2*ul_sf_idx+i, drms_signal)) {
|
||||
fprintf(stderr, "Error generating PUSCH DRMS signals\n");
|
||||
exit(-1);
|
||||
}
|
||||
refsignal_drms_pusch_put(&drms, &pusch_cfg, drms_signal, i,
|
||||
prb_alloc.n_prb[i], sf_symbols);
|
||||
}
|
||||
|
||||
lte_ifft_run_sf(&fft, sf_symbols, ul_signal);
|
||||
|
||||
cfo_correct(&ue_sync.sfind.cfocorr,
|
||||
ul_signal, ul_signal,
|
||||
sync_get_cfo(&ue_sync.strack) / lte_symbol_sz(cell.nof_prb));
|
||||
|
||||
|
||||
ue_ul_set_cfo(&ue_ul, sync_get_cfo(&ue_sync.strack));
|
||||
|
||||
gettimeofday(&tdata[2], NULL);
|
||||
get_time_interval(tdata);
|
||||
printf("time exec UL: %d\n",tdata[0].tv_usec);
|
||||
|
@ -557,13 +485,12 @@ int main(int argc, char **argv) {
|
|||
printf("time to stop RX: %d\n",tdata[0].tv_usec);
|
||||
|
||||
ue_sync_get_last_timestamp(&ue_sync, &uhd_time);
|
||||
|
||||
//float time_adv_sec = ((float) rar_msg.timing_adv_cmd - 31 - 25) * 16 /(15000*2048);
|
||||
float time_adv_sec = ((float) rar_msg.timing_adv_cmd - 31) * 16 /(15000*2048);
|
||||
|
||||
float time_adv_sec = lte_N_ta_new_rar(rar_msg.timing_adv_cmd)*LTE_TS;
|
||||
vec_sc_prod_cfc(ul_signal, 2, ul_signal, SF_LEN_PRB(cell.nof_prb));
|
||||
|
||||
timestamp_copy(&next_tx_time, &uhd_time);
|
||||
timestamp_add(&next_tx_time, 0, 0.006 + time_adv_sec); // send after 6 sub-frames (6 ms)
|
||||
timestamp_add(&next_tx_time, 0, 0.006 - time_adv_sec); // send after 6 sub-frames (6 ms)
|
||||
printf("Send %d samples PUSCH sfn: %d. Last frame time = %.6f"
|
||||
"send PUSCH time = %.6f TA: %.1f us\n",
|
||||
SF_LEN_PRB(cell.nof_prb), sfn, timestamp_real(&uhd_time),
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
|
||||
#define LTE_NSOFT_BITS 250368 // Soft buffer size for Category 1 UE
|
||||
|
||||
#define LTE_TS (1.0/(15000.0*2048.0))
|
||||
|
||||
#define MAX_PORTS 4
|
||||
#define MAX_LAYERS 8
|
||||
#define MAX_CODEWORDS 2
|
||||
|
@ -186,6 +188,11 @@ LIBLTE_API uint32_t lte_voffset(uint32_t symbol_id,
|
|||
uint32_t cell_id,
|
||||
uint32_t nof_ports);
|
||||
|
||||
LIBLTE_API uint32_t lte_N_ta_new_rar(uint32_t ta);
|
||||
|
||||
LIBLTE_API uint32_t lte_N_ta_new(uint32_t N_ta_old,
|
||||
uint32_t ta);
|
||||
|
||||
LIBLTE_API int lte_cb_size(uint32_t index);
|
||||
|
||||
LIBLTE_API bool lte_cb_size_isvalid(uint32_t size);
|
||||
|
|
|
@ -81,10 +81,16 @@ LIBLTE_API int dci_msg_to_ra_dl(dci_msg_t *msg,
|
|||
ra_pdsch_t *ra_dl);
|
||||
|
||||
LIBLTE_API int dci_msg_to_ra_ul(dci_msg_t *msg,
|
||||
lte_cell_t cell,
|
||||
uint32_t nof_prb,
|
||||
uint32_t n_rb_ho,
|
||||
ra_pusch_t *ra_ul);
|
||||
|
||||
LIBLTE_API int dci_rar_to_ra_ul(uint32_t rba,
|
||||
uint32_t trunc_mcs,
|
||||
bool hopping_flag,
|
||||
uint32_t nof_prb,
|
||||
ra_pusch_t *ra);
|
||||
|
||||
LIBLTE_API dci_format_t dci_format_from_string(char *str);
|
||||
|
||||
LIBLTE_API char* dci_format_string(dci_format_t format);
|
||||
|
|
|
@ -35,10 +35,9 @@
|
|||
********************************************************/
|
||||
|
||||
|
||||
|
||||
#include "liblte/phy/common/phy_common.h"
|
||||
#include "liblte/phy/ch_estimation/chest_dl.h"
|
||||
#include "liblte/phy/common/fft.h"
|
||||
#include "liblte/phy/common/phy_common.h"
|
||||
#include "liblte/phy/ch_estimation/refsignal_ul.h"
|
||||
#include "liblte/phy/phch/pusch.h"
|
||||
#include "liblte/phy/phch/ra.h"
|
||||
|
@ -85,11 +84,13 @@ LIBLTE_API void ue_ul_set_pusch_cfg(ue_ul_t *q,
|
|||
LIBLTE_API int ue_ul_pusch_encode(ue_ul_t *q,
|
||||
ra_pusch_t *ra_ul,
|
||||
uint8_t *data,
|
||||
uint32_t sf_idx,
|
||||
cf_t *output_signal);
|
||||
|
||||
LIBLTE_API int ue_ul_pusch_encode_rnti(ue_ul_t *q,
|
||||
ra_pusch_t *ra_ul,
|
||||
uint8_t *data,
|
||||
uint32_t sf_idx,
|
||||
uint16_t rnti,
|
||||
cf_t *output_signal);
|
||||
|
||||
|
@ -97,12 +98,14 @@ LIBLTE_API int ue_ul_pusch_uci_encode(ue_ul_t *q,
|
|||
ra_pusch_t *ra_ul,
|
||||
uint8_t *data,
|
||||
uci_data_t uci_data,
|
||||
uint32_t sf_idx,
|
||||
cf_t *output_signal);
|
||||
|
||||
LIBLTE_API int ue_ul_pusch_uci_encode_rnti(ue_ul_t *q,
|
||||
ra_pusch_t *ra_ul,
|
||||
uint8_t *data,
|
||||
uint8_t *data,
|
||||
uci_data_t uci_data,
|
||||
uint32_t sf_idx,
|
||||
uint16_t rnti,
|
||||
cf_t *output_signal);
|
||||
|
||||
|
|
|
@ -170,6 +170,31 @@ char *lte_cp_string(lte_cp_t cp) {
|
|||
}
|
||||
}
|
||||
|
||||
/* Returns the new time advance N_ta_new as specified in Section 4.2.3 of 36.213 */
|
||||
uint32_t lte_N_ta_new(uint32_t N_ta_old, uint32_t ta) {
|
||||
|
||||
ta &= 63;
|
||||
int n_ta_new = N_ta_old + ((float) ta - 31) * 16;
|
||||
if (n_ta_new < 0) {
|
||||
return 0;
|
||||
} else {
|
||||
if (n_ta_new < 20512) {
|
||||
return (uint32_t) n_ta_new;
|
||||
} else {
|
||||
return 20512;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns the new time advance as indicated by the random access response
|
||||
* as specified in Section 4.2.3 of 36.213 */
|
||||
uint32_t lte_N_ta_new_rar(uint32_t ta) {
|
||||
if (ta > 1282) {
|
||||
ta = 1282;
|
||||
}
|
||||
return ta*16;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finds index of minimum K>=long_cb in Table 5.1.3-3 of 36.212
|
||||
*/
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
#include "liblte/phy/utils/debug.h"
|
||||
|
||||
|
||||
/* Creates the DL PDSCH resource allocation grant from a DCI message
|
||||
*/
|
||||
int dci_msg_to_ra_dl(dci_msg_t *msg, uint16_t msg_rnti,
|
||||
lte_cell_t cell, uint32_t cfi,
|
||||
ra_pdsch_t *ra_dl)
|
||||
|
@ -97,28 +99,56 @@ int dci_msg_to_ra_dl(dci_msg_t *msg, uint16_t msg_rnti,
|
|||
return ret;
|
||||
}
|
||||
|
||||
int dci_msg_to_ra_ul(dci_msg_t *msg, lte_cell_t cell, uint32_t n_rb_ho, ra_pusch_t *ra_ul)
|
||||
/* Creates the UL PUSCH resource allocation grant from the random access respone message
|
||||
*/
|
||||
int dci_rar_to_ra_ul(uint32_t rba, uint32_t trunc_mcs, bool hopping_flag, uint32_t nof_prb, ra_pusch_t *ra) {
|
||||
bzero(ra, sizeof(ra_pusch_t));
|
||||
if (!hopping_flag) {
|
||||
ra->freq_hop_fl = hop_disabled;
|
||||
} else {
|
||||
fprintf(stderr, "FIXME: Frequency hopping in RAR not implemented\n");
|
||||
ra->freq_hop_fl = 1;
|
||||
}
|
||||
uint32_t riv = rba;
|
||||
// Truncate resource block assignment
|
||||
uint32_t b = 0;
|
||||
if (nof_prb <= 44) {
|
||||
b = (uint32_t) (ceilf(log2((float) nof_prb*(nof_prb+1)/2)));
|
||||
riv = riv & ((1<<(b+1))-1);
|
||||
}
|
||||
ra->type2_alloc.riv = riv;
|
||||
ra->mcs_idx = trunc_mcs;
|
||||
|
||||
ra_type2_from_riv(riv, &ra->type2_alloc.L_crb, &ra->type2_alloc.RB_start,
|
||||
nof_prb, nof_prb);
|
||||
|
||||
ra_mcs_from_idx_ul(ra->mcs_idx, ra_nprb_ul(ra, nof_prb), &ra->mcs);
|
||||
return LIBLTE_SUCCESS;
|
||||
}
|
||||
|
||||
/* Creates the UL PUSCH resource allocation grant from a DCI format 0 message
|
||||
*/
|
||||
int dci_msg_to_ra_ul(dci_msg_t *msg, uint32_t nof_prb, uint32_t n_rb_ho, ra_pusch_t *ra_ul)
|
||||
{
|
||||
int ret = LIBLTE_ERROR_INVALID_INPUTS;
|
||||
|
||||
if (msg != NULL &&
|
||||
ra_ul != NULL &&
|
||||
lte_cell_isvalid(&cell))
|
||||
ra_ul != NULL)
|
||||
{
|
||||
ret = LIBLTE_ERROR;
|
||||
|
||||
bzero(ra_ul, sizeof(ra_pusch_t));
|
||||
|
||||
if (dci_msg_unpack_pusch(msg, ra_ul, cell.nof_prb)) {
|
||||
if (dci_msg_unpack_pusch(msg, ra_ul, nof_prb)) {
|
||||
fprintf(stderr, "Can't unpack PDSCH message\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (VERBOSE_ISINFO()) {
|
||||
ra_pusch_fprint(stdout, ra_ul, cell.nof_prb);
|
||||
ra_pusch_fprint(stdout, ra_ul, nof_prb);
|
||||
}
|
||||
|
||||
if (ra_ul_alloc(&ra_ul->prb_alloc, ra_ul, n_rb_ho, cell.nof_prb)) {
|
||||
if (ra_ul_alloc(&ra_ul->prb_alloc, ra_ul, n_rb_ho, nof_prb)) {
|
||||
fprintf(stderr, "Error computing resource allocation\n");
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include <math.h>
|
||||
|
||||
#define CURRENT_FFTSIZE lte_symbol_sz(q->cell.nof_prb)
|
||||
#define CURRENT_SFLEN SF_LEN(CURRENT_FFTSIZE, q->cell.cp)
|
||||
#define CURRENT_SFLEN SF_LEN(CURRENT_FFTSIZE)
|
||||
|
||||
#define CURRENT_SLOTLEN_RE SLOT_LEN_RE(q->cell.nof_prb, q->cell.cp)
|
||||
#define CURRENT_SFLEN_RE SF_LEN_RE(q->cell.nof_prb, q->cell.cp)
|
||||
|
|
|
@ -25,16 +25,16 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "liblte/phy/ue/ue_ul.h"
|
||||
|
||||
#include <complex.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "liblte/phy/ue/ue_ul.h"
|
||||
|
||||
#define CURRENT_FFTSIZE lte_symbol_sz(q->cell.nof_prb)
|
||||
#define CURRENT_SFLEN SF_LEN(CURRENT_FFTSIZE, q->cell.cp)
|
||||
#define CURRENT_SFLEN SF_LEN(CURRENT_FFTSIZE)
|
||||
|
||||
#define CURRENT_SLOTLEN_RE SLOT_LEN_RE(q->cell.nof_prb, q->cell.cp)
|
||||
#define CURRENT_SFLEN_RE SF_LEN_RE(q->cell.nof_prb, q->cell.cp)
|
||||
#define CURRENT_SFLEN_RE SF_LEN_RE(q->cell.nof_prb, q->cell.cp)
|
||||
|
||||
|
||||
int ue_ul_init(ue_ul_t *q,
|
||||
|
@ -108,7 +108,8 @@ void ue_ul_free(ue_ul_t *q) {
|
|||
harq_free(&q->harq_process[i]);
|
||||
}
|
||||
cfo_free(&q->cfo);
|
||||
refsignal_ul_free(&q>drms);
|
||||
refsignal_ul_free(&q->drms);
|
||||
|
||||
if (q->sf_symbols) {
|
||||
free(q->sf_symbols);
|
||||
}
|
||||
|
@ -148,7 +149,7 @@ int ue_ul_pusch_encode(ue_ul_t *q, ra_pusch_t *ra_ul, uint8_t *data, uint32_t sf
|
|||
return ue_ul_pusch_uci_encode_rnti(q, ra_ul, data, uci_data, sf_idx, q->current_rnti, output_signal);
|
||||
}
|
||||
|
||||
int ue_ul_pusch_encode_rnti(ue_ul_t *q, ra_pusch_t *ra_ul, uint8_t *data, uint16_t rnti, uint32_t sf_idx, cf_t *output_signal)
|
||||
int ue_ul_pusch_encode_rnti(ue_ul_t *q, ra_pusch_t *ra_ul, uint8_t *data, uint32_t sf_idx, uint16_t rnti, cf_t *output_signal)
|
||||
{
|
||||
uci_data_t uci_data;
|
||||
bzero(&uci_data, sizeof(uci_data_t));
|
||||
|
@ -173,10 +174,9 @@ int ue_ul_pusch_uci_encode_rnti(ue_ul_t *q, ra_pusch_t *ra_ul, uint8_t *data, uc
|
|||
{
|
||||
|
||||
if (ra_ul->prb_alloc.L_prb == 0) {
|
||||
fprintf(stderr, "Invalid UL PRB allocation (L_prb=0)\n" ;
|
||||
fprintf(stderr, "Invalid UL PRB allocation (L_prb=0)\n");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
ret = LIBLTE_ERROR;
|
||||
|
||||
|
@ -207,4 +207,8 @@ int ue_ul_pusch_uci_encode_rnti(ue_ul_t *q, ra_pusch_t *ra_ul, uint8_t *data, uc
|
|||
cfo_correct(&q->cfo, output_signal, output_signal, q->current_cfo / lte_symbol_sz(q->cell.nof_prb));
|
||||
|
||||
ret = LIBLTE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
Loading…
Reference in New Issue