Commit ee03d228 authored by yihongzheng's avatar yihongzheng

FPGA encode OK, decode not, decode just test, encode need to uncomment

parent ee45cf21
......@@ -71,7 +71,7 @@ int load_nrLDPClib(void) {
nrLDPC_encoder = (nrLDPC_encoderfunc_t)shlib_fdesc[1].fptr;
//手动加载指定位置的so动态库
void *handle = dlopen("/home/witcomm/work/yihz_5gran/FecDemo/cDemo2/ldpc_fpga_encode.so", RTLD_LAZY|RTLD_NODELETE|RTLD_GLOBAL);
void *handle = dlopen("/home/witcomm/work/yihz_5gran/ran/yihz/FecDemo/cDemo2/ldpc_fpga_encode.so", RTLD_LAZY|RTLD_NODELETE|RTLD_GLOBAL);
if(!handle){
printf("open ldpc_fpga_encode error!\n");
return -1;
......
PREGCC=
TARGET=FFTest
GCC=$(PREGCC)gcc
SYS_INC=/usr/local/include/dev2.0
INCLUDE_DIR := -I$(SYS_INC)
INCLUDE_DIR += -I$(SYS_INC)/9371base
INCLUDE_DIR += -I$(SYS_INC)/ecpriBase
INCLUDE_DIR += -I$(SYS_INC)/fr9371
INCLUDE_DIR += -I$(SYS_INC)/frecpri
INCLUDE_DIR += -I$(SYS_INC)/wi9371
INCLUDE_DIR += -I$(SYS_INC)/wiecpri
LIB_DIR = -lpthread -lhugetlbfs
LIB_DIR1 = -lhugetlbfs
LIB_DIR2 = -ldev2.0
CURDIR:=$(shell pwd)
SRCDIR2 := $(CURDIR)
SRCS := $(wildcard *.c)
OBJS = $(SRCS:%.c=%.o)
CCFLAGS := -g -O2 $(INCLUDE_DIR)
$(TARGET):$(OBJS)
$(GCC) $(CCFLAGS) $(OBJS) -o $@ $(LIB_DIR) $(LIB_DIR2)
%.o: %.c
$(GCC) $(INCLUDE_DIR) $(CCFLAGS) -c $< -o $@
clean:
rm -rf $(OBJS) $(TARGET)
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "logger_wrapper.h"
#include "ff_define.h"
int getBinDataFromFile(unsigned char *pData, int *len,char *fname)
{
int fileSize,ret;
FILE *fp;
int i,j,count;
int tempData;
fp=fopen(fname,"rb");
if(fp==NULL){
printf("This %s file is open failed.\n",fname);
}
fseek(fp,0,SEEK_END);
fileSize=ftell(fp);
rewind(fp);
printf("fileSize=0x%x\n",fileSize);
ret=fread(pData,1,fileSize,fp);
*len=fileSize;
//printf("ret=0x%x\n",ret);
fclose(fp);
return 1;
}
//
//
//
////////////////////////////////
void saveBinDataTofile(unsigned char *pData,int len,char * fname)
{
int i,fileSize,ret;
FILE *fp;
fp=fopen(fname,"wb+");
if(fp==NULL){
printf("This %s file is open failed.\n",fname);
}
ret=fwrite(pData,1,len,fp);
//printf("ret=0x%x\n",ret);
fclose(fp);
}
char tempData[512];
char saveDataDirDe[]="/tmp/saveData/de";
char saveDataDirEn[]="/tmp/saveData/en";
static int count1=0,count2=0,loop_count_de=0,loop_count_en=0;
void saveBinData(unsigned char *pData, int type)
{
int i;
DataHeadInfo *pDataHeadInfo;
DataHeadInfo TempDataHead;
unsigned char *pDataHead;
char fname[64];
pDataHeadInfo=(DataHeadInfo *)pData;
if(type==FEC_DECODE_DATA){
loop_count_de++;
if(loop_count_de>=100000){
sprintf(fname,"%s/decode_%08d.bin",saveDataDirDe,count2++);
saveBinDataTofile(pData, pDataHeadInfo->pktLen, fname);
loop_count_de=0;
}
}else if(type==FEC_ENCODE_DATA){
loop_count_en++;
if(loop_count_en>=200000){
sprintf(fname,"%s/encode_%08d.bin",saveDataDirEn,count1++);
saveBinDataTofile(pData, pDataHeadInfo->pktLen, fname);
loop_count_en=0;
}
}
//zLog(PHY_LOG_INFO,"rec header: len=%x---[DRV_LOG]",pDataHeadInfo->pktLen);
}
//
//
//
//
////////////////////////////////////////////
void load_expect_data(unsigned char *pData, char *fname)
{
int len;
getBinDataFromFile(pData, &len, fname);
}
//
//
//
//
////////////////////////////////////////////
int compare_data(unsigned char *pDst1, unsigned char *pDst2, int len)
{
int ret=0;
//ret=memcmp(pDst1,pDst2,len);
return ret;
}
#ifndef __DEV2_DATA_FILE__
#define __DEV2_DATA_FILE__
//
int getBinDataFromFile(unsigned char *pData,int *len, char * fname);
//
void saveBinDataTofile(unsigned char *pData,int len, char *fname);
//
void saveBinData(unsigned char *pData, int type);
//
int compare_data(unsigned char *pDst1, unsigned char *pDst2, int len);
//
void load_expect_data(unsigned char *pData, char *fname);
#endif //__DEV2_DATA_FILE__
This source diff could not be displayed because it is too large. You can view the blob instead.
#ifndef __FF_DEMO_DEFINE__
#define __FF_DEMO_DEFINE__
#define FPGA_FRONTHAUL 0
#define FPGA_FEC 1
#define FPGA_NUM 2
#define IS_FREE 0
#define IS_BUSY 1
#define IS_FULL 2
#define IS_INVAL 3
#define MILLION 1000000
#define THOUSAND 1000
#define FEC_DECODE_DATA 0x01
#define FEC_ENCODE_DATA 0x02
// log mask
#define ZLOG_DRIVER_DM_TX (1<<20)
#define ZLOG_DRIVER_DM_RX (1<<21)
#define ZLOG_DRIVER_DM_FEC (1<<22)
#define ZLOG_DRIVER_DM_STATUS (1<<23)
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;
typedef int int32_t;
typedef long int int64_t;
typedef short int int16_t;
#include "fec_c_if.h"
/*
typedef struct __DescriptorAddrRingStruct
{
uint32_t nRingBufferPoolIndex;
HugepageTblStruct RxFhRingBuffer;
HugepageTblStruct RxEnCodeRingBuffer;
HugepageTblStruct RxDeCodeRingBuffer;
HugepageTblStruct SyncFhRingBuffer;
HugepageTblStruct TxFhRingBuffer;
HugepageTblStruct TxEnCodeRingBuffer;
HugepageTblStruct TxDeCodeRingBuffer;
uint64_t BaseAddress;
}DescriptorAddrRingStruct;
typedef struct __DmaDescInfo
{
uint32_t nAddressHigh;
uint32_t nAddressLow;
uint32_t nAddressLen;
uint32_t rsvrd;
}DescInfo;
typedef struct __DmaDescChainInfo
{
volatile uint32_t nDescriptorStatus[127];
volatile uint32_t nTotalDescriptorStatus;
DescInfo sDescriptor[127];
}DescChainInfo;
typedef struct __HugepageInfo
{
void* pHugepages;
uint32_t nHugePage;
uint32_t nSegment;
uint32_t nHugePagePerSegment;
uint64_t nHugePageSize;
}HugepageInfo;
typedef struct __HugepageTbl
{
void *pPageVirtAddr;
uint64_t nPagePhyAddr;
uint8_t nIsAllocated:1;
HugepageInfo info;
}HugepageTblStruct;
typedef struct __DmaDescDataInfo
{
uint64_t nPhysicalAddr;
void * nVirtAddr;
void * pBarVirtAddr;
uint32_t dataLen;
}DescDataInfo;
typedef struct __DataHeadStruct
{
unsigned int pktType :8;
unsigned int rsv0 :8;
unsigned int chkCode :16;
unsigned int pktLen :21;
unsigned int rsv1:11;
unsigned int rsv2;
unsigned int rsv3;
unsigned int rsv4;
unsigned int rsv5;
unsigned int rsv6;
unsigned int rsv7;
}DataHeadInfo;
*/
typedef struct __MemorySegment
{
void *pSegment;
uint64_t nPhysicalAddr;
uint32_t nSize;
uint8_t nReferences;
}MemorySegmentStruct;
typedef union
{
uint32_t nAll;
struct
{
uint32_t nSlotIdx : 5;
uint32_t nSubFrameIdx : 6;
uint32_t nFrameIdx : 10;
uint32_t nSymbolIdx : 4;
uint32_t nReservd : 7;
} bit;
}TimeStempIndUnion;
#endif // __FF_DEMO_DEFINE__
#!/bin/bash
echo "Insmod NR_Drv"
NR_DRV=./
lsmod | grep nr_drv >& /dev/null
if [ $? -eq 0 ]; then
rmmod nr_drv
rm -rf /dev/nr_cdev0
rm -rf /dev/nr_cdev1
rm -rf /dev/nr_sys
fi
insmod ${NR_DRV}/nr_drv.ko
mknod /dev/nr_sys c 200 0
mknod /dev/nr_cdev0 c 201 0
mknod /dev/nr_cdev1 c 202 0
mkdir -p /tmp/saveData/en
mkdir -p /tmp/saveData/de
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include <hugetlbfs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include "logger_wrapper.h"
#include "ff_define.h"
#include "mem.h"
#include "dataFile.h"
#include "fec_c_if.h"
int32_t zlogMask=0xF00000; //driver log all open
char FecDeDataFileName[]="decode_data_0.bin";
char FecEnDataFileName[]="encode_data_0.bin";
char saveDataFileName[]="save_data.bin";
//
//
//
//
////////////////////////////////////////////////////////
void dm_time_rec_add(struct timespec *t)
{
clock_gettime(CLOCK_MONOTONIC, t);
}
uint64_t dm_time_rec_diff(struct timespec* now, struct timespec* old) {
uint64_t diff_time = 0;
diff_time = MILLION * (now->tv_sec - old->tv_sec) + (now->tv_nsec - old->tv_nsec) / THOUSAND;
return diff_time;
}
volatile TimeStempIndUnion gTxTimeIndex;
volatile uint64_t *pTxTimeIndex = NULL;
volatile int32_t newSlotIdx,oldSlotIdx;
volatile uint32_t tti_loop_count=0;
volatile uint64_t loopCountEn=0,loopCountDe=0;
volatile uint64_t DeAllTime=0, EnAllTime=0;
volatile uint64_t DeAllLen=0, EnAllLen=0;
int32_t lstSlotIdx =0;
#define DE_RESULT_DATA_MAX 0x100000
#define EN_RESULT_DATA_MAX 0x10000
unsigned char DeDataResult[DE_RESULT_DATA_MAX];
unsigned char EnDataResult[EN_RESULT_DATA_MAX];
char DeResultFileName[]="decode_00.bin";
char EnResultFileName[]="encode_00.bin";
//
//
//
//
////////////////////////////////////////////////////////
int main(int argc,char *argv[])
{
int32_t retVal,i;
uint64_t DmaBaseVirAddr,DmaBasePhyAddr, TtiPhyAddr;
uint8_t *pTtiVirAddr;
MemorySegmentStruct *pFecSegentInfo;
HugepageTblStruct *pFecHugepageTbl;
DescriptorAddrRingStruct DescRingAddr={0};
uint64_t time_dis = 0;
uint32_t fpgaData1,fpgaData2;
DescDataInfo EnDataTx, EnDataRx;
DescDataInfo DeDataTx, DeDataRx;
DataHeadInfo *pDataHeadInfo;
struct timespec deRxEndNew;
struct timespec deRxEndOld;
struct timespec deTxEndNew;
struct timespec deTxEndOld;
struct timespec enRxEndNew;
struct timespec enRxEndOld;
struct timespec enTxEndNew;
struct timespec enTxEndOld;
struct timespec deTxStartRec;
struct timespec deTxStartNew;
struct timespec deRxStartRec;
struct timespec deRxStartNew;
struct timespec enTxStartRec;
struct timespec enTxStartNew;
struct timespec enRxStartRec;
struct timespec enRxStartNew;
volatile uint32_t k;
mm_huge_table_init(&pFecHugepageTbl, SW_FPGA_FH_TOTAL_BUFFER_LEN);
printf( "%s>>>---pFecHugepageTbl->nPagePhyAddr=0x%lx\n",__FUNCTION__,(uint64_t)pFecHugepageTbl->nPagePhyAddr );
mm_segment_init(&pFecSegentInfo, pFecHugepageTbl);
printf("%s>>> pFecSegentInfo->pSegment=0x%lx, pFecSegentInfo->nPhysicalAddr=0x%lx\n", __FUNCTION__, pFecSegentInfo->pSegment, pFecSegentInfo->nPhysicalAddr);
mm_regist_addr_to_ring(&DescRingAddr, pFecSegentInfo);
//log init
GLOBAL_FRLOG_INIT("/tmp/usrp/l1/", "l1", 2, 3);
//
dev2_init_fec();
//
dev2_register_mem_addr(&DescRingAddr);
// malloc memory for rx/tx data
get_data_addr_len(&DescRingAddr, &EnDataTx, &EnDataRx, &DeDataTx, &DeDataRx);
// date init
dm_time_rec_add(&enTxStartNew);
dm_time_rec_add(&enRxStartNew);
dm_time_rec_add(&deTxEndNew);
dm_time_rec_add(&deRxEndNew);
// test data load
getBinDataFromFile((unsigned char *)DeDataTx.nVirtAddr, &DeDataTx.dataLen, FecDeDataFileName);
getBinDataFromFile((unsigned char *)EnDataTx.nVirtAddr, &EnDataTx.dataLen, FecEnDataFileName);
//load_expect_data(DeDataResult,DeResultFileName);
//load_expect_data(EnDataResult,EnResultFileName);
pDataHeadInfo=(DataHeadInfo *)DeDataRx.nVirtAddr;
// main loop !!!
while(1)
{
// Fec Encode Ring
if( fec_en_tx_release() )
{
// release encode data buffer
}
if( fec_en_rx_release() )
{
if( zlogMask & ZLOG_DRIVER_DM_FEC ){
dm_time_rec_add(&enRxEndNew);
time_dis = dm_time_rec_diff(&enRxEndNew, &enTxStartNew);
EnAllTime+=time_dis;
EnAllLen+=EnDataTx.dataLen;
loopCountEn++;
if(loopCountEn>=10000){
EnAllTime/=1000;
zLog(PHY_LOG_INFO,"[FecEnRxRing] data throughput=%dMbps current time=%dus EnDataTx.dataLen=%d ---[DRV_LOG]", 8*EnAllLen/EnAllTime/1024,time_dis,EnDataTx.dataLen);
//zLog(PHY_LOG_INFO,"[FecEnRxRing] EnAllTime=%d EnAllLen=%d ---[DRV_LOG]", EnAllTime, EnAllLen);
loopCountEn=0;
EnAllTime=0;
EnAllLen=0;
}
}
saveBinData((unsigned char *)EnDataRx.nVirtAddr, FEC_ENCODE_DATA);
}
// Fec Decode Ring
if( fec_de_tx_release() )
{
// release decode data buffer
}
if( fec_de_rx_release() )
{
if( zlogMask & ZLOG_DRIVER_DM_FEC ){
dm_time_rec_add(&deRxEndNew);
time_dis = dm_time_rec_diff(&deRxEndNew, &deTxStartNew);
DeAllTime+=time_dis;
DeAllLen+=pDataHeadInfo->pktLen;
loopCountDe++;
if(loopCountDe>=10000){
DeAllTime/=1000;
zLog(PHY_LOG_INFO,"[FecDeRxRing] data throughput=%dMbps ,current time=%dus,pDataHeadInfo->pktLen=%d ---[DRV_LOG]", 8*DeAllLen/DeAllTime/1024, time_dis, pDataHeadInfo->pktLen);
//zLog(PHY_LOG_INFO,"[FecDeRxRing] DeAllTime=%d DeAllLen=%d ----[DRV_LOG]", DeAllTime, DeAllLen);
loopCountDe=0;
DeAllTime=0;
DeAllLen=0;
}
}
//compare_data();
saveBinData((unsigned char *)DeDataRx.nVirtAddr, FEC_DECODE_DATA);
}
//FEC Encode
if( fec_en_tx_require() )
{
if( zlogMask & ZLOG_DRIVER_DM_FEC ){
dm_time_rec_add(&enTxStartNew);
}
dev2_send_en_data(&EnDataTx);
}
if( fec_en_rx_require() )
{
dev2_recv_en_data(&EnDataRx);
}
// FEC Decode
if( fec_de_tx_require() )
{
if( zlogMask & ZLOG_DRIVER_DM_FEC ){
dm_time_rec_add(&deTxStartNew);
}
dev2_send_de_data(&DeDataTx);
}
if( fec_de_rx_require() )
{
dev2_recv_de_data(&DeDataRx);
}
}
return 0;
}
This diff is collapsed.
#ifndef __DEV2_FF_DEMO_MEM__
#define __DEV2_FF_DEMO_MEM__
/*DMA CONTROL REG*/
#define CTRL_MODE_CFG_REG 0
#define STATUS_HADDR_REG 1
#define STATUS_LADDR_REG 2
#define VALID_DES_NUM_REG 3
#define DESC_RING_HADDR_REG 4
#define DESC_RING_LADDR_REG 5
#define BAR_MODE_READ_DESC 0x0 /*2'b00'*/
#define BAR_MODE_READ_MEM 0x2 /*2'b10'*/
#define BAR_MODE_NOTIFY_EACH 0x0 /*2'b00'*/
#define BAR_MODE_NOTIFY_ALL 0x1 /*2'b01'*/
/* hugepage setting */
#define SW_FPGA_TOTAL_BUFFER_LEN 4LL*1024*1024*1024
#define SW_FPGA_SEGMENT_BUFFER_LEN 1LL*1024*1024*1024
#define SW_FPGA_FH_TOTAL_BUFFER_LEN 1LL*1024*1024*1024
#define DIV_ROUND_OFF(X,Y) ( X/Y + ((X%Y)?1:0) )
#define DEVICE_NAME "/dev/nr_cdev"
#define FTH_MEM_SIZE (0x100000)
#define FEC_MEM_SIZE (0x100000)
#define RING_MEM_SIZE (0x10000)
#define SHIFTBITS_32 (32)
#define IS_DESC_DONE(desc) (0xFF&desc)
//
int mm_huge_table_init(HugepageTblStruct **pHugepageTbl, uint64_t memSize);
//
int mm_segment_init(MemorySegmentStruct **pFecSegInfo, HugepageTblStruct *pHugepageTbl);
//
void mm_regist_addr_to_ring(DescriptorAddrRingStruct *pDescRing, MemorySegmentStruct *pFecSegInfo);
//
//
void get_data_addr_len(DescriptorAddrRingStruct *pDescRingAddr, DescDataInfo *pEnDataTx, DescDataInfo *pEnDataRx, DescDataInfo *pDeDataTx, DescDataInfo *pDeDataRx);
#endif //__DEV2_FF_DEMO_MEM__
PREGCC=
TARGET=FFTest
GCC=$(PREGCC)gcc
SYS_INC=/usr/local/include/dev2.0
INCLUDE_DIR := -I$(SYS_INC)
INCLUDE_DIR += -I$(SYS_INC)/9371base
INCLUDE_DIR += -I$(SYS_INC)/ecpriBase
INCLUDE_DIR += -I$(SYS_INC)/fr9371
INCLUDE_DIR += -I$(SYS_INC)/frecpri
INCLUDE_DIR += -I$(SYS_INC)/wi9371
INCLUDE_DIR += -I$(SYS_INC)/wiecpri
LIB_DIR = -lpthread -lhugetlbfs
LIB_DIR1 = -lhugetlbfs
LIB_DIR2 = -ldev2.0
CURDIR:=$(shell pwd)
SRCDIR2 := $(CURDIR)
SRCS := $(wildcard *.c)
OBJS = $(SRCS:%.c=%.o)
CCFLAGS := -g -O2 $(INCLUDE_DIR)
$(TARGET):$(OBJS)
$(GCC) $(CCFLAGS) $(OBJS) -o $@ $(LIB_DIR) $(LIB_DIR2)
%.o: %.c
$(GCC) $(INCLUDE_DIR) $(CCFLAGS) -c $< -o $@
clean:
rm -rf $(OBJS) $(TARGET)
gcc main.c dataFile.c mem.c -fPIC -lpthread -shared -lhugetlbfs -ldev2.0 -o ldpc_fpga_encode.so
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#if 1
#include <dev2.0/logger_wrapper.h>
#include "ff_define.h"
int getBinDataFromFile(unsigned char *pData, int *len,char *fname)
{
int fileSize,ret;
FILE *fp;
int i,j,count;
int tempData;
fp=fopen(fname,"rb");
if(fp==NULL){
printf("This %s file is open failed.\n",fname);
}
fseek(fp,0,SEEK_END);
fileSize=ftell(fp);
rewind(fp);
printf("fileSize=0x%x\n",fileSize);
ret=fread(pData,1,fileSize,fp);
*len=fileSize;
//printf("ret=0x%x\n",ret);
fclose(fp);
return 1;
}
//
//
//
////////////////////////////////
void saveBinDataTofile(unsigned char *pData,int len,char * fname)
{
int i,fileSize,ret;
FILE *fp;
fp=fopen(fname,"wb+");
if(fp==NULL){
printf("This %s file is open failed.\n",fname);
}
ret=fwrite(pData,1,len,fp);
//printf("ret=0x%x\n",ret);
fclose(fp);
}
char tempData[512];
char saveDataDirDe[]="/tmp/saveData/de";
char saveDataDirEn[]="/tmp/saveData/en";
static int count1=0,count2=0,loop_count_de=0,loop_count_en=0;
void saveBinData(unsigned char *pData, int type)
{
int i;
DataHeadInfo *pDataHeadInfo;
DataHeadInfo TempDataHead;
unsigned char *pDataHead;
char fname[64];
pDataHeadInfo=(DataHeadInfo *)pData;
if(type==FEC_DECODE_DATA){
loop_count_de++;
if(loop_count_de>=10000){
sprintf(fname,"%s/decode_%08d.bin",saveDataDirDe,count2++);
saveBinDataTofile(pData, pDataHeadInfo->pktLen+16, fname);
loop_count_de=0;
}
}else if(type==FEC_ENCODE_DATA){
loop_count_en++;
if(loop_count_en>=100000){
sprintf(fname,"%s/encode_%08d.bin",saveDataDirEn,count1++);
saveBinDataTofile(pData, pDataHeadInfo->pktLen+16, fname);
loop_count_en=0;
}
}
//zLog(PHY_LOG_INFO,"rec header: len=%x---[DRV_LOG]",pDataHeadInfo->pktLen);
}
//
//
//
//
////////////////////////////////////////////
void load_expect_data(unsigned char *pData, char *fname)
{
int len;
getBinDataFromFile(pData, &len, fname);
}
//
//
//
//
////////////////////////////////////////////
int compare_data(unsigned char *pDst1, unsigned char *pDst2, int len)
{
int ret=0;
//ret=memcmp(pDst1,pDst2,len);
return ret;
}
#endif
#include "dataFile.h"
int add(int x, int y)
{
printf("dataFile x+y = %d\n", x+y);
return(x+y);
}
#ifndef __DEV2_DATA_FILE__
#define __DEV2_DATA_FILE__
#if 1
//
int getBinDataFromFile(unsigned char *pData,int *len, char * fname);
//
void saveBinDataTofile(unsigned char *pData,int len, char *fname);
//
void saveBinData(unsigned char *pData, int type);
//
int compare_data(unsigned char *pDst1, unsigned char *pDst2, int len);
//
void load_expect_data(unsigned char *pData, char *fname);
#endif
int add(int x, int y);
#endif //__DEV2_DATA_FILE__
#ifndef __FF_DEMO_DEFINE__
#define __FF_DEMO_DEFINE__
#define FPGA_FRONTHAUL 0
#define FPGA_FEC 1
#define FPGA_NUM 2
#define IS_FREE 0
#define IS_BUSY 1
#define IS_FULL 2
#define IS_INVAL 3
#define MILLION 1000000
#define THOUSAND 1000
#define FEC_DECODE_DATA 0x01
#define FEC_ENCODE_DATA 0x02
// log mask
#define ZLOG_DRIVER_DM_TX (1<<20)
#define ZLOG_DRIVER_DM_RX (1<<21)
#define ZLOG_DRIVER_DM_FEC (1<<22)
#define ZLOG_DRIVER_DM_STATUS (1<<23)
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;
typedef int int32_t;
typedef long int int64_t;
typedef short int int16_t;
#include <dev2.0/fec_c_if.h>
typedef struct
{
/*Word 0*/
uint32_t pktType :8;
uint32_t rsv0 :8;
uint32_t chkCode :16;
/*Word 1*/
uint32_t pktLen :21; /*按照byte计算,header+tbsize 按照byte对齐后的长度*/
uint32_t rsv1 :11;
/*Word 2*/
uint32_t rsv2 :28;
uint32_t sectorId :2;
uint32_t rsv3 :2;
/*Word 3*/
uint32_t sfn :10;
uint32_t rsv4 :2;
uint32_t subfn :4;
uint32_t slotNum :5;
uint32_t pduIdx :9;
uint32_t rev5 :2;
/*Word 4*/
uint32_t tbSizeB :18;
uint32_t rev6 :2;
uint32_t lastTb :1;
uint32_t firstTb :1;
uint32_t rev7 :2;
uint32_t cbNum :8;
/*Word 5*/
uint32_t qm :3;
uint32_t rev8 :1;
uint32_t fillbit :14;
uint32_t rev9 :2;
uint32_t kpInByte :11;
uint32_t rev10 :1;
/*Word 6*/
uint32_t gamma :8;
uint32_t codeRate :6;
uint32_t rev11 :2;
uint32_t rvIdx :2;
uint32_t rev12 :6;
uint32_t lfSizeIx :3;
uint32_t rev13 :1;
uint32_t iLs :3;
uint32_t bg :1;
/*Word 7*/
uint32_t e1 :16;
uint32_t e0 :16;
}EncodeInHeaderStruct;
typedef struct
{
uint32_t pktType :8;
uint32_t rsv0 :8;
uint32_t chkCode :16;
uint32_t pduSize :21;
uint32_t rsv1 :11;
uint32_t rsv2 :28;
uint32_t sectorId :2;
uint32_t rsv3 :2;
uint32_t sfn :10;
uint32_t rsv4 :2;
uint32_t subfn :4;
uint32_t slotNum :5;
uint32_t pduIdx :9;
uint32_t rev5 :2;
uint32_t tbSizeB :18;
uint32_t rev6 :2;
uint32_t lastTb :1;
uint32_t firstTb :1;
uint32_t rev7 :2;
uint32_t cbNum :8;
uint32_t qm :3;
uint32_t rev8 :1;
uint32_t fillbit :14;
uint32_t rev9 :2;
uint32_t kpInByte :11;
uint32_t rev10 :1;
uint32_t gamma :8;
uint32_t codeRate :6;
uint32_t rev11 :2;
uint32_t rvIdx :2;
uint32_t rev12 :6;
uint32_t lfSizeIx :3;
uint32_t rev13 :1;
uint32_t iLs :3;
uint32_t bg :1;
uint32_t e1 :16;
uint32_t e0 :16;
}EncodeOutHeaderStruct;
typedef struct
{
/*Word 0*/
uint32_t pktType :8;
uint32_t rsv0 :8;
uint32_t chkCode :16;
/*Word 1*/
uint32_t pktLen :21; /*包含header + DDRheader + CB DATA的长度,单位是byte*/
uint32_t rsv1 :11;
/*Word 2*/
uint32_t pktTpTmp :4;
uint32_t pduSize :24; /*包含header + DDRheader + CB DATA的长度,单位是Word*/
uint32_t sectorId :2;
uint32_t rsv2 :2;
/*Word 3*/
uint32_t sfn :10;
uint32_t rsv3 :2;
uint32_t subfn :4;
uint32_t slotNum :5;
uint32_t pduIdx :9;
uint32_t rev4 :2;
/*Word 4*/
uint32_t tbSizeB :18; /*tbsize的大小,单位byte*/
uint32_t rev5 :2;
uint32_t lastTb :1;
uint32_t firstTb :1;
uint32_t rev6 :2;
uint32_t cbNum :8; /*码块数*/
/*Word 5*/
uint32_t qm :3;
uint32_t rev7 :1;
uint32_t fillbit :14;
uint32_t kpInByte :14; /* 被均分后每个cb块的长度,单位bit */
/*Word 6*/
uint32_t gamma :8;
uint32_t maxRowNm :6; //填成46
uint32_t maxRvIdx :2;
uint32_t rvIdx :2;
uint32_t ndi :1;
uint32_t flush :1;
uint32_t maxIter :4;
uint32_t lfSizeIx :3;
uint32_t rev10 :1;
uint32_t iLs :3;
uint32_t bg :1;
/*Word 7*/
uint32_t e1 :16;
uint32_t e0 :16;
}DecodeInHeaderStruct;
typedef struct
{
/*word 0*/
uint32_t pktType :8; /* FEC RX 类型: 0x11*/
uint32_t rsv0 :8;
uint32_t chkCode :16; /* 数据校验 :0xFAFA*/
/*word 1*/
uint32_t pktLen :21; /* 包括 FPGA_ALIGN(header+ FPGA_ALIGN4B(tbsizeB)+4byte) */
uint32_t rsv1 :11;
/*word 2*/
uint32_t pktTpTmp :4;
uint32_t pduSize :20; /* pktLen长度除以4 单位 word*/
uint32_t rsv2 :4;
uint32_t sectorId :2;
uint32_t rsv3 :2;
/*word 3*/
uint32_t sfn :10; /* 帧号 */
uint32_t rsv4 :2;
uint32_t subfn :4; /* 子帧号 */
uint32_t slotNum :5; /* 时隙号 */
uint32_t pduIdx :9;
uint32_t rsv5 :2;
/*Word 4*/
uint32_t tbSizeB :18; /* tbsize 的大小,单位byte*/
uint32_t rsv6 :2;
uint32_t lastTb :1;
uint32_t firstTb :1;
uint32_t rsv7 :2;
uint32_t cbNum :8;
/*Word 5*/
uint32_t rsv8 :32;
/*Word 6*/
uint32_t rsv9 :32;
/*Word 7*/
uint32_t rsv10 :32;
}DecodeOutHeaderStruct;
typedef struct __MemorySegment
{
void *pSegment;
uint64_t nPhysicalAddr;
uint32_t nSize;
uint8_t nReferences;
}MemorySegmentStruct;
typedef union
{
uint32_t nAll;
struct
{
uint32_t nSlotIdx : 5;
uint32_t nSubFrameIdx : 6;
uint32_t nFrameIdx : 10;
uint32_t nSymbolIdx : 4;
uint32_t nReservd : 7;
} bit;
}TimeStempIndUnion;
#endif // __FF_DEMO_DEFINE__
#!/bin/bash
echo "Insmod NR_Drv"
NR_DRV=./
lsmod | grep nr_drv >& /dev/null
if [ $? -eq 0 ]; then
rmmod nr_drv
rm -rf /dev/nr_cdev0
rm -rf /dev/nr_cdev1
rm -rf /dev/nr_sys
fi
insmod ${NR_DRV}/nr_drv.ko
mknod /dev/nr_sys c 200 0
mknod /dev/nr_cdev0 c 201 0
mknod /dev/nr_cdev1 c 202 0
mkdir -p /tmp/saveData/en
mkdir -p /tmp/saveData/de
This diff is collapsed.
This diff is collapsed.
#ifndef __DEV2_FF_DEMO_MEM__
#define __DEV2_FF_DEMO_MEM__
/*DMA CONTROL REG*/
#define CTRL_MODE_CFG_REG 0
#define STATUS_HADDR_REG 1
#define STATUS_LADDR_REG 2
#define VALID_DES_NUM_REG 3
#define DESC_RING_HADDR_REG 4
#define DESC_RING_LADDR_REG 5
#define BAR_MODE_READ_DESC 0x0 /*2'b00'*/
#define BAR_MODE_READ_MEM 0x2 /*2'b10'*/
#define BAR_MODE_NOTIFY_EACH 0x0 /*2'b00'*/
#define BAR_MODE_NOTIFY_ALL 0x1 /*2'b01'*/
/* hugepage setting */
#define SW_FPGA_TOTAL_BUFFER_LEN 4LL*1024*1024*1024
#define SW_FPGA_SEGMENT_BUFFER_LEN 1LL*1024*1024*1024
#define SW_FPGA_FH_TOTAL_BUFFER_LEN 1LL*1024*1024*1024
#define DIV_ROUND_OFF(X,Y) ( X/Y + ((X%Y)?1:0) )
#define DEVICE_NAME "/dev/nr_cdev"
#define FTH_MEM_SIZE (0x100000)
#define FEC_MEM_SIZE (0x100000)
#define RING_MEM_SIZE (0x10000)
#define SHIFTBITS_32 (32)
#define IS_DESC_DONE(desc) (0xFF&desc)
//
int mm_huge_table_init(HugepageTblStruct **pHugepageTbl, uint64_t memSize);
//
int mm_segment_init(MemorySegmentStruct **pFecSegInfo, HugepageTblStruct *pHugepageTbl);
//
void mm_regist_addr_to_ring(DescriptorAddrRingStruct *pDescRing, MemorySegmentStruct *pFecSegInfo);
//
//
void get_data_addr_len(DescriptorAddrRingStruct *pDescRingAddr, DescDataInfo *pEnDataTx, DescDataInfo *pEnDataRx, DescDataInfo *pDeDataTx, DescDataInfo *pDeDataRx);
#endif //__DEV2_FF_DEMO_MEM__
PREGCC=
TARGET=FFTest
GCC=$(PREGCC)g++
SYS_INC=/usr/local/include/dev2.0
INCLUDE_DIR := -I$(SYS_INC)
INCLUDE_DIR += -I$(SYS_INC)/9371base
INCLUDE_DIR += -I$(SYS_INC)/ecpriBase
INCLUDE_DIR += -I$(SYS_INC)/fr9371
INCLUDE_DIR += -I$(SYS_INC)/frecpri
INCLUDE_DIR += -I$(SYS_INC)/wi9371
INCLUDE_DIR += -I$(SYS_INC)/wiecpri
LIB_DIR = -lpthread -lhugetlbfs
LIB_DIR1 = -lhugetlbfs
LIB_DIR2 = -ldev2.0
CURDIR:=$(shell pwd)
SRCDIR2 := $(CURDIR)
SRCS := $(wildcard *.cpp)
OBJS = $(SRCS:%.cpp=%.o)
CCFLAGS := -std=c++11 -g -O2 $(INCLUDE_DIR)
$(TARGET):$(OBJS)
$(GCC) $(CCFLAGS) $(OBJS) -o $@ $(LIB_DIR) $(LIB_DIR2)
%.o: %.cpp
$(GCC) $(INCLUDE_DIR) $(CCFLAGS) -c $< -o $@
clean:
rm -rf $(OBJS) $(TARGET)
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <iostream>
#include <string>
#include <sstream>
#include <cstdint>
#include "logger_wrapper.h"
#include "ff_define.h"
//using namespace std;
int getBinDataFromFile(unsigned char *pData, int *len,char *fname)
{
int fileSize,ret;
FILE *fp;
int i,j,count;
int tempData;
fp=fopen(fname,"rb");
if(fp==NULL){
printf("This %s file is open failed.\n",fname);
}
fseek(fp,0,SEEK_END);
fileSize=ftell(fp);
rewind(fp);
printf("fileSize=0x%x\n",fileSize);
ret=fread(pData,1,fileSize,fp);
*len=fileSize;
//printf("ret=0x%x\n",ret);
fclose(fp);
/*
count=ret/32;
for(j=0;j<count;j++){
for(i=0;i<16;i++){
tempData=pData[i+j*32];
pData[i+j*32]=pData[j*32+31-i];
pData[j*32+31-i]=tempData;
}
}
*/
return 1;
}
//
//
//
////////////////////////////////
void saveBinDataTofile(unsigned char *pData,int len,char * fname)
{
int i,fileSize,ret;
FILE *fp;
fp=fopen(fname,"wb+");
if(fp==NULL){
printf("This %s file is open failed.\n",fname);
}
ret=fwrite(pData,1,len,fp);
//printf("ret=0x%x\n",ret);
fclose(fp);
}
char tempData[512];
char saveDataDirDe[]="./saveData/de";
char saveDataDirEn[]="./saveData/en";
static int count1=0,count2=0;
void saveBinData(unsigned char *pData, int type)
{
int i;
DataHeadInfo *pDataHeadInfo;
DataHeadInfo TempDataHead;
unsigned char *pDataHead;
char fname[64];
/*
for(i=0;i<32;i++){
//printf("%02x_",*(pData+i));
sprintf(tempData+(i*3),"%02x_",*(pData+i));
}
*(tempData+32*3)='\0';
//sprintf(tempData+(6*3),"%02x_", 0x17);
zLog(PHY_LOG_INFO,"rec header:=%s---[DRV_LOG]",tempData);
*/
pDataHeadInfo=(DataHeadInfo *)pData;
//zLog(PHY_LOG_INFO,"rec header: len=%x---[DRV_LOG]",pDataHeadInfo->pktLen);
if(type==FEC_DECODE_DATA){
sprintf(fname,"%s/decode_%08d.bin",saveDataDirDe,count2++);
}else if(type==FEC_ENCODE_DATA){
sprintf(fname,"%s/encode_%08d.bin",saveDataDirEn,count1++);
}
saveBinDataTofile(pData, pDataHeadInfo->pktLen+32, fname);
}
//
//
//
//
////////////////////////////////////////////
void load_expect_data(unsigned char *pData, char *fname)
{
int len;
getBinDataFromFile(pData, &len, fname);
}
//
//
//
//
////////////////////////////////////////////
int compare_data(unsigned char *pDst1, unsigned char *pDst2, int len)
{
int ret=0;
//ret=memcmp(pDst1,pDst2,len);
return ret;
}
#ifndef __DEV2_DATA_FILE__
#define __DEV2_DATA_FILE__
//
int getBinDataFromFile(unsigned char *pData,int *len, char * fname);
//
void saveBinDataTofile(unsigned char *pData,int len, char *fname);
//
void saveBinData(unsigned char *pData, int type);
//
int compare_data(unsigned char *pDst1, unsigned char *pDst2, int len);
//
void load_expect_data(unsigned char *pData, char *fname);
#endif //__DEV2_DATA_FILE__
#ifndef __FF_DEMO_DEFINE__
#define __FF_DEMO_DEFINE__
#include "fec_c_if.h"
#define FPGA_FRONTHAUL 0
#define FPGA_FEC 1
#define FPGA_NUM 2
#define IS_FREE 0
#define IS_BUSY 1
#define IS_FULL 2
#define IS_INVAL 3
#define MILLION 1000000
#define THOUSAND 1000
#define FEC_DECODE_DATA 0x01
#define FEC_ENCODE_DATA 0x02
// log mask
#define ZLOG_DRIVER_DM_TX (1<<20)
#define ZLOG_DRIVER_DM_RX (1<<21)
#define ZLOG_DRIVER_DM_FEC (1<<22)
#define ZLOG_DRIVER_DM_STATUS (1<<23)
/*
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;
typedef int int32_t;
typedef long int int64_t;
typedef short int int16_t;
*/
/*
typedef struct __DescriptorAddrRingStruct
{
uint32_t nRingBufferPoolIndex;
HugepageTblStruct RxFhRingBuffer;
HugepageTblStruct RxEnCodeRingBuffer;
HugepageTblStruct RxDeCodeRingBuffer;
HugepageTblStruct SyncFhRingBuffer;
HugepageTblStruct TxFhRingBuffer;
HugepageTblStruct TxEnCodeRingBuffer;
HugepageTblStruct TxDeCodeRingBuffer;
uint64_t BaseAddress;
}DescriptorAddrRingStruct;
typedef struct __DmaDescInfo
{
uint32_t nAddressHigh;
uint32_t nAddressLow;
uint32_t nAddressLen;
uint32_t rsvrd;
}DescInfo;
typedef struct __DmaDescChainInfo
{
volatile uint32_t nDescriptorStatus[127];
volatile uint32_t nTotalDescriptorStatus;
DescInfo sDescriptor[127];
}DescChainInfo;
typedef struct __HugepageInfo
{
void* pHugepages;
uint32_t nHugePage;
uint32_t nSegment;
uint32_t nHugePagePerSegment;
uint64_t nHugePageSize;
}HugepageInfo;
typedef struct __HugepageTbl
{
void *pPageVirtAddr;
uint64_t nPagePhyAddr;
uint8_t nIsAllocated:1;
HugepageInfo info;
}HugepageTblStruct;
typedef struct __DmaDescDataInfo
{
uint64_t nPhysicalAddr;
void * nVirtAddr;
void * pBarVirtAddr;
uint32_t dataLen;
}DescDataInfo;
typedef struct __DataHeadStruct
{
unsigned int pktType :8;
unsigned int rsv0 :8;
unsigned int chkCode :16;
unsigned int pktLen :21;
unsigned int rsv1:11;
unsigned int rsv2;
unsigned int rsv3;
unsigned int rsv4;
unsigned int rsv5;
unsigned int rsv6;
unsigned int rsv7;
}DataHeadInfo;
*/
typedef struct __MemorySegment
{
void *pSegment;
uint64_t nPhysicalAddr;
uint32_t nSize;
uint8_t nReferences;
}MemorySegmentStruct;
typedef union
{
uint32_t nAll;
struct
{
uint32_t nSlotIdx : 5;
uint32_t nSubFrameIdx : 6;
uint32_t nFrameIdx : 10;
uint32_t nSymbolIdx : 4;
uint32_t nReservd : 7;
} bit;
}TimeStempIndUnion;
#endif // __FF_DEMO_DEFINE__
#!/bin/bash
echo "Insmod NR_Drv"
NR_DRV=./
lsmod | grep nr_drv >& /dev/null
if [ $? -eq 0 ]; then
rmmod nr_drv
rm -rf /dev/nr_cdev0
rm -rf /dev/nr_cdev1
rm -rf /dev/nr_sys
fi
insmod ${NR_DRV}/nr_drv.ko
mknod /dev/nr_sys c 200 0
mknod /dev/nr_cdev0 c 201 0
mknod /dev/nr_cdev1 c 202 0
This diff is collapsed.
This diff is collapsed.
#ifndef __DEV2_FF_DEMO_MEM__
#define __DEV2_FF_DEMO_MEM__
/*DMA CONTROL REG*/
#define CTRL_MODE_CFG_REG 0
#define STATUS_HADDR_REG 1
#define STATUS_LADDR_REG 2
#define VALID_DES_NUM_REG 3
#define DESC_RING_HADDR_REG 4
#define DESC_RING_LADDR_REG 5
#define BAR_MODE_READ_DESC 0x0 /*2'b00'*/
#define BAR_MODE_READ_MEM 0x2 /*2'b10'*/
#define BAR_MODE_NOTIFY_EACH 0x0 /*2'b00'*/
#define BAR_MODE_NOTIFY_ALL 0x1 /*2'b01'*/
/* hugepage setting */
#define SW_FPGA_TOTAL_BUFFER_LEN 4LL*1024*1024*1024
#define SW_FPGA_SEGMENT_BUFFER_LEN 1LL*1024*1024*1024
#define SW_FPGA_FH_TOTAL_BUFFER_LEN 1LL*1024*1024*1024
#define DIV_ROUND_OFF(X,Y) ( X/Y + ((X%Y)?1:0) )
#define DEVICE_NAME "/dev/nr_cdev"
#define FTH_MEM_SIZE (0x100000)
#define FEC_MEM_SIZE (0x100000)
#define RING_MEM_SIZE (0x10000)
#define SHIFTBITS_32 (32)
#define IS_DESC_DONE(desc) (0xFF&desc)
//
int mm_huge_table_init(HugepageTblStruct **pHugepageTbl, uint64_t memSize);
//
int mm_segment_init(MemorySegmentStruct **pFecSegInfo, HugepageTblStruct *pHugepageTbl);
//
void mm_regist_addr_to_ring(DescriptorAddrRingStruct *pDescRing, MemorySegmentStruct *pFthSegInfo, MemorySegmentStruct *pFecSegInfo);
//
void mm_get_tti_phy_addr(MemorySegmentStruct *pFthSegInfo, uint8_t **pDmaBaseVirAddr,uint64_t *pDmaBasePhyAddr);
//
void mm_register_ring_addr_to_bar ( DescriptorAddrRingStruct * pDring, uint64_t nFuncBaseAddr);
//
void de_tx_update_data_addr_len(DescChainInfo *pRingInfo,DescDataInfo *pData);
//
void de_rx_update_data_addr_len(DescChainInfo *pRingInfo,DescDataInfo *pData);
//
void get_data_addr_len(DescriptorAddrRingStruct *pDescRingAddr, DescDataInfo *pEnDataTx, DescDataInfo *pEnDataRx, DescDataInfo *pDeDataTx, DescDataInfo *pDeDataRx);
#endif //__DEV2_FF_DEMO_MEM__
18.04 vm.nr_hugepages=4096
\ No newline at end of file
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