📄 sdram.c
字号:
/*H******************************************************************************* $Archive:: $* $Revision:: $* $Date:: $* $Author:: $** DESCRIPTION: ** GLOBALS ** PUBLIC FUNCTIONS:* * PRIVATE FUNCTIONS:** USAGE/LIMITATIONS:** NOTES: ***H***************************************************************************/#define sdram_c/*---- compilation control switches ----------------------------------------*//****************************************************************************** INCLUDE FILES*****************************************************************************//*---- system and platform files -------------------------------------------*/#include <stdlib.h>#include <stdio.h>#include <c6x.h>/*---- program files -------------------------------------------------------*/#include "sdram.h"/****************************************************************************** EXTERNAL REFERENCE *****************************************************************************//*---- data declarations ---------------------------------------------------*//*---- function prototypes -------------------------------------------------*//****************************************************************************** PUBLIC DECLARATIONS *****************************************************************************//*---- data declarations ---------------------------------------------------*//****************************************************************************** PRIVATE DECLARATIONS *****************************************************************************//*---- context -------------------------------------------------------------*//*---- data declarations ---------------------------------------------------*//*---- function prototypes -------------------------------------------------*//*---- macros --------------------------------------------------------------*//****************************************************************************** PUBLIC FUNCTION DEFINITIONS*****************************************************************************//*F**************************************************************************** NAME: FLASH_Write ** DESCRIPTION: Write "Count" words to flash. * * NOTES:* *F***************************************************************************/ /*F**************************************************************************** NAME: DRAM_SlidingData32** DESCRIPTION: Write Sliding data pattern to DRAM address/address+1. Tests* for data failures. * * NOTES: DRAM address must be on a 4 byte boundary as we are doing 32 bit* data test. When we write the complement pattern it must be on * *F***************************************************************************/int DRAM_SlidingData32( DRAM_ADDR DramAddr, DRAM_DWORD Pattern, int Count ){ volatile DRAM_DWORD * pDRAM_DWORD = ( volatile DRAM_DWORD *)DramAddr; int Error = 0; DRAM_DWORD Value = 1; int i; for( i=0; i<Count; i++ ) { if( Pattern ) { // Test for sliding 1 pDRAM_DWORD[0] = Value; pDRAM_DWORD[2] = ~Value; // !Pattern to complement the bus if( pDRAM_DWORD[0] != Value ) Error++; } else { // Test for sliding 0 pDRAM_DWORD[0] = ~Value; pDRAM_DWORD[2] = Value; // !Pattern to complement the bus if( pDRAM_DWORD[0] != ~Value ) Error++; } Value = Value << 1; } return( Error );}/*F**************************************************************************** NAME: DRAM_ByteStrobes** DESCRIPTION: Write data as DRAM_BYTEs and read as words. Tests for functional* DRAM_BYTE strobes. * * NOTES: DRAM address must be on a 4 byte boundary as we are doing 32 bit* data test.** Endianess does matter for this test. So if BigEndian we store* the data byte reversed.* *F***************************************************************************/int DRAM_ByteStrobes( DRAM_ADDR DramAddr, DRAM_DWORD Pattern ){ volatile DRAM_BYTE * pDRAM_BYTE = ( volatile DRAM_BYTE *)DramAddr; volatile DRAM_DWORD * pDRAM_DWORD = ( volatile DRAM_DWORD *)DramAddr; DRAM_DWORD Temp[2]; int Error = 0; int BigEndian = ((CSR & 0x100) == 0); // Write the pattern and ~pattern to two word locations // as DRAM_BYTEs then read back as 32 bit. if( !BigEndian ) { pDRAM_BYTE[7] = (DRAM_BYTE)( Pattern >> 24); pDRAM_BYTE[3] = (DRAM_BYTE)(~Pattern >> 24); pDRAM_BYTE[6] = (DRAM_BYTE)( Pattern >> 16); pDRAM_BYTE[2] = (DRAM_BYTE)(~Pattern >> 16); pDRAM_BYTE[5] = (DRAM_BYTE)( Pattern >> 8); pDRAM_BYTE[1] = (DRAM_BYTE)(~Pattern >> 8); pDRAM_BYTE[4] = (DRAM_BYTE)( Pattern >> 0); pDRAM_BYTE[0] = (DRAM_BYTE)(~Pattern >> 0); } else { pDRAM_BYTE[4] = (DRAM_BYTE)( Pattern >> 24); pDRAM_BYTE[0] = (DRAM_BYTE)(~Pattern >> 24); pDRAM_BYTE[5] = (DRAM_BYTE)( Pattern >> 16); pDRAM_BYTE[1] = (DRAM_BYTE)(~Pattern >> 16); pDRAM_BYTE[6] = (DRAM_BYTE)( Pattern >> 8); pDRAM_BYTE[2] = (DRAM_BYTE)(~Pattern >> 8); pDRAM_BYTE[7] = (DRAM_BYTE)( Pattern >> 0); pDRAM_BYTE[3] = (DRAM_BYTE)(~Pattern >> 0); } Temp[0] = pDRAM_DWORD[0]; Temp[1] = pDRAM_DWORD[1]; if( Temp[0] != ~Pattern ) Error++; if( Temp[1] != Pattern ) Error++; return( Error );}/*F**************************************************************************** NAME: DRAM_SlidingAddr32** DESCRIPTION: Test binary power of 2 addresses. This tests for functional* address bits.* * NOTES: DRAM address must be on a 4 byte boundary as we are doing 32 bit* data test.* *F***************************************************************************/int DRAM_SlidingAddr32( DRAM_ADDR DramAddr, int Count ){ volatile DRAM_DWORD * pDRAM_DWORD; DRAM_DWORD TestAddr; DRAM_DWORD BckgndAddr; DRAM_DWORD TestPattern; int i; int j; int Error; // The address bit must be on an 4 byte boundary for this test. // We want to have only 1 address bit change and all bytes // strobes in a word. TestPattern = 0x87654321; Error = 0; for( i=0; i<Count; i++ ) { TestAddr = DramAddr + (4<<i); pDRAM_DWORD = (volatile DRAM_DWORD *)TestAddr; // Write the test pattern *pDRAM_DWORD = TestPattern; // Now write to all the other address bits with compliment data // to test for disturbance. for( j=0; j<Count; j++ ) { BckgndAddr = DramAddr + (4<<j); if( TestAddr != BckgndAddr ) { pDRAM_DWORD = (volatile DRAM_DWORD *)BckgndAddr; *pDRAM_DWORD = ~TestPattern+i; } } pDRAM_DWORD = (volatile DRAM_DWORD *)TestAddr; if( *pDRAM_DWORD != TestPattern ) Error++; } return( Error );}/*F**************************************************************************** NAME: DRAM_AddressAsData** DESCRIPTION: Write the DRAM address as data to test that each memory* location is unique.* * NOTES: DRAM address must be on a 4 byte boundary as we are doing 32 bit* data test.* *F***************************************************************************/int DRAM_AddressAsData( DRAM_ADDR DramAddr, int Count ){ volatile DRAM_DWORD * pDRAM_DWORD; DRAM_DWORD TestPattern; int i; int Error; pDRAM_DWORD = (DRAM_ADDR *) DramAddr; TestPattern = DramAddr; for( i=0; i<Count; i++ ) { // Write the test pattern *pDRAM_DWORD = TestPattern; pDRAM_DWORD++; TestPattern++; } Error = 0; pDRAM_DWORD = (DRAM_ADDR *) DramAddr; TestPattern = DramAddr; for( i=0; i<Count; i++ ) { // Read the test pattern if( *pDRAM_DWORD != TestPattern ) Error++; pDRAM_DWORD++; TestPattern++; } return( Error );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -