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; }
BOOL TEST_DMA_READ_QUERY_MEMORY(PCIE_HANDLE hPCIe){ BOOL bPass=TRUE; //const int nTestSize = MEM_SIZE; const PCIE_LOCAL_ADDRESS LocalAddr = DEMO_PCIE_MEM_QUERY_ADDR; // 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{ printHexString(outQueryByte); } } 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_READ_DATABASE_MEMORY(PCIE_HANDLE hPCIe){ BOOL bPass=TRUE; strcpy(databaseblock,""); const PCIE_LOCAL_ADDRESS LocalAddr = DEMO_PCIE_MEM_SUBJECT_ADDR; // read back test pattern and verify if (bPass){ bPass = PCIE_DmaRead(hPCIe, LocalAddr, databaseblock, DATABASE_BLOCK_SIZE); if (!bPass){ printf("06:DMA Memory:PCIE_DmaRead failed\r\n"); }else{ printHexString(outQueryByte); } } return bPass; }
// Read the processed edge image from SDRAM and write it to a new BMP image named "out.bmp" BOOL NewReadImage(PCIE_HANDLE hPCIe, BITMAPINFOHEADER *info) { //checkImageDone(hPCIe); FILE* fp = fopen("out.bmp", "wb"); static unsigned char //color[1], /* 1 byte = 8 bits */ byte[1]; unsigned short word[1]; /* 2 bytes */ unsigned long dword[1], /* 4 bytes */ bpp=1, /* in bytes */ FileHeaderSize=14, InfoHeaderSize=40, // header_bytes PaletteSize=255*4, // = 8 = number of bytes in palette, 256 colors BytesPerRow, FileSize, OffBits, BytesSize, // bytes in image portion //iByte, // number of byte /* in pixels */ Width= info->width, Height= info->height; /* in ... */ //ix, iy, ix_, //bit=0, /* bit value */ //bitNumber; /* bits are numberd from 0 to 7 */ BytesPerRow=(((Width * bpp)+31)/32)*4; BytesSize=BytesPerRow*Height; FileSize=FileHeaderSize+InfoHeaderSize+PaletteSize+BytesSize; OffBits=FileHeaderSize+InfoHeaderSize+PaletteSize; word[0]=19778; fwrite(word,1,2,fp); /* file Type signature = BM */ dword[0]=FileSize; fwrite(dword,1,4,fp); /* FileSize */ word[0]=0; fwrite(word,1,2,fp); /* reserved1 */ word[0]=0; fwrite(word,1,2,fp); /* reserved2 */ dword[0]=OffBits; fwrite(dword,1,4,fp); /* OffBits */ dword[0]=InfoHeaderSize; fwrite(dword,1,4,fp); dword[0]=Width; fwrite(dword,1,4,fp); dword[0]=Height; fwrite(dword,1,4,fp); word[0]=1; fwrite(word,1,2,fp); /* planes */ word[0]=8; fwrite(word,1,2,fp); /* Bits of color per pixel */ dword[0]=0; fwrite(dword,1,4,fp); /* compression type */ dword[0]=0; fwrite(dword,1,4,fp); /* Image Data Size, set to 0 when no compression */ dword[0]=0; fwrite(dword,1,4,fp); /* */ dword[0]=0; fwrite(dword,1,4,fp); /* */ dword[0]=255; fwrite(dword,1,4,fp); /* number of used coloors*/ dword[0]=0; fwrite(dword,1,4,fp); /* */ int i; for (i = 0; i < 256; i++) { byte[0]=i; fwrite(byte,1,1,fp); /* R */ byte[0]=i; fwrite(byte,1,1,fp); /* R */ byte[0]=i; fwrite(byte,1,1,fp); /* G */ byte[0]=i; fwrite(byte,1,1,fp); /* B */ } DWORD addr = 0x08500000; //new image starts from 0x08500000 unsigned char *testImage;//test image buffer testImage = (unsigned char*)malloc(info->width*info->height*4*sizeof(unsigned char)); BOOL bPass = PCIE_DmaRead(hPCIe, addr, testImage, info->width*info->height*4); if(!bPass) { printf("ERROR: unsuccessful image reading.\n"); return FALSE; } else printf("Image read by the Atom.\n"); unsigned char *bitmapImage;//image buffer bitmapImage = (unsigned char*)malloc(info->width*info->height*sizeof(unsigned char)); int index = 0; int j; // Store only the LSByte of the 32-bit data into the new image file for (j = 0; j < info->width*info->height; ++j) { unsigned char buff; buff = testImage[index++]; bitmapImage[j] = buff; buff = testImage[index++]; buff = testImage[index++]; buff = testImage[index++]; } if(!bitmapImage) { printf("ERROR: new image is empty.\n"); return FALSE; } fwrite(bitmapImage, info->width*info->height*sizeof(unsigned char),1,fp); free(bitmapImage); free(testImage); fclose(fp); printf("New image written to **out.bmp**.\n"); return TRUE; }