// -------------------------------------------------------------------- // Copyright (c) 2008 by Terasic Technologies Inc. // -------------------------------------------------------------------- // // Permission: // // Terasic grants permission to use and modify this code for use // in synthesis for all Terasic Development Boards and Altera Development // Kits made by Terasic. Other use of this code, including the selling // ,duplication, or modification of any portion is strictly prohibited. // // Disclaimer: // // This VHDL/Verilog or C/C++ source code is intended as a design reference // which illustrates how these types of functions can be implemented. // It is the user's responsibility to verify their design for // consistency and functionality through the use of formal // verification methods. Terasic provides no warranty regarding the use // or functionality of this code. // // -------------------------------------------------------------------- // // Terasic Technologies Inc // 356 Fu-Shin E. Rd Sec. 1. JhuBei City, // HsinChu County, Taiwan // 302 // // web: http://www.terasic.com/ // email: support@terasic.com // // -------------------------------------------------------------------- #include "terasic_includes.h" #include "mem_test.h" #define SHOW_PROGRESS bool TMEM_Verify(alt_u32 BaseAddr, alt_u32 ByteLen, alt_u32 InitValue){ bool bPass = TRUE; alt_u32 szData[257]; alt_u32 szRead[257]; int i, nRemainedLen, nAccessLen; alt_u32 *pDes, *pSrc, nItemNum, nPos; #ifdef SHOW_PROGRESS int nProgressIndex=0; alt_u32 szProgress[10]; for(i=0;i<10;i++){ szProgress[i] = ByteLen/10*(i+1); } #endif nItemNum = sizeof(szData)/sizeof(szData[0]); for(i=0;i nRemainedLen) nAccessLen = nRemainedLen; memcpy(pDes, szData, nAccessLen); pDes += nAccessLen/4; nPos += nAccessLen; #ifdef SHOW_PROGRESS if (nProgressIndex <= 9 && nPos >= szProgress[nProgressIndex]){ nProgressIndex++; printf("%02d%% ", nProgressIndex*10); } #endif } alt_dcache_flush_all(); #ifdef SHOW_PROGRESS nProgressIndex = 0; printf("\nread/verify...\n"); #endif // read & verify pSrc = (alt_u32 *)BaseAddr; nAccessLen = sizeof(szRead); nPos = 0; while(bPass && nPos < ByteLen){ nRemainedLen = ByteLen - nPos; if (nAccessLen > nRemainedLen) nAccessLen = nRemainedLen; memset(szRead, 0xAA, nAccessLen); // reset content memcpy(szRead, pSrc, nAccessLen); // verify nItemNum = nAccessLen / 4; for(i=0;i= szProgress[nProgressIndex]){ nProgressIndex++; printf("%02d%% ", nProgressIndex*10); } #endif } #ifdef SHOW_PROGRESS printf("\n"); #endif return bPass; }