BOOL TEST_DMA_MEMORY(PCIE_HANDLE hPCIe){ BOOL bPass; int i; const int nTestSize = MEM_SIZE; const PCIE_LOCAL_ADDRESS LocalAddr = DEMO_PCIE_MEM_ADDR; char *pWrite; char *pRead; char szError[256]; pWrite = (char *)malloc(nTestSize); pRead = (char *)malloc(nTestSize); if (!pWrite || !pRead){ bPass = FALSE; sprintf(szError, "DMA Memory:malloc failed\r\n"); } // init test pattern for(i=0;i<nTestSize && bPass;i++) *(pWrite+i) = PAT_GEN(i); // write test pattern if (bPass){ bPass = PCIE_DmaWrite(hPCIe, LocalAddr, pWrite, nTestSize); if (!bPass) sprintf(szError, "DMA Memory:PCIE_DmaWrite failed\r\n"); } // read back test pattern and verify if (bPass){ bPass = PCIE_DmaRead(hPCIe, LocalAddr, pRead, nTestSize); if (!bPass){ sprintf(szError, "DMA Memory:PCIE_DmaRead failed\r\n"); }else{ for(i=0;i<nTestSize && bPass;i++){ if (*(pRead+i) != PAT_GEN(i)){ bPass = FALSE; sprintf(szError, "DMA Memory:Read-back verify unmatch, index = %d, read=%xh, expected=%xh\r\n", i, *(pRead+i), PAT_GEN(i)); } } } } // free resource if (pWrite) free(pWrite); if (pRead) free(pRead); if (!bPass) printf("%s", szError); else printf("DMA-Memory (Size = %d byes) pass\r\n", nTestSize); return bPass; }
// Clean all the memories used in the demo BOOL clearMem(PCIE_HANDLE hPCIe, BITMAPINFOHEADER *info) { DWORD addr = 0x00; //BYTE start = 0x04; PCIE_Write8( hPCIe, pcie_bars[0], addr, 0x00); addr = addr+4; PCIE_Write8( hPCIe, pcie_bars[0], addr, 0x00); addr = addr+4; PCIE_Write8( hPCIe, pcie_bars[0], addr, 0x00);//r_addr addr = addr+4; PCIE_Write8( hPCIe, pcie_bars[0], addr, 0x00); addr = addr+4; PCIE_Write8( hPCIe, pcie_bars[0], addr, 0x00); unsigned char *testImage;//test image buffer testImage = (unsigned char*)malloc(info->width*info->height*4*sizeof(unsigned char)); addr = 0x08000000; BOOL bPass = PCIE_DmaWrite(hPCIe, addr, testImage, info->width*info->height*4); if (!bPass) { printf("ERROR: unsuccessful memory clearing 1.\n"); return FALSE; } addr = 0x08500000; int i; for ( i = 0; i < info->width*info->height*4; ++i) { testImage[i] = 0; } bPass = PCIE_DmaWrite(hPCIe, addr, testImage, info->width*info->height*4); if (!bPass) { printf("ERROR: unsuccessful memory clearing 2.\n"); return FALSE; } // printf("All memory cleared.\n"); return TRUE; }
// Write the image field to SDRAM BOOL WriteImage(PCIE_HANDLE hPCIe, char *filename, BITMAPINFOHEADER *info) { FILE * pFile; pFile = fopen(filename,"rb"); BITMAPFILEHEADER bitmapFileHeader; fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER),1,pFile); //read the info header fread(info, sizeof(BITMAPINFOHEADER),1,pFile); unsigned char *bitmapImage;//image buffer bitmapImage = (unsigned char*)malloc(info->width*info->height*sizeof(unsigned char)); if (!bitmapImage) { free(bitmapImage); fclose(pFile); printf("Image loading failed.\n"); return FALSE; } //read in the bitmap image data fread(bitmapImage,info->width*info->height*sizeof(unsigned char),1,pFile); //BYTE tempRGB; DWORD addr = 0x08000000; //original image written starting from 0x08000000 // Write only one pixel to the LSByte and zero pad the rest 24 bits unsigned char *imageDataBuffer; imageDataBuffer = (unsigned char*)malloc(info->width*info->height*4*sizeof(unsigned char)); int index = 0; int i; for (i = 0; i <info->width*info->height; ++i) { imageDataBuffer[index++] = bitmapImage[i]; imageDataBuffer[index++] = 0; imageDataBuffer[index++] = 0; imageDataBuffer[index++] = 0; } BOOL bPass = PCIE_DmaWrite(hPCIe, addr, imageDataBuffer, info->width*info->height*4); if(!bPass) { printf("ERROR: unsuccessful image writing.\n"); return FALSE; } else printf("Image written.\n"); free(bitmapImage); free(imageDataBuffer); return TRUE; }
BOOL TEST_DMA_WRITE_DATABASE_MEMORY(PCIE_HANDLE hPCIe , FILE *ptr_file){ BOOL bPass=TRUE; const PCIE_LOCAL_ADDRESS LocalAddr = DEMO_PCIE_MEM_SUBJECT_ADDR; TEST_LOAD_DATABASE(ptr_file); // write test pattern if (bPass){ bPass = PCIE_DmaWrite(hPCIe, LocalAddr, databaseblock, DATABASE_BLOCK_SIZE); if (!bPass) printf("05:DMA Memory:PCIE_DmaWrite failed\r\n"); } return bPass; }
//tests DMA write of buffer to address void testDMA( PCIE_HANDLE hPCIe, DWORD addr) { BOOL bPass; DWORD testArray[MAXDMA]; DWORD readArray[MAXDMA]; WORD i = 0; while ( i < MAXDMA ) { testArray[i] = i + 0xfd; i++; } bPass = PCIE_DmaWrite(hPCIe, addr, testArray, MAXDMA * RWSIZE ); if (!bPass) { printf("test FAILED: write did not return success"); return; } bPass = PCIE_DmaRead(hPCIe, addr, readArray, MAXDMA * RWSIZE ); if (!bPass) { printf("test FAILED: read did not return success"); return; } i = 0; while ( i < MAXDMA ) { if (testArray[i] == readArray[i]) { //printf("Test PASSED: expected %x, received %x\n", testArray[i], readArray[i]); } else { printf("Test FAILED: expected %x, received %x\n", testArray[i], readArray[i]); } i++; } return; }
BOOL TEST_DMA_WRITE_QUERY_MEMORY(PCIE_HANDLE hPCIe){ BOOL bPass=TRUE; const PCIE_LOCAL_ADDRESS LocalAddr = DEMO_PCIE_MEM_QUERY_ADDR; printf("Input your query (maximum %d):", MAX_QUERY_SIZE_CHAR); scanf("%s",inQueryADN); CovertQuery2Bit(inQueryADN, MAX_QUERY_SIZE_CHAR, inQueryByte, MAX_QUERY_SIZE_BYTE); printHexString(inQueryByte); // write test pattern if (bPass){ bPass = PCIE_DmaWrite(hPCIe, LocalAddr, inQueryByte, MAX_QUERY_SIZE_BYTE); if (!bPass) printf("05:DMA Memory:PCIE_DmaWrite failed\r\n"); } // read back test pattern and verify /* if (bPass){ bPass = PCIE_DmaRead(hPCIe, LocalAddr, outQueryByte, MAX_QUERY_SIZE_BYTE); if (!bPass){ printf("06:DMA Memory:PCIE_DmaRead failed\r\n"); }else{ for(i=0; i<MAX_QUERY_SIZE_BYTE && bPass; i++){ if (outQueryByte[i] != inQueryByte[i]){ bPass = FALSE; printf("07:DMA Memory:Read-back verify unmatch, index = %d, read=%xh, expected=%xh\r\n", i,outQueryByte[i], inQueryByte[i]); } } } } */ return bPass; }