📄 sdram_tests.c
字号:
/*! * \file sdram_tests.c * \brief SDRAM Test Routines * * Test the SDRAM interface on Jamaica * * \version $Revision: 1.3 $ * \author Michael Norman */#include "common.h"#include "sdramc.h"#include "sdram_tests.h"#include "memtest.h"/********************************************************************//*! Initialized data for test purposes */int test_data[] = { 0x00112233, 0x44556677, 0x8899AABB, 0xCCDDEEFF, 0x00112233, 0x44556677, 0x8899AABB, 0xCCDDEEFF, 0x00112233, 0x44556677, 0x8899AABB, 0xCCDDEEFF, 0x00112233, 0x44556677, 0x8899AABB, 0xCCDDEEFF, 0x00001111, 0x22223333, 0x44445555, 0x66667777, 0x88889999, 0xAAAABBBB, 0xCCCCDDDD, 0xEEEEFFFF, 0x00000000, 0x11111111, 0x22222222, 0x33333333, 0x44444444, 0x55555555, 0x66666666, 0x77777777, 0x11111111, 0x22222222, 0x44444444, 0x88888888, 0xAAAAAAAA, 0x55555555, 0x99999999, 0x66666666, 0xEEEEEEEE, 0x77777777, 0xFFFFFFFF, 0x00000000, 0x33333333, 0xCCCCCCCC, 0xDEADBEEF, 0xFEEDFACE };/********************************************************************//*! * \brief SDRAM Register Dump * \param none * \return none */voidsdram_register_dump (void){ printf("SDRAM Controller Registers:\n"); printf("SDMR: %08X\n", MCF_SDRAMC_SDMR); printf("SDCR: %08X\n", MCF_SDRAMC_SDCR); printf("SDCFG1: %08X\n", MCF_SDRAMC_SDCFG1); printf("SDCFG2: %08X\n", MCF_SDRAMC_SDCFG2); printf("SDCS0: %08X\n", MCF_SDRAMC_SDCS0); printf("SDCS1: %08X\n", MCF_SDRAMC_SDCS1);}/********************************************************************//*! * \brief SDRAM Burst Read Test * \param addr SDRAM test address * \return 0 for success, non-zero for failure * * Test aligned and mis-aligned burst reads from the SDRAM controller. * This test uses the cache to generate the bursts. */intsdram_burst_read (ADDRESS addr){ int i; uint32 lw0, lw1, lw2, lw3, *src; #ifdef SDRAM_DEBUG_PRINT printf("SDRAM Burst Read Test:\n"); #endif /* Initialize SDRAM with known data */ src = (uint32*)(addr); for (i = 0; i < sizeof(test_data)/4; i++) src[i] = test_data[i]; /* Setup CACR to enable data cache; default mode is inhibited-precise */ mcf5xxx_wr_cacr(0 | MCF5XXX_CACR_DEC | MCF5XXX_CACR_DDCM_IP | MCF5XXX_CACR_DCINVA); /* SDRAM will be copy-back cacheable */ mcf5xxx_wr_acr0(0 | MCF5XXX_ACR_AB(SDRAM_ADDRESS) | MCF5XXX_ACR_AM_256M | MCF5XXX_ACR_EN | MCF5XXX_ACR_SM_IGNORE | MCF5XXX_ACR_CM_CB); /* Access at 0x0 aligned address */ lw0 = *(uint32*)(addr + 0); lw1 = *(uint32*)(addr + 4); lw2 = *(uint32*)(addr + 8); lw3 = *(uint32*)(addr + 12); if ((lw0 != test_data[0]) || (lw1 != test_data[1]) || (lw2 != test_data[2]) || (lw3 != test_data[3])) return 1; #ifdef SDRAM_DEBUG_PRINT printf("\n0x0 aligned: "); for (i = 0; i < 4; i++) { printf(" %08x", src[i]); } #endif /* Invalidate the data cache */ mcf5xxx_wr_cacr(0 | MCF5XXX_CACR_DEC | MCF5XXX_CACR_DDCM_IP | MCF5XXX_CACR_DCINVA); /* Access at 0x4 aligned address */ lw1 = *(uint32*)(addr + 4); lw2 = *(uint32*)(addr + 8); lw3 = *(uint32*)(addr + 12); lw0 = *(uint32*)(addr + 0); if ((lw0 != test_data[0]) || (lw1 != test_data[1]) || (lw2 != test_data[2]) || (lw3 != test_data[3])) return 1; #ifdef SDRAM_DEBUG_PRINT printf("\n0x4 aligned: "); for (i = 0; i < 4; i++) { printf(" %08x", src[i]); } #endif /* Invalidate the data cache */ mcf5xxx_wr_cacr(0 | MCF5XXX_CACR_DEC | MCF5XXX_CACR_DDCM_IP | MCF5XXX_CACR_DCINVA); /* Access at 0x8 aligned address */ lw2 = *(uint32*)(addr + 8); lw3 = *(uint32*)(addr + 12); lw0 = *(uint32*)(addr + 0); lw1 = *(uint32*)(addr + 4); if ((lw0 != test_data[0]) || (lw1 != test_data[1]) || (lw2 != test_data[2]) || (lw3 != test_data[3])) return 1; #ifdef SDRAM_DEBUG_PRINT printf("\n0x8 aligned: "); for (i = 0; i < 4; i++) { printf(" %08x", src[i]); } #endif /* Invalidate the data cache */ mcf5xxx_wr_cacr(0 | MCF5XXX_CACR_DEC | MCF5XXX_CACR_DDCM_IP | MCF5XXX_CACR_DCINVA); /* Access at 0x4 aligned address */ lw1 = *(uint32*)(addr + 4); lw2 = *(uint32*)(addr + 8); lw3 = *(uint32*)(addr + 12); lw0 = *(uint32*)(addr + 0); if ((lw0 != test_data[0]) || (lw1 != test_data[1]) || (lw2 != test_data[2]) || (lw3 != test_data[3])) return 1; #ifdef SDRAM_DEBUG_PRINT printf("\n0x4 aligned: "); for (i = 0; i < 4; i++) { printf(" %08x", src[i]); } printf("\n"); #endif /* Disable and invalidate the data cache */ mcf5xxx_wr_cacr(MCF5XXX_CACR_DCINVA); return 0;}/********************************************************************//*! * \brief SDRAM Burst Write Test * \param addr SDRAM test address * \return 0 for pass, non-zero for failure * * Test aligned bursts to the SDRAM controller. This test uses the * movem instruction of the ColdFire core to burst to the memory. * * \warning This test does not perform mis-aligned burst writes. There * is no bus master on the MCF5445x that is capable of bursting * to the SDRAM on a non-line-aligned address. */intsdram_burst_write (ADDRESS addr){ int i; uint32 lw0, lw1, lw2, lw3, *dest; #ifdef SDRAM_DEBUG_PRINT printf("SDRAM Burst Write Test:\n"); #endif /* Initialize SDRAM with known data */ dest = (uint32*)(addr); for (i = 0; i < sizeof(test_data)/4; i++) dest[i] = 0x0; /* Burst writes */ for (i = 0; i < sizeof(test_data); i+=16) { mcf5xxx_move_line((ADDRESS)&test_data[i/4], (ADDRESS)&dest[i/4]); } /* Verify data in SDRAM */ for (i = 0; i < sizeof(test_data)/4; i++) { if (dest[i] != test_data[i]) return 1; } return 0;}/********************************************************************//*! * \brief SDRAM Data Bus Test * \param addr SDRAM test address * \return 0 for success, non-zero for failure */intsdram_data_test(ADDRESS address){ return (memtest_databus_8((uint8*)address) || memtest_databus_16((uint16*)address) || memtest_databus_16((uint16*)address+1) || memtest_databus_32((uint32*)address) || memtest_databus_32((uint32*)address+1) || memtest_databus_32((uint32*)address+2) || memtest_databus_32((uint32*)address+3));}/********************************************************************//*! * \brief SDRAM Address Bus Test * \param addr SDRAM test address * \param bytes Number of bytes to test * \return 0 for success, non-zero for failure */intsdram_addr_test(ADDRESS address, int bytes){ return (memtest_addrbus_8((uint8*)address, bytes) || memtest_addrbus_16((uint16*)address, bytes) || memtest_addrbus_16((uint16*)address+1, bytes) || memtest_addrbus_32((uint32*)address, bytes) || memtest_addrbus_32((uint32*)address+1, bytes) || memtest_addrbus_32((uint32*)address+2, bytes) || memtest_addrbus_32((uint32*)address+3, bytes));}/********************************************************************//*! * \brief SDRAM Device Test * \param addr SDRAM test address * \param bytes Number of bytes to test * \return 0 for success, non-zero for failure */intsdram_device_test(ADDRESS address, int bytes){ return (memtest_device_8((uint8*)address, bytes) || memtest_device_16((uint16*)address, bytes) || memtest_device_32((uint32*)address, bytes));}/********************************************************************//*! * \brief SDRAM Invalid Access Test * Access a region within the SDRAM slave port, but outside * the valid SDRAM mask range */voidsdram_invalid_access(void){ vuint32 data; #ifdef DEBUG_PRINT printf("\nPerforming invalid access tests.\n"); printf("You should see two internal bus faults next...\n"); #endif data = *(vuint32 *)(SDRAM_ADDRESS + SDRAM_SIZE); *(vuint32 *)(SDRAM_ADDRESS + SDRAM_SIZE) = data; }/********************************************************************//*! * \brief SDRAM Self-Refresh * Place the SDRAM device(s) in self-refresh mode for a period * of time and insure that the data in the memory was retained. * \return 0 for success, non-zero for failure */intsdram_self_refresh(void){ int i, result = 0; uint32 * pu32Data = (uint32 *)SDRAM_ADDRESS; /* Write data pattern to SDRAM */ for (i = 0; i < sizeof(test_data)/4; i++) pu32Data[i] = test_data[i]; sdram_enter_self_refresh(); /* Wait a second... */ cpu_pause(100000000); sdram_exit_self_refresh(); /* Test data in SDRAM */ for (i = 0; i < sizeof(test_data)/4; i++) if (pu32Data[i] != test_data[i]) result++; return result;}/********************************************************************//*! * \brief SDRAM Power-Down * Place the SDRAM device(s) in power-down mode for a period * of time and insure that the data in the memory was retained. * \return 0 for success, non-zero for failure */intsdram_power_down(void){ int i, result = 0; uint32 * pu32Data = (uint32 *)SDRAM_ADDRESS; /* Write data pattern to SDRAM */ for (i = 0; i < sizeof(test_data)/4; i++) pu32Data[i] = test_data[i]; sdram_enter_power_down(); /* Wait a second... */ cpu_pause(100000000); sdram_exit_power_down(); /* Test data in SDRAM */ for (i = 0; i < sizeof(test_data)/4; i++) if (pu32Data[i] != test_data[i]) result++; return result;}/********************************************************************//*! * \brief Perform all SDRAM tests * \return 0 for success, non-zero for failure */intsdram_all_tests (void){ int result = 0; ADDRESS addr = (ADDRESS) SDRAM_ADDRESS; sdram_invalid_access(); if (sdram_data_test(addr)) { #ifdef DEBUG_PRINT printf("FAILED: sdram_data_test()\n"); #endif result += 1; } if (sdram_addr_test(addr+(SDRAM_SIZE/8*3), SDRAM_SIZE/4)) { #ifdef DEBUG_PRINT printf("FAILED: sdram_addr_test()\n"); #endif result += 1; } if (sdram_device_test(addr+(SDRAM_SIZE/16*7), SDRAM_SIZE/8)) { #ifdef DEBUG_PRINT printf("FAILED: sdram_device_test()"); #endif result += 1; } if (sdram_burst_write(addr)) { #ifdef DEBUG_PRINT printf("FAILED: sdram_burst_write()\n"); #endif result += 1; } if (sdram_burst_read(addr)) { #ifdef DEBUG_PRINT printf("FAILED: sdram_burst_read()\n"); #endif result += 1; } #ifdef DEBUG_PRINT if (result == 0) printf("All SDRAM tests passed.\n"); #endif return result;}/********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -