Commit 3d3f49c5 authored by Khalid Ahmed's avatar Khalid Ahmed Committed by Thomas Schlichter

nr_ulsch_encoding is implemented and tested

parent 009b195d
...@@ -272,7 +272,7 @@ int nr_dlsch_encoding(unsigned char *a, ...@@ -272,7 +272,7 @@ int nr_dlsch_encoding(unsigned char *a,
unsigned int G; unsigned int G;
unsigned int crc=1; unsigned int crc=1;
int i;
uint8_t harq_pid = dlsch->harq_ids[slot]; uint8_t harq_pid = dlsch->harq_ids[slot];
nfapi_nr_dl_config_dlsch_pdu_rel15_t rel15 = dlsch->harq_processes[harq_pid]->dlsch_pdu.dlsch_pdu_rel15; nfapi_nr_dl_config_dlsch_pdu_rel15_t rel15 = dlsch->harq_processes[harq_pid]->dlsch_pdu.dlsch_pdu_rel15;
uint16_t nb_rb = rel15.n_prb; uint16_t nb_rb = rel15.n_prb;
...@@ -302,7 +302,9 @@ int nr_dlsch_encoding(unsigned char *a, ...@@ -302,7 +302,9 @@ int nr_dlsch_encoding(unsigned char *a,
A = rel15.transport_block_size; A = rel15.transport_block_size;
G = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs,mod_order,rel15.nb_layers); G = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs,mod_order,rel15.nb_layers);
LOG_D(PHY,"dlsch coding A %d G %d mod_order %d\n", A,G, mod_order); LOG_D(PHY,"dlsch coding A %d G %d mod_order %d\n", A,G, mod_order);
Tbslbrm = nr_compute_tbs(28,nb_rb,frame_parms->symbols_per_slot,0,0, rel15.nb_layers); Tbslbrm = nr_compute_tbs(28,nb_rb,frame_parms->symbols_per_slot,0,0, rel15.nb_layers);
...@@ -328,8 +330,13 @@ int nr_dlsch_encoding(unsigned char *a, ...@@ -328,8 +330,13 @@ int nr_dlsch_encoding(unsigned char *a,
dlsch->harq_processes[harq_pid]->B = A+24; dlsch->harq_processes[harq_pid]->B = A+24;
// dlsch->harq_processes[harq_pid]->b = a; // dlsch->harq_processes[harq_pid]->b = a;
memcpy(dlsch->harq_processes[harq_pid]->b,a,(A/8)+4); memcpy(dlsch->harq_processes[harq_pid]->b,a,(A/8)+4);
//write_output("enc_b.m","enc_in0",&dlsch->harq_processes[harq_pid]->b[0],(A/8)+4,1,4);
//for(i=0;i<10;i++)
//printf("dlsch->harq_processes[harq_pid]->b %d\n", dlsch->harq_processes[harq_pid]->b[i]);
nr_segmentation(dlsch->harq_processes[harq_pid]->b, nr_segmentation(dlsch->harq_processes[harq_pid]->b,
dlsch->harq_processes[harq_pid]->c, dlsch->harq_processes[harq_pid]->c,
dlsch->harq_processes[harq_pid]->B, dlsch->harq_processes[harq_pid]->B,
...@@ -351,6 +358,7 @@ int nr_dlsch_encoding(unsigned char *a, ...@@ -351,6 +358,7 @@ int nr_dlsch_encoding(unsigned char *a,
Kr = dlsch->harq_processes[harq_pid]->K; Kr = dlsch->harq_processes[harq_pid]->K;
Kr_bytes = Kr>>3; Kr_bytes = Kr>>3;
//write_output("enc_input0.m","enc_in0",&dlsch->harq_processes[harq_pid]->c[0][0],Kr_bytes,1,4);
//printf("segment Z %d k %d Kr %d BG %d\n", *pz,dlsch->harq_processes[harq_pid]->K,Kr,BG); //printf("segment Z %d k %d Kr %d BG %d\n", *pz,dlsch->harq_processes[harq_pid]->K,Kr,BG);
//start_meas(te_stats); //start_meas(te_stats);
...@@ -388,6 +396,7 @@ int nr_dlsch_encoding(unsigned char *a, ...@@ -388,6 +396,7 @@ int nr_dlsch_encoding(unsigned char *a,
//stop_meas(te_stats); //stop_meas(te_stats);
//printf("end ldpc encoder -- output\n"); //printf("end ldpc encoder -- output\n");
//write_output("enc_input0.m","enc_in0",&dlsch->harq_processes[harq_pid]->c[0][0],Kr_bytes,1,4);
#ifdef DEBUG_DLSCH_CODING #ifdef DEBUG_DLSCH_CODING
write_output("enc_input0.m","enc_in0",&dlsch->harq_processes[harq_pid]->c[0][0],Kr_bytes,1,4); write_output("enc_input0.m","enc_in0",&dlsch->harq_processes[harq_pid]->c[0][0],Kr_bytes,1,4);
write_output("enc_output0.m","enc0",&dlsch->harq_processes[harq_pid]->d[0][0],(3*8*Kr_bytes)+12,1,4); write_output("enc_output0.m","enc0",&dlsch->harq_processes[harq_pid]->d[0][0],(3*8*Kr_bytes)+12,1,4);
...@@ -429,6 +438,7 @@ int nr_dlsch_encoding(unsigned char *a, ...@@ -429,6 +438,7 @@ int nr_dlsch_encoding(unsigned char *a,
rel15.redundancy_version, rel15.redundancy_version,
E); E);
#ifdef DEBUG_DLSCH_CODING #ifdef DEBUG_DLSCH_CODING
for (int i =0; i<16; i++) for (int i =0; i<16; i++)
printf("output ratematching e[%d]= %d r_offset %d\n", i,dlsch->harq_processes[harq_pid]->e[i+r_offset], r_offset); printf("output ratematching e[%d]= %d r_offset %d\n", i,dlsch->harq_processes[harq_pid]->e[i+r_offset], r_offset);
...@@ -442,6 +452,7 @@ int nr_dlsch_encoding(unsigned char *a, ...@@ -442,6 +452,7 @@ int nr_dlsch_encoding(unsigned char *a,
dlsch->harq_processes[harq_pid]->f+r_offset); dlsch->harq_processes[harq_pid]->f+r_offset);
//stop_meas(i_stats); //stop_meas(i_stats);
#ifdef DEBUG_DLSCH_CODING #ifdef DEBUG_DLSCH_CODING
for (int i =0; i<16; i++) for (int i =0; i<16; i++)
printf("output interleaving f[%d]= %d r_offset %d\n", i,dlsch->harq_processes[harq_pid]->f[i+r_offset], r_offset); printf("output interleaving f[%d]= %d r_offset %d\n", i,dlsch->harq_processes[harq_pid]->f[i+r_offset], r_offset);
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#define MAX_NUM_NR_ULSCH_SEGMENTS MAX_NUM_NR_DLSCH_SEGMENTS #define MAX_NUM_NR_ULSCH_SEGMENTS MAX_NUM_NR_DLSCH_SEGMENTS
#define MAX_NR_DLSCH_PAYLOAD_BYTES (MAX_NUM_NR_DLSCH_SEGMENTS*1056) #define MAX_NR_DLSCH_PAYLOAD_BYTES (MAX_NUM_NR_DLSCH_SEGMENTS*1056)
#define MAX_NR_ULSCH_PAYLOAD_BYTES (MAX_NUM_NR_DLSCH_SEGMENTS*1056) #define MAX_NR_ULSCH_PAYLOAD_BYTES (MAX_NUM_NR_ULSCH_SEGMENTS*1056)
#define MAX_NUM_NR_CHANNEL_BITS (14*273*12*6) // 14 symbols, 273 RB #define MAX_NUM_NR_CHANNEL_BITS (14*273*12*6) // 14 symbols, 273 RB
#define MAX_NUM_NR_RE (14*273*12) #define MAX_NUM_NR_RE (14*273*12)
......
...@@ -1006,6 +1006,9 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, ...@@ -1006,6 +1006,9 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue,
uint8_t is_crnti, uint8_t is_crnti,
uint8_t llr8_flag); uint8_t llr8_flag);
int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch,
NR_DL_FRAME_PARMS* frame_parms);
uint32_t nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue, uint32_t nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
UE_nr_rxtx_proc_t *proc, UE_nr_rxtx_proc_t *proc,
int eNB_id, int eNB_id,
......
...@@ -102,6 +102,8 @@ typedef struct { ...@@ -102,6 +102,8 @@ typedef struct {
uint16_t first_rb; uint16_t first_rb;
/// Current Number of RBs /// Current Number of RBs
uint16_t nb_rb; uint16_t nb_rb;
/// number of layers
uint8_t Nl;
/// Last TPC command /// Last TPC command
uint8_t TPC; uint8_t TPC;
/// Transport block size /// Transport block size
...@@ -117,17 +119,17 @@ typedef struct { ...@@ -117,17 +119,17 @@ typedef struct {
/// Redundancy-version of the current sub-frame /// Redundancy-version of the current sub-frame
uint8_t rvidx; uint8_t rvidx;
/// pointer to pdu from MAC interface (TS 36.212 V15.4.0, Sec 5.1 p. 8) /// pointer to pdu from MAC interface (TS 36.212 V15.4.0, Sec 5.1 p. 8)
uint8_t *a; unsigned char *a;
/// Pointer to the payload + CRC /// Pointer to the payload + CRC
uint8_t *b; uint8_t *b;
/// Pointers to transport block segments /// Pointers to transport block segments
uint8_t *c[MAX_NUM_NR_ULSCH_SEGMENTS]; uint8_t *c[MAX_NUM_NR_ULSCH_SEGMENTS];
/// LDPC-code outputs
uint8_t *d[MAX_NUM_NR_ULSCH_SEGMENTS];
/// LDPC-code outputs (TS 36.212 V15.4.0, Sec 5.3.2 p. 17) /// LDPC-code outputs (TS 36.212 V15.4.0, Sec 5.3.2 p. 17)
uint8_t *d[MAX_NUM_NR_ULSCH_SEGMENTS]; // 66*Z_c is the maximum LDPC block length. We use 68 for internal manipulation of the buffer uint8_t e[MAX_NUM_NR_CHANNEL_BITS] __attribute__((aligned(32)));
/// Rate matching (Bit selection) outputs (TS 36.212 V15.4.0, Sec 5.4.2.1 p. 28)
uint8_t *e[MAX_NUM_NR_ULSCH_SEGMENTS];
/// Rate matching (Interleaving) outputs (TS 36.212 V15.4.0, Sec 5.4.2.2 p. 30) /// Rate matching (Interleaving) outputs (TS 36.212 V15.4.0, Sec 5.4.2.2 p. 30)
uint8_t *f[MAX_NUM_NR_ULSCH_SEGMENTS]; uint8_t f[MAX_NUM_NR_CHANNEL_BITS] __attribute__((aligned(32)));
/// Number of code segments /// Number of code segments
uint32_t C; uint32_t C;
/// Number of bits in code segments /// Number of bits in code segments
...@@ -162,6 +164,8 @@ typedef struct { ...@@ -162,6 +164,8 @@ typedef struct {
typedef struct { typedef struct {
/// Current Number of Symbols /// Current Number of Symbols
uint8_t Nsymb_pusch; uint8_t Nsymb_pusch;
/// number of DMRS resource elements
uint8_t nb_re_dmrs;
/// SRS active flag /// SRS active flag
uint8_t srs_active; uint8_t srs_active;
//#if defined(UPGRADE_RAT_NR) //#if defined(UPGRADE_RAT_NR)
......
...@@ -122,7 +122,7 @@ char quantize(double D, double x, unsigned char B) { ...@@ -122,7 +122,7 @@ char quantize(double D, double x, unsigned char B) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
char c; char c;
int i; //,j,l,aa; int i,sf; //,j,l,aa;
double SNR, SNR_lin, snr0 = -2.0, snr1 = 2.0; double SNR, SNR_lin, snr0 = -2.0, snr1 = 2.0;
double snr_step = 0.1; double snr_step = 0.1;
uint8_t snr1set = 0; uint8_t snr1set = 0;
...@@ -438,7 +438,7 @@ int main(int argc, char **argv) { ...@@ -438,7 +438,7 @@ int main(int argc, char **argv) {
//nr_init_frame_parms_ue(&UE->frame_parms); //nr_init_frame_parms_ue(&UE->frame_parms);
//init_nr_ue_transport(UE, 0); //init_nr_ue_transport(UE, 0);
for (int sf = 0; sf < 2; sf++) { for (sf = 0; sf < 2; sf++) {
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
UE->dlsch[sf][0][i] = new_nr_ue_dlsch(Kmimo, 8, Nsoft, 5, N_RB_DL, UE->dlsch[sf][0][i] = new_nr_ue_dlsch(Kmimo, 8, Nsoft, 5, N_RB_DL,
0); 0);
...@@ -464,6 +464,9 @@ int main(int argc, char **argv) { ...@@ -464,6 +464,9 @@ int main(int argc, char **argv) {
unsigned char harq_pid = 0; //dlsch->harq_ids[subframe]; unsigned char harq_pid = 0; //dlsch->harq_ids[subframe];
NR_gNB_DLSCH_t *dlsch = gNB->dlsch[0][0]; NR_gNB_DLSCH_t *dlsch = gNB->dlsch[0][0];
nfapi_nr_dl_config_dlsch_pdu_rel15_t *rel15 = &dlsch->harq_processes[harq_pid]->dlsch_pdu.dlsch_pdu_rel15; nfapi_nr_dl_config_dlsch_pdu_rel15_t *rel15 = &dlsch->harq_processes[harq_pid]->dlsch_pdu.dlsch_pdu_rel15;
NR_UE_ULSCH_t *ulsch = UE->ulsch[0][0][0];
//time_stats_t *rm_stats, *te_stats, *i_stats; //time_stats_t *rm_stats, *te_stats, *i_stats;
uint8_t is_crnti = 0, llr8_flag = 0; uint8_t is_crnti = 0, llr8_flag = 0;
unsigned int TBS = 8424; unsigned int TBS = 8424;
...@@ -474,6 +477,7 @@ int main(int argc, char **argv) { ...@@ -474,6 +477,7 @@ int main(int argc, char **argv) {
uint8_t Nl = 1; uint8_t Nl = 1;
uint8_t rvidx = 0; uint8_t rvidx = 0;
dlsch->rnti = 1; dlsch->rnti = 1;
ulsch->nb_re_dmrs = nb_re_dmrs; //[adk] A HOT FIX until cearting nfapi_nr_ul_config_ulsch_pdu_rel15_t
/*dlsch->harq_processes[0]->mcs = Imcs; /*dlsch->harq_processes[0]->mcs = Imcs;
dlsch->harq_processes[0]->rvidx = rvidx;*/ dlsch->harq_processes[0]->rvidx = rvidx;*/
//printf("dlschsim harqid %d nb_rb %d, mscs %d\n",dlsch->harq_ids[subframe], //printf("dlschsim harqid %d nb_rb %d, mscs %d\n",dlsch->harq_ids[subframe],
...@@ -497,9 +501,13 @@ int main(int argc, char **argv) { ...@@ -497,9 +501,13 @@ int main(int argc, char **argv) {
unsigned char *estimated_output_bit; unsigned char *estimated_output_bit;
unsigned char *test_input_bit; unsigned char *test_input_bit;
unsigned int errors_bit = 0; unsigned int errors_bit = 0;
test_input_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); test_input_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384);
estimated_output = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); estimated_output = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384);
estimated_output_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); estimated_output_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384);
NR_UE_DLSCH_t *dlsch0_ue = UE->dlsch[0][0][0]; NR_UE_DLSCH_t *dlsch0_ue = UE->dlsch[0][0][0];
NR_DL_UE_HARQ_t *harq_process = dlsch0_ue->harq_processes[harq_pid]; NR_DL_UE_HARQ_t *harq_process = dlsch0_ue->harq_processes[harq_pid];
harq_process->mcs = Imcs; harq_process->mcs = Imcs;
...@@ -516,6 +524,26 @@ int main(int argc, char **argv) { ...@@ -516,6 +524,26 @@ int main(int argc, char **argv) {
estimated_output = harq_process->b; estimated_output = harq_process->b;
/////////////////////////[adk] preparing UL harq_process parameters/////////////////////////
///////////
NR_UL_UE_HARQ_t *harq_process_ul_ue = ulsch->harq_processes[harq_pid];
if (harq_process_ul_ue){
harq_process_ul_ue->mcs = Imcs;
harq_process_ul_ue->Nl = Nl;
harq_process_ul_ue->nb_rb = nb_rb;
harq_process_ul_ue->nb_symbols = nb_symb_sch;
harq_process_ul_ue->rvidx = rvidx;
harq_process_ul_ue->TBS = TBS;
harq_process_ul_ue->a = &test_input[0];
}
///////////
////////////////////////////////////////////////////////////////////////////////////////////
#ifdef DEBUG_DLSCHSIM #ifdef DEBUG_DLSCHSIM
for (i = 0; i < TBS / 8; i++) printf("test_input[i]=%d \n",test_input[i]); for (i = 0; i < TBS / 8; i++) printf("test_input[i]=%d \n",test_input[i]);
#endif #endif
...@@ -527,6 +555,7 @@ int main(int argc, char **argv) { ...@@ -527,6 +555,7 @@ int main(int argc, char **argv) {
// generate signal // generate signal
if (input_fd == NULL) { if (input_fd == NULL) {
nr_dlsch_encoding(test_input, subframe, dlsch, frame_parms); nr_dlsch_encoding(test_input, subframe, dlsch, frame_parms);
nr_ulsch_encoding(ulsch, frame_parms);
} }
for (SNR = snr0; SNR < snr1; SNR += snr_step) { for (SNR = snr0; SNR < snr1; SNR += snr_step) {
...@@ -540,10 +569,14 @@ int main(int argc, char **argv) { ...@@ -540,10 +569,14 @@ int main(int argc, char **argv) {
if ((i&0xf)==0) if ((i&0xf)==0)
printf("\ne %d..%d: ",i,i+15); printf("\ne %d..%d: ",i,i+15);
#endif #endif
/*
if (i<16){
printf("dlsch_encoder output f[%d] = %d\n",i,dlsch->harq_processes[0]->f[i]);
printf("ulsch_encoder output f[%d] = %d\n",i,ulsch->harq_processes[0]->f[i]);
//if (i<16) }
// printf("encoder output f[%d] = %d\n",i,dlsch->harq_processes[0]->f[i]); */
if (dlsch->harq_processes[0]->f[i] == 0) if (ulsch->harq_processes[0]->f[i] == 0)
modulated_input[i] = 1.0; ///sqrt(2); //QPSK modulated_input[i] = 1.0; ///sqrt(2); //QPSK
else else
modulated_input[i] = -1.0; ///sqrt(2); modulated_input[i] = -1.0; ///sqrt(2);
...@@ -594,7 +627,7 @@ int main(int argc, char **argv) { ...@@ -594,7 +627,7 @@ int main(int argc, char **argv) {
errors_bit = 0; errors_bit = 0;
for (i = 0; i < TBS; i++) { for (i = 0; i < TBS; i++) {
estimated_output_bit[i] = (dlsch0_ue->harq_processes[0]->b[i / 8] & (1 << (i & 7))) >> (i & 7); estimated_output_bit[i] = (ulsch->harq_processes[0]->b[i / 8] & (1 << (i & 7))) >> (i & 7);
test_input_bit[i] = (test_input[i / 8] & (1 << (i & 7))) >> (i & 7); // Further correct for multiple segments test_input_bit[i] = (test_input[i / 8] & (1 << (i & 7))) >> (i & 7); // Further correct for multiple segments
if (estimated_output_bit[i] != test_input_bit[i]) { if (estimated_output_bit[i] != test_input_bit[i]) {
...@@ -653,12 +686,24 @@ int main(int argc, char **argv) { ...@@ -653,12 +686,24 @@ int main(int argc, char **argv) {
} }
}*/ }*/
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
printf("gNB %d\n", i); printf("gNB %d\n", i);
free_gNB_dlsch(gNB->dlsch[0][i]);
printf("UE %d\n", i); if (gNB->dlsch[0][i])
free_nr_ue_dlsch(UE->dlsch[0][0][i]); free_gNB_dlsch(gNB->dlsch[0][i]);
free_nr_ue_ulsch(UE->ulsch[0][0][i]);
for (sf = 0; sf < 2; sf++) {
printf("UE %d\n", i);
if (UE->dlsch[sf][0][i])
free_nr_ue_dlsch(UE->dlsch[sf][0][i]);
if (UE->ulsch[sf][0][i])
free_nr_ue_ulsch(UE->ulsch[sf][0][i]);
}
} }
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment