Commit 9e75b806 authored by yihongzheng's avatar yihongzheng

FPGA LDPC run more data OK, but SIB decode just success once

parent a9d3c4ac
...@@ -545,7 +545,8 @@ const char* eurecomFunctionsNames[] = { ...@@ -545,7 +545,8 @@ const char* eurecomFunctionsNames[] = {
"pss_synchro_nr", "pss_synchro_nr",
"pss_search_time_nr", "pss_search_time_nr",
"nr_initial_ue_sync", "nr_initial_ue_sync",
"beam_switching_gpio" "beam_switching_gpio",
"dl_encode_ldpc_fpga"
}; };
struct vcd_module_s vcd_modules[] = { struct vcd_module_s vcd_modules[] = {
......
...@@ -538,7 +538,7 @@ typedef enum { ...@@ -538,7 +538,7 @@ typedef enum {
VCD_SIGNAL_DUMPER_FUNCTIONS_PSS_SEARCH_TIME_NR, VCD_SIGNAL_DUMPER_FUNCTIONS_PSS_SEARCH_TIME_NR,
VCD_SIGNAL_DUMPER_FUNCTIONS_NR_INITIAL_UE_SYNC, VCD_SIGNAL_DUMPER_FUNCTIONS_NR_INITIAL_UE_SYNC,
VCD_SIGNAL_DUMPER_FUNCTIONS_BEAM_SWITCHING_GPIO, VCD_SIGNAL_DUMPER_FUNCTIONS_BEAM_SWITCHING_GPIO,
VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DL_Encode_LPDC_FPGA,
VCD_SIGNAL_DUMPER_FUNCTIONS_END VCD_SIGNAL_DUMPER_FUNCTIONS_END
} vcd_signal_dump_functions; } vcd_signal_dump_functions;
......
...@@ -73,7 +73,8 @@ typedef struct { ...@@ -73,7 +73,8 @@ typedef struct {
} T_cache_t; } T_cache_t;
/* number of VCD functions (to be kept up to date! see in T_messages.txt) */ /* number of VCD functions (to be kept up to date! see in T_messages.txt) */
#define VCD_NUM_FUNCTIONS (273) // #define VCD_NUM_FUNCTIONS (273)
#define VCD_NUM_FUNCTIONS (274)
/* number of VCD variables (to be kept up to date! see in T_messages.txt) */ /* number of VCD variables (to be kept up to date! see in T_messages.txt) */
#define VCD_NUM_VARIABLES (187) #define VCD_NUM_VARIABLES (187)
......
...@@ -3560,4 +3560,8 @@ ID = VCD_FUNCTION_BEAM_SWITCHING_GPIO ...@@ -3560,4 +3560,8 @@ ID = VCD_FUNCTION_BEAM_SWITCHING_GPIO
GROUP = ALL:VCD:ENB:VCD_FUNCTION GROUP = ALL:VCD:ENB:VCD_FUNCTION
FORMAT = int,value FORMAT = int,value
VCD_NAME = beam_switching_gpio VCD_NAME = beam_switching_gpio
ID = VCD_FUNCTION_gNB_DL_Encode_LPDC_FPGA
DESC = VCD function gNB_DL_Encode_LPDC_FPGA
GROUP = ALL:VCD:ENB:VCD_FUNCTION
FORMAT = int,value
VCD_NAME = dl_encode_ldpc_fpga
...@@ -77,6 +77,11 @@ void nr_pdsch_codeword_scrambling_optim(uint8_t *in, ...@@ -77,6 +77,11 @@ void nr_pdsch_codeword_scrambling_optim(uint8_t *in,
uint32_t* out) { uint32_t* out) {
uint32_t x1, x2, s=0,in32; uint32_t x1, x2, s=0,in32;
static uint32_t count_data = 0;
uint8_t *u8data;
uint32_t *pin32;
uint32_t byteSize = size/8;
// AssertFatal(size%8==0,"ByteSize is not 8\n");
x2 = (n_RNTI<<15) + (q<<14) + Nid; x2 = (n_RNTI<<15) + (q<<14) + Nid;
...@@ -84,12 +89,45 @@ void nr_pdsch_codeword_scrambling_optim(uint8_t *in, ...@@ -84,12 +89,45 @@ void nr_pdsch_codeword_scrambling_optim(uint8_t *in,
#if defined(__AVX2__) #if defined(__AVX2__)
#if 0 //OAI自己的加扰代码
for (int i=0; i<((size>>5)+((size&0x1f) > 0 ? 1 : 0)); i++) { for (int i=0; i<((size>>5)+((size&0x1f) > 0 ? 1 : 0)); i++) {
in32=_mm256_movemask_epi8(_mm256_slli_epi16(((__m256i*)in)[i],7)); in32=_mm256_movemask_epi8(_mm256_slli_epi16(((__m256i*)in)[i],7));
out[i]=(in32^s); out[i]=(in32^s);
// u8data = (uint8_t *)&in32;
// if(i < 10)
// {
// LOG_I(PHY, "in32 = %x, %02x, %02x, %02x, %02x\n",in32, u8data[0],u8data[1],u8data[2],u8data[3]);
// }
//printf("in[%d] %x => %x\n",i,in32,out[i]); //printf("in[%d] %x => %x\n",i,in32,out[i]);
s=lte_gold_generic(&x1, &x2, 0); s=lte_gold_generic(&x1, &x2, 0);
} }
if(count_data == 9)
{
LOG_M("out1.m","out1", out, (byteSize+3)/4, 1, 9);
}
count_data++;
#endif
#if 1
//让FPGA输出的每个BYTE中的高低位bit翻转
//LOG_I(PHY, "in = %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x\n",in[0],in[1],in[2],in[3],in[4],in[5],in[6],in[7]);
Byte_Reverse_11(in, in, byteSize);
pin32 = (uint32_t *)in;
// if(count_data == 9)
// {
// LOG_M("pin32.m","pin32", pin32, byteSize, 1, 9);
// }
//LOG_I(PHY, "in32 = %x, %x, %x, %x, %02x, %02x, %02x, %02x\n",pin32[0],pin32[1],pin32[2],pin32[3],in[0],in[1],in[2],in[3]);
for(int j = 0; j < (byteSize+3)/4; j++)
{
out[j]=(pin32[j]^s);
s=lte_gold_generic(&x1, &x2, 0);
}
// if(count_data == 9)
// {
// LOG_M("out.m","out", out, (byteSize+3)/4, 1, 9);
// }
// count_data++;
#endif
#elif defined(__SSE4__) #elif defined(__SSE4__)
_m128i *in128; _m128i *in128;
for (int i=0; i<((size>>5)+((size&0x1f) > 0 ? 1 : 0)); i++) { for (int i=0; i<((size>>5)+((size&0x1f) > 0 ? 1 : 0)); i++) {
...@@ -99,6 +137,7 @@ void nr_pdsch_codeword_scrambling_optim(uint8_t *in, ...@@ -99,6 +137,7 @@ void nr_pdsch_codeword_scrambling_optim(uint8_t *in,
out[i]=(in32^s); out[i]=(in32^s);
s=lte_gold_generic(&x1, &x2, 0); s=lte_gold_generic(&x1, &x2, 0);
} }
log_dump(PHY, out, 32, LOG_DUMP_CHAR,"__SSE4__out[] = \n");
//#elsif defined(__arm__) || defined(__aarch64) //#elsif defined(__arm__) || defined(__aarch64)
#else #else
...@@ -108,6 +147,7 @@ void nr_pdsch_codeword_scrambling_optim(uint8_t *in, ...@@ -108,6 +147,7 @@ void nr_pdsch_codeword_scrambling_optim(uint8_t *in,
Nid, Nid,
n_RNTI, n_RNTI,
out); out);
LOG_I(PHY,"nr_pdsch_codeword_scrambling\n");
#endif #endif
} }
...@@ -548,3 +588,28 @@ void clear_pdsch_stats(PHY_VARS_gNB *gNB) { ...@@ -548,3 +588,28 @@ void clear_pdsch_stats(PHY_VARS_gNB *gNB) {
for (int i=0;i<NUMBER_OF_NR_DLSCH_MAX;i++) for (int i=0;i<NUMBER_OF_NR_DLSCH_MAX;i++)
memset((void*)&gNB->dlsch_stats[i],0,sizeof(gNB->dlsch_stats[i])); memset((void*)&gNB->dlsch_stats[i],0,sizeof(gNB->dlsch_stats[i]));
} }
unsigned char Reverse8U(unsigned char x)
{
x = (x & 0xaa) >> 1 | (x & 0x55) << 1;
x = (x & 0xcc) >> 2 | (x & 0x33) << 2;
x = (x & 0xf0) >> 4 | (x & 0x0f) << 4;
return x;
}
void Byte_Reverse_11(unsigned char *Src, unsigned char *Dest, int Length)
{
int BlockSize = 16, Block = Length / BlockSize;
for (int Y = 0; Y < Block * BlockSize; Y += BlockSize)
{
__m128i V = _mm_loadu_si128((__m128i *)(Src + Y));
V = _mm_or_si128(_mm_srli_epi16(_mm_and_si128(V, _mm_set1_epi8(0xaa)), 1), _mm_slli_epi16(_mm_and_si128(V, _mm_set1_epi8(0x55)), 1));
V = _mm_or_si128(_mm_srli_epi16(_mm_and_si128(V, _mm_set1_epi8(0xcc)), 2), _mm_slli_epi16(_mm_and_si128(V, _mm_set1_epi8(0x33)), 2));
V = _mm_or_si128(_mm_srli_epi16(_mm_and_si128(V, _mm_set1_epi8(0xf0)), 4), _mm_slli_epi16(_mm_and_si128(V, _mm_set1_epi8(0x0f)), 4));
_mm_storeu_si128((__m128i *)(Dest + Y), V);
}
for (int Y = Block * BlockSize; Y < Length; Y++)
{
Dest[Y] = Reverse8U(Src[Y]);
}
}
\ No newline at end of file
...@@ -104,4 +104,8 @@ void clear_pdsch_stats(PHY_VARS_gNB *gNB); ...@@ -104,4 +104,8 @@ void clear_pdsch_stats(PHY_VARS_gNB *gNB);
void dl_find_iLS_lsIndex(unsigned int *LDPC_lifting_size, uint32_t *iLS_out, uint32_t *lsIndex_out); void dl_find_iLS_lsIndex(unsigned int *LDPC_lifting_size, uint32_t *iLS_out, uint32_t *lsIndex_out);
unsigned char Reverse8U(unsigned char x);
void Byte_Reverse_11(unsigned char *Src, unsigned char *Dest, int Length);
#endif #endif
...@@ -241,6 +241,8 @@ void clean_gNB_dlsch(NR_gNB_DLSCH_t *dlsch) ...@@ -241,6 +241,8 @@ void clean_gNB_dlsch(NR_gNB_DLSCH_t *dlsch)
} }
} }
#if 1
// unsigned char EnDataOut[0x20000]={0};
int nr_dlsch_encoding(PHY_VARS_gNB *gNB, int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
unsigned char *a, unsigned char *a,
int frame, int frame,
...@@ -285,15 +287,14 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB, ...@@ -285,15 +287,14 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
EncodeInHeaderStruct EncodeHead; EncodeInHeaderStruct EncodeHead;
uint8_t *pEnDataIn = NULL; uint8_t *pEnDataIn = NULL;
uint8_t *pEnDataOut = NULL; uint8_t *pEnDataOut = NULL;
pEnDataOut=(unsigned char *)malloc(0x400000); // pEnDataOut=(unsigned char *)malloc(0x20000);
static uint32_t iLS = 0; // uint8_t *pEnDataOut = EnDataOut;
static uint32_t lsIndex = 0; uint32_t iLS = 0;
uint32_t *iLS_out = &iLS; uint32_t lsIndex = 0;
uint32_t *lsIndex_out = &lsIndex;
uint32_t dl_E0 = 0, dl_E1 = 0; uint32_t dl_E0 = 0, dl_E1 = 0;
uint32_t *dl_e0 = &dl_E0, *dl_e1 = &dl_E1;
pEnDataIn = a; pEnDataIn = a;
pEnDataOut = harq->f;
// int sum = add(7, 8); // int sum = add(7, 8);
// printf("7+8 = %d\n", sum); // printf("7+8 = %d\n", sum);
#endif #endif
...@@ -322,7 +323,7 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB, ...@@ -322,7 +323,7 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
} }
G = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs,mod_order,rel15->nrOfLayers); G = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs,mod_order,rel15->nrOfLayers);
LOG_D(PHY,"dlsch coding A %d G %d (nb_rb %d, nb_symb_sch %d, nb_re_dmrs %d, length_dmrs %d, mod_order %d)\n", A,G, nb_rb,nb_symb_sch,nb_re_dmrs,length_dmrs,mod_order); LOG_I(PHY,"dlsch coding A %d G %d (nb_rb %d, nb_symb_sch %d, nb_re_dmrs %d, length_dmrs %d, mod_order %d)\n", A,G, nb_rb,nb_symb_sch,nb_re_dmrs,length_dmrs,mod_order);
if (A > 3824) { if (A > 3824) {
// Add 24-bit crc (polynomial A) to payload // Add 24-bit crc (polynomial A) to payload
...@@ -491,7 +492,11 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB, ...@@ -491,7 +492,11 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
r_offset += E; r_offset += E;
} }
#if 1 #if 1
if(dl_encode_count == dl_encode_count_set2){ LOG_I(PHY, "dl_encode_count = %d\n", dl_encode_count);
// if(dl_encode_count == dl_encode_count_set2)
{
// LOG_M("harq->f.m","harq->f", harq->f, G+32, 1, 9);
//使输入参数固定,测试使用
// int dl_encode_i; // int dl_encode_i;
// for (dl_encode_i = 0; dl_encode_i<(rel15->TBSize[0]); dl_encode_i++){ // for (dl_encode_i = 0; dl_encode_i<(rel15->TBSize[0]); dl_encode_i++){
// a[dl_encode_i] = dl_encode_i; // a[dl_encode_i] = dl_encode_i;
...@@ -499,6 +504,7 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB, ...@@ -499,6 +504,7 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
// int fileSize,ret; // int fileSize,ret;
// FILE *fp; // FILE *fp;
#if 0 #if 0
//demo中从文件里读取固定的数据,测试使用
fp=fopen("oai_encode_data_0.bin","rb"); fp=fopen("oai_encode_data_0.bin","rb");
if(fp==NULL){ if(fp==NULL){
printf("This oai_encode_data_0 file is open failed.\n"); printf("This oai_encode_data_0 file is open failed.\n");
...@@ -512,6 +518,7 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB, ...@@ -512,6 +518,7 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
fclose(fp); fclose(fp);
#endif #endif
#if 1 #if 1
//FPGA加速的头部
//word 0 //word 0
EncodeHead.pktType = 0x12; EncodeHead.pktType = 0x12;
EncodeHead.rsv0 = 0x00; EncodeHead.rsv0 = 0x00;
...@@ -562,9 +569,9 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB, ...@@ -562,9 +569,9 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
EncodeHead.rvIdx = rel15->rvIndex[0]; EncodeHead.rvIdx = rel15->rvIndex[0];
EncodeHead.rev12 = 0x0; EncodeHead.rev12 = 0x0;
//查找iLS和lfSizeIx //查找iLS和lfSizeIx
dl_find_iLS_lsIndex(Zc, iLS_out, lsIndex_out); dl_find_iLS_lsIndex(Zc, &iLS, &lsIndex);
EncodeHead.iLs = *iLS_out; EncodeHead.iLs = iLS;
EncodeHead.lfSizeIx = *lsIndex_out; EncodeHead.lfSizeIx = lsIndex;
EncodeHead.rev13 = 0x0; EncodeHead.rev13 = 0x0;
// EncodeHead.iLs = *iLS_out; // EncodeHead.iLs = *iLS_out;
EncodeHead.bg = harq->BG-1; //规定选择协议base grape1 bg=0; base grape2 bg=1;OAI的BG大了1 EncodeHead.bg = harq->BG-1; //规定选择协议base grape1 bg=0; base grape2 bg=1;OAI的BG大了1
...@@ -576,12 +583,13 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB, ...@@ -576,12 +583,13 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
} }
//word 7 //word 7
//计算并获得e0和e1 //计算并获得e0和e1
nr_get_E0_E1(G, harq->C, mod_order, rel15->nrOfLayers, r, dl_e0, dl_e1); nr_get_E0_E1(G, harq->C, mod_order, rel15->nrOfLayers, r, &dl_E0, &dl_E1);
EncodeHead.e0 = *dl_e0; EncodeHead.e0 = dl_E0;
EncodeHead.e1 = *dl_e1; EncodeHead.e1 = dl_E1;
#endif #endif
///////////////////////////////////////////// /////////////////////////////////////////////
#if 0 #if 0
//demo中固定的头部参数
//word 0 //word 0
EncodeHead.pktType=0x12; EncodeHead.pktType=0x12;
EncodeHead.rsv0=0x00; EncodeHead.rsv0=0x00;
...@@ -628,19 +636,308 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB, ...@@ -628,19 +636,308 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
EncodeHead.e1=0x44be; EncodeHead.e1=0x44be;
EncodeHead.e0=0x44b8; EncodeHead.e0=0x44b8;
#endif #endif
printf("EncodeHead_fill_finished\n"); #if 1
//调用FPGA的.so中的编码函数
LOG_I(PHY, "encoder_load_start\n");
// printf("EncodeHead_fill_finished\n");
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DL_Encode_LPDC_FPGA, 1);
encoder_load( &EncodeHead, pEnDataIn, pEnDataOut ); encoder_load( &EncodeHead, pEnDataIn, pEnDataOut );
printf("encoder_load_end\n"); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DL_Encode_LPDC_FPGA, 0);
LOG_I(PHY, "encoder_load_end\n");
// encoder_load( &EncodeHead, pEnDataIn, pEnDataOut ); // encoder_load( &EncodeHead, pEnDataIn, pEnDataOut );
//LOG_M("pEnDataOut.m","pEnDataOut", pEnDataOut, G+32, 1, 9); //LOG_M("pEnDataOut.m","pEnDataOut", pEnDataOut, G+32, 1, 9);
#endif
} }
dl_encode_count++; //count +1 after encoding dl_encode_count++; //count +1 after encoding
// free(pEnDataOut);
#endif #endif
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DLSCH_ENCODING, VCD_FUNCTION_OUT); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DLSCH_ENCODING, VCD_FUNCTION_OUT);
return 0; return 0;
} }
#endif
#if 0
//把OAI中的编码部分去掉后的新函数,但好像还有问题
int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
unsigned char *a,
int frame,
uint8_t slot,
NR_gNB_DLSCH_t *dlsch,
NR_DL_FRAME_PARMS* frame_parms,
time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput,
time_stats_t *dlsch_rate_matching_stats,time_stats_t *dlsch_interleaving_stats,
time_stats_t *dlsch_segmentation_stats)
{
unsigned int G;
unsigned int crc=1;
NR_DL_gNB_HARQ_t *harq = &dlsch->harq_process;
nfapi_nr_dl_tti_pdsch_pdu_rel15_t *rel15 = &harq->pdsch_pdu.pdsch_pdu_rel15;
uint16_t nb_rb = rel15->rbSize;
uint8_t nb_symb_sch = rel15->NrOfSymbols;
uint32_t A, Kb, F=0;
uint32_t *Zc = &dlsch->harq_process.Z;
uint8_t mod_order = rel15->qamModOrder[0];
uint16_t Kr=0,r;
uint32_t r_offset=0;
uint8_t Ilbrm = 1;
uint32_t Tbslbrm = 950984; //max tbs
uint8_t nb_re_dmrs;
int fileSize,ret;
FILE *fp;
if (rel15->dmrsConfigType==NFAPI_NR_DMRS_TYPE1)
nb_re_dmrs = 6*rel15->numDmrsCdmGrpsNoData;
else
nb_re_dmrs = 4*rel15->numDmrsCdmGrpsNoData;
uint16_t length_dmrs = get_num_dmrs(rel15->dlDmrsSymbPos);
uint16_t R=rel15->targetCodeRate[0];
float Coderate = 0.0;
uint8_t Nl = 4;
#if 1
static uint32_t dl_encode_count = 0;
uint32_t dl_encode_count_set2 = 9;
EncodeInHeaderStruct EncodeHead;
uint8_t *pEnDataIn = NULL;
uint8_t *pEnDataOut = NULL;
// pEnDataOut=(unsigned char *)malloc(0x20000);
// uint8_t *pEnDataOut = EnDataOut;
uint32_t iLS = 0;
uint32_t lsIndex = 0;
uint32_t dl_E0 = 0, dl_E1 = 0;
pEnDataIn = a;
pEnDataOut = harq->f;
// int sum = add(7, 8);
// printf("7+8 = %d\n", sum);
#endif
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DLSCH_ENCODING, VCD_FUNCTION_IN);
A = rel15->TBSize[0]<<3;
harq->B = A+24;
NR_gNB_SCH_STATS_t *stats=NULL;
int first_free=-1;
for (int i=0;i<NUMBER_OF_NR_SCH_STATS_MAX;i++) {
if (gNB->dlsch_stats[i].rnti == 0 && first_free == -1) {
first_free = i;
stats=&gNB->dlsch_stats[i];
}
if (gNB->dlsch_stats[i].rnti == dlsch->rnti) {
stats=&gNB->dlsch_stats[i];
break;
}
}
if (stats) {
stats->rnti = dlsch->rnti;
stats->total_bytes_tx += rel15->TBSize[0];
stats->current_RI = rel15->nrOfLayers;
stats->current_Qm = rel15->qamModOrder[0];
}
G = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs,mod_order,rel15->nrOfLayers);
LOG_I(PHY,"dlsch coding A %d G %d (nb_rb %d, nb_symb_sch %d, nb_re_dmrs %d, length_dmrs %d, mod_order %d)\n", A,G, nb_rb,nb_symb_sch,nb_re_dmrs,length_dmrs,mod_order);
if (R<1000)
Coderate = (float) R /(float) 1024;
else // to scale for mcs 20 and 26 in table 5.1.3.1-2 which are decimal and input 2* in nr_tbs_tools
Coderate = (float) R /(float) 2048;
if ((A <=292) || ((A<=3824) && (Coderate <= 0.6667)) || Coderate <= 0.25)
harq->BG = 2;
else
harq->BG = 1;
start_meas(dlsch_segmentation_stats);
Kb = nr_segmentation(NULL, NULL, harq->B, &harq->C, &harq->K, Zc, &harq->F, harq->BG);
stop_meas(dlsch_segmentation_stats);
F = harq->F;
Kr = harq->K;
#ifdef DEBUG_DLSCH_CODING
uint16_t Kr_bytes;
Kr_bytes = Kr>>3;
#endif
//printf("segment Z %d k %d Kr %d BG %d C %d\n", *Zc,harq->K,Kr,BG,harq->C);
#ifdef DEBUG_DLSCH_CODING
write_output("enc_input0.m","enc_in0",&harq->c[0][0],Kr_bytes,1,4);
write_output("enc_output0.m","enc0",&harq->d[0][0],(3*8*Kr_bytes)+12,1,4);
#endif
F = harq->F;
Kr = harq->K;
if (rel15->nrOfLayers < Nl)
Nl = rel15->nrOfLayers;
#if 1
LOG_I(PHY, "dl_encode_count = %d\n", dl_encode_count);
// if(dl_encode_count == dl_encode_count_set2)
{
// int dl_encode_i;
// for (dl_encode_i = 0; dl_encode_i<(rel15->TBSize[0]); dl_encode_i++){
// a[dl_encode_i] = dl_encode_i;
// }
// int fileSize,ret;
// FILE *fp;
#if 0
//demo中从文件里读取固定的数据
fp=fopen("oai_encode_data_0.bin","rb");
if(fp==NULL){
printf("This oai_encode_data_0 file is open failed.\n");
}
fseek(fp,0,SEEK_END);
fileSize=ftell(fp);
rewind(fp);
printf("fileSize=0x%x\n",fileSize);
ret=fread(a,1,fileSize,fp);
fclose(fp);
#endif
#if 1
//word 0
EncodeHead.pktType = 0x12;
EncodeHead.rsv0 = 0x00;
EncodeHead.chkCode = 0xFAFA;
//word 1
EncodeHead.rsv1 = 0x0000;
//word 2
EncodeHead.rsv2 = 0x0;
EncodeHead.sectorId = 0x0;
//=0表示单小区
EncodeHead.rsv3 = 0x0;
//word 3
EncodeHead.sfn = frame;
EncodeHead.rsv4 = 0x0;
EncodeHead.slotNum = slot;
EncodeHead.subfn = EncodeHead.slotNum/2;
EncodeHead.pduIdx = 0x0;
//=0表示第一个码字,总共一个码字
EncodeHead.rev5 = 0x0;
//word 4
EncodeHead.tbSizeB = rel15->TBSize[0];
EncodeHead.pktLen = 32+((EncodeHead.tbSizeB+32-1)/32)*32;
//Byte,pktLen=encoder header(32byte)+ tbszie (byte),并且32Byte对齐,是32的整数倍
EncodeHead.rev6 = 0x0;
EncodeHead.lastTb = 0x1;
EncodeHead.firstTb = 0x1;
//=1表示本slot只有一个TB
EncodeHead.rev7 = 0x0;
EncodeHead.cbNum = harq->C;
//word 5
EncodeHead.qm = stats->current_Qm/2;
//规定是BPSK qm=0,QPSK qm=1,其他floor(调制阶数/2);OAI的Qm为2/4/6/8
EncodeHead.rev8 = 0x0;
EncodeHead.fillbit = harq->F;
EncodeHead.rev9 = 0x0;
if( EncodeHead.cbNum == 1){
EncodeHead.kpInByte = ((harq->B)/ EncodeHead.cbNum)>>3;
}
else{
EncodeHead.kpInByte = ((harq->B+(( EncodeHead.cbNum)*24))/ EncodeHead.cbNum)>>3;
}
EncodeHead.rev10 = 0x0;
//word 6
EncodeHead.gamma = EncodeHead.cbNum - (G/(Nl*(2*EncodeHead.qm)))%EncodeHead.cbNum;
//=1表示本slot只有一个TB
EncodeHead.rev11 = 0x0;
EncodeHead.rvIdx = rel15->rvIndex[0];
EncodeHead.rev12 = 0x0;
//查找iLS和lfSizeIx
dl_find_iLS_lsIndex(Zc, &iLS, &lsIndex);
EncodeHead.iLs = iLS;
EncodeHead.lfSizeIx = lsIndex;
EncodeHead.rev13 = 0x0;
// EncodeHead.iLs = *iLS_out;
EncodeHead.bg = harq->BG-1; //规定选择协议base grape1 bg=0; base grape2 bg=1;OAI的BG大了1
if( EncodeHead.bg == 0){
EncodeHead.codeRate = 46;
}
else{
EncodeHead.codeRate = 42;
}
//word 7
//计算并获得e0和e1
nr_get_E0_E1(G, harq->C, mod_order, rel15->nrOfLayers, r, &dl_E0, &dl_E1);
EncodeHead.e0 = dl_E0;
EncodeHead.e1 = dl_E1;
#endif
/////////////////////////////////////////////
#if 0
//demo中固定的头部参数
//word 0
EncodeHead.pktType=0x12;
EncodeHead.rsv0=0x00;
EncodeHead.chkCode=0xFAFA;
//word 1
EncodeHead.pktLen=0x1000;
EncodeHead.rsv1=0x0000;
//word 2
EncodeHead.rsv2=0x0;
EncodeHead.sectorId=0x0;
EncodeHead.rsv3=0x0;
//word 3
EncodeHead.sfn=0x13c;
EncodeHead.rsv4=0x0;
EncodeHead.subfn=0x1;
EncodeHead.slotNum=0x2;
EncodeHead.pduIdx=0x0;
EncodeHead.rev5=0x0;
//word 4
EncodeHead.tbSizeB=0x0fc1;
EncodeHead.rev6=0x0;
EncodeHead.lastTb=0x1;
EncodeHead.firstTb=0x1;
EncodeHead.rev7=0x0;
EncodeHead.cbNum=0x04;
//word 5
EncodeHead.qm=0x3;
EncodeHead.rev8=0x0;
EncodeHead.fillbit=0x160;
EncodeHead.rev9=0x0;
EncodeHead.kpInByte=0x3f4;
EncodeHead.rev10=0x0;
//word 6
EncodeHead.gamma=0x02;
EncodeHead.codeRate=0x2e;
EncodeHead.rev11=0x0;
EncodeHead.rvIdx=0x0;
EncodeHead.rev12=0x0;
EncodeHead.lfSizeIx=0x7;
EncodeHead.rev13=0x0;
EncodeHead.iLs=0x1;
EncodeHead.bg=0x0;
//word 7
EncodeHead.e1=0x44be;
EncodeHead.e0=0x44b8;
#endif
LOG_I(PHY, "encoder_load_start\n");
// printf("EncodeHead_fill_finished\n");
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DL_Encode_LPDC_FPGA, 1);
encoder_load( &EncodeHead, pEnDataIn, pEnDataOut );
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DL_Encode_LPDC_FPGA, 0);
LOG_I(PHY, "encoder_load_end\n");
// encoder_load( &EncodeHead, pEnDataIn, pEnDataOut );
//LOG_M("pEnDataOut.m","pEnDataOut", pEnDataOut, G+32, 1, 9);
}
dl_encode_count++; //count +1 after encoding
// free(pEnDataOut);
#endif
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DLSCH_ENCODING, VCD_FUNCTION_OUT);
return 0;
}
#endif
void dl_find_iLS_lsIndex(unsigned int *LDPC_lifting_size, uint32_t *iLS_out, uint32_t *lsIndex_out) void dl_find_iLS_lsIndex(unsigned int *LDPC_lifting_size, uint32_t *iLS_out, uint32_t *lsIndex_out)
{ {
unsigned int Set_of_LDPC_lifting_size[8][8] = { unsigned int Set_of_LDPC_lifting_size[8][8] = {
......
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