/client_v4_1/Test/PortingKitTest/Archive/DeviceTests/HAL/AuxTests/Automated/Drivers/RAM/RAM_Test.cpp
# · C++ · 491 lines · 381 code · 63 blank · 47 comment · 66 complexity · 887941e3cb58006831cf32f545d55a0e MD5 · raw file
- /*********************************************************************/
- /* #includes */
- /*********************************************************************/
- #include "..\..\..\..\common\AutoTestProtocol.h"
-
- struct RAMTest
- {
- public:
-
- /*************************************************************/
- /* functions */
- /*************************************************************/
-
- static void Set32(UINT32 Address, UINT32 Value)
- {
- volatile UINT32 *Pt;
- Pt = (UINT32 *)Address;
- *Pt = Value;
- }
-
- static void Set16(UINT32 Address, UINT16 Value)
- {
- volatile UINT16 *Pt;
- Pt = (UINT16 *)Address;
- *Pt = Value;
- }
-
-
- static void Set8(UINT32 Address, UINT8 Value)
- {
- volatile UINT8 *Pt;
- Pt = (UINT8 *)Address;
- *Pt = Value;
- }
-
- static BOOL CheckSet32(UINT32 Address,UINT32 MySet,UINT32 MyCheck)
- {
- volatile UINT32 *Pt;
- UINT32 Temp;
- BOOL result;
-
- result = TRUE;
- Pt = (UINT32 *)Address;
- Temp = *Pt;
- if (Temp != MyCheck)
- {
- result = FALSE;
- HalTest_print_info("Error at memory location %08x: Set to %08x Read as %08x\r\n",Address,MyCheck,Temp);
- }
- else
- {
- //printf("OK at memory location %08x: Set to %08x Read as %08x\r\n",Address,MyCheck,Temp);
- }
-
- if (MySet)
- {
- Set32(Address,MySet);
- }
- return result;
- }
-
- static BOOL CheckSet16(UINT32 Address,UINT16 MySet,UINT16 MyCheck)
- {
- volatile UINT16 *Pt;
- UINT16 Temp;
- BOOL result;
-
- result = TRUE;
- Pt = (UINT16 *)Address;
- Temp = *Pt;
- if (Temp != MyCheck)
- {
- result = FALSE;
- HalTest_print_info("Error at memory location %08x: Set to %04x Read as %04x\r\n",Address,MyCheck,Temp);
- }
- else
- {
- //printf("OK at memory location %08x: Set to %08x Read as %08x\r\n",Address,MyCheck,Temp);
- }
-
- if (MySet)
- {
- Set16(Address,MySet);
- }
- return result;
- }
- static BOOL CheckSet8(UINT32 Address,UINT8 MySet,UINT8 MyCheck)
- {
- volatile UINT8 *Pt;
- UINT8 Temp;
- BOOL result;
-
- result = TRUE;
- Pt = (UINT8 *)Address;
- Temp = *Pt;
- if (Temp != MyCheck)
- {
- result = FALSE;
- HalTest_print_info("Error at memory location %08x: Set to %02x Read as %02x\r\n",Address,MyCheck,Temp);
- }
- else
- {
- //printf("OK at memory location %08x: Set to %08x Read as %08x\r\n",Address,MyCheck,Temp);
- }
-
- if (MySet)
- {
- Set8(Address,MySet);
- }
- return result;
- }
-
-
-
-
- static BOOL MemoryWalkingAddress(UINT32 Start, UINT32 Stop)
- {
- BOOL result;
- UINT32 cursor;
- UINT32 i;
- UINT32 j;
- result = TRUE;
-
- //set all to 0...
- for (cursor = Start; cursor < Stop; cursor+=4)
- {
- Set32(cursor,0x00000000);
- }
- //check 0 and set address
- for (cursor = Start; cursor < Stop; cursor+=4)
- {
- result = result & CheckSet32(cursor,cursor,0x00000000);
- }
- //check address and set Antiaddress
- for (cursor = Start; cursor < Stop; cursor+=4)
- {
- result = result & CheckSet32(cursor,0xffffffff - cursor,cursor);
- }
-
- //check antiaddress
- for (cursor = Start; cursor < Stop; cursor+=4)
- {
- result = result & CheckSet32(cursor,0,0xffffffff - cursor);
- }
-
- return result;
- }
-
- static BOOL MemoryWalkingAddress16(UINT32 Start, UINT32 Stop)
- {
- BOOL result;
- UINT32 cursor;
- UINT32 i;
- UINT32 j;
- result = TRUE;
-
- //set all to 0...
- for (cursor = Start; cursor < Stop; cursor+=2)
- {
- Set16(cursor,0x0000);
- }
- //check 0 and set address
- for (cursor = Start; cursor < Stop; cursor+=2)
- {
- result = result & CheckSet16(cursor,(UINT16)cursor,0x0000);
- }
- //check address and set Antiaddress
- for (cursor = Start; cursor < Stop; cursor+=2)
- {
- result = result & CheckSet16(cursor,(UINT16)(0xffffffff - cursor),(UINT16)cursor);
- }
-
- //check antiaddress
- for (cursor = Start; cursor < Stop; cursor+=2)
- {
- result = result & CheckSet16(cursor,0,(UINT16)(0xffffffff - cursor));
- }
-
- return result;
- }
- static BOOL MemoryWalkingAddress8(UINT32 Start, UINT32 Stop)
- {
- BOOL result;
- UINT32 cursor;
- UINT32 i;
- UINT32 j;
- result = TRUE;
-
- //set all to 0...
- for (cursor = Start; cursor < Stop; cursor+=1)
- {
- Set8(cursor,0x0000);
- }
- //check 0 and set address
- for (cursor = Start; cursor < Stop; cursor+=1)
- {
- result = result & CheckSet8(cursor,(UINT8)cursor,0x00);
- }
- //check address and set Antiaddress
- for (cursor = Start; cursor < Stop; cursor+=1)
- {
- result = result & CheckSet8(cursor,(UINT8)(0xffffffff - cursor),(UINT8)cursor);
- }
-
- //check antiaddress
- for (cursor = Start; cursor < Stop; cursor+=1)
- {
- result = result & CheckSet8(cursor,0,(UINT8)(0xffffffff - cursor));
- }
-
- return result;
- }
-
- static BOOL MemoryAlternate(UINT32 Start, UINT32 Stop)
- {
- BOOL result;
- UINT32 cursor;
- UINT32 i;
- UINT32 j;
- result = TRUE;
- i = 0;
- //set alternate
- for (cursor = Start; cursor < Stop; cursor+=4)
- {
- i++;
- if (i & 0x1)
- Set32(cursor,0x55555555);
- else
- Set32(cursor,0xAAAAAAAA);
-
- }
- i = 0;
- //check alternate
- for (cursor = Start; cursor < Stop; cursor+=4)
- {
- i++;
- if (i & 0x1)
- result = result & CheckSet32(cursor,0xAAAAAAAA,0x55555555);
- else
- result = result & CheckSet32(cursor,0x55555555,0xAAAAAAAA);
-
- }
- //check alternate
- i = 0;
-
- for (cursor = Start; cursor < Stop; cursor+=4)
- {
- i++;
-
- if (i & 0x1)
- result = result & CheckSet32(cursor,0,0xAAAAAAAA);
- else
- result = result & CheckSet32(cursor,0,0x55555555);
- }
-
-
-
- return result;
- }
-
- static BOOL MemoryWalk_1( UINT32 start_addr )
- {
- BOOL result = FALSE;
- volatile UINT32 WordSave;
- volatile UINT32 *MyPointer, Value;
- volatile UINT32 Cursor,Counter;
- UINT32 i,j;
- result = TRUE;
- // order is important here if we have interrupts on IRQs might modify RAM areas after we save
- {
- SmartPtr_IRQ irq;
-
- // this routine cannot call any functions until memory word is restored!
- // The functions might live in RAM being tested
- Cursor = start_addr;
- Counter = 0;
- MyPointer = (UINT32 *)Cursor;
-
- while(Cursor < (SRAM1_MEMORY_Base + SRAM1_MEMORY_Size) && Cursor != (UINT32)MemoryWalk_1)
- {
- Counter ++;
- WordSave = *MyPointer;
-
- if( Cursor % 0x1000 == 0 )
- hal_fprintf( STREAM_LCD, "\r0x%08x", Cursor );
- //here run the test
- //STEP 1: SET memory to all 0s
- *MyPointer = 0x00000000;
- if (0x00000000 != *MyPointer)
- {
- HalTest_print_info("Cannot set to all 0s memory location %08x. It is %08x\r\n",Cursor, *MyPointer);
- result = FALSE;
- }
- i = 0x00000001;
- j = 1;
- while(j < 33)
- {
- *MyPointer = i;
- if (i != *MyPointer)
- result = FALSE;
- i = i + i;
- j++;
-
- }
- // Zero
- *MyPointer = 0xffffffff;
- if (0xffffffff != *MyPointer)
- {
- HalTest_print_info("Cannot set to all 1s memory location %08x. It is %08x\r\n",Cursor, *MyPointer);
- result = FALSE;
- }
- i = 0x00000001;
- j = 1;
- while(j < 33)
- { Value = 0xffffffff - i;
- *MyPointer = Value;
- if (Value != *MyPointer)
- result = FALSE;
- i = i + i;
- j++;
- //printf("%08x %08x\r\n",Value, Cursor);
- }
- //STEP 1: SET memory to be anti-address
- Value = 0xffffffff - Cursor;
- *MyPointer = Value;
- if (Value != *MyPointer)
- {
- HalTest_print_info("Cannot set memory location %08x to its anti - address(%08x). It is %08x\r\n",Cursor, Value, *MyPointer);
- result = FALSE;
- }
-
- //Restore the memory content
- *MyPointer = WordSave;
- //Increment the cursor-pointer
- Cursor += sizeof(UINT32);
- MyPointer = (UINT32*)Cursor;
- }
- }
-
- HalTest_print_info("Performed Walking One on each bit of RAM (till %08x). There were %d memory locations.\r\n",Cursor, Counter*sizeof(UINT32));
- if (result)
- {
- HalTest_print_info("Test Passes\r\n");
- }
- Events_WaitForEvents(0, 200);
-
- return result;
- }
-
- static BOOL MemoryWalk_2( UINT32 start_addr )
- {
- BOOL result = FALSE;
- volatile UINT32 WordSave;
- volatile UINT32 *MyPointer, Value;
- volatile UINT32 Cursor,Counter;
- UINT32 i,j;
- result = TRUE;
- // order is important here if we have interrupts on IRQs might modify RAM areas after we save
- {
- SmartPtr_IRQ irq;
-
- // this routine cannot call any functions until memory word is restored!
- // The functions might live in RAM being tested
- Cursor = start_addr;
- Counter = 0;
- MyPointer = (UINT32 *)Cursor;
-
- while(Cursor < (SRAM1_MEMORY_Base+SRAM1_MEMORY_Size) && Cursor != (UINT32)MemoryWalk_2)
- {
- Counter ++;
- WordSave = *MyPointer;
-
- if( Cursor % 0x1000 == 0 )
- hal_fprintf( STREAM_LCD, "\r0x%08x", Cursor );
- //here run the test
- //STEP 1: SET memory to all 0s
- *MyPointer = 0x00000000;
- if (0x00000000 != *MyPointer)
- {
- HalTest_print_info("Cannot set to all 0s memory location %08x. It is %08x\r\n",Cursor, *MyPointer);
- result = FALSE;
- }
- i = 0x00000001;
- j = 1;
- while(j < 33)
- {
- *MyPointer = i;
- if (i != *MyPointer)
- result = FALSE;
- i = i + i;
- j++;
-
- }
- // Zero
- *MyPointer = 0xffffffff;
- if (0xffffffff != *MyPointer)
- {
- HalTest_print_info("Cannot set to all 1s memory location %08x. It is %08x\r\n",Cursor, *MyPointer);
- result = FALSE;
- }
- i = 0x00000001;
- j = 1;
- while(j < 33)
- { Value = 0xffffffff - i;
- *MyPointer = Value;
- if (Value != *MyPointer)
- result = FALSE;
- i = i + i;
- j++;
- //printf("%08x %08x\r\n",Value, Cursor);
- }
- //STEP 1: SET memory to be anti-address
- Value = 0xffffffff - Cursor;
- *MyPointer = Value;
- if (Value != *MyPointer)
- {
- HalTest_print_info("Cannot set memory location %08x to its anti - address(%08x). It is %08x\r\n",Cursor, Value, *MyPointer);
- result = FALSE;
- }
-
- //Restore the memory content
- *MyPointer = WordSave;
- //Increment the cursor-pointer
- Cursor += sizeof(UINT32);
- MyPointer = (UINT32*)Cursor;
- }
- }
-
- HalTest_print_info("Performed Walking One on each bit of RAM (till %08x). There were %d memory locations.\r\n",Cursor, Counter*sizeof(UINT32));
- if (result)
- {
- HalTest_print_info("Test Passes\r\n");
- }
- Events_WaitForEvents(0, 200);
-
- return result;
- }
-
-
- static BOOL ApplicationEntryPoint()
- {
- BOOL bRet = TRUE;
-
- HalTest_print_info("RAM Test\r\n");
- HalTest_print_info("Ram Start: 0x%08x\r\n", SRAM1_MEMORY_Base );
- HalTest_print_info("Ram Size : 0x%08x\r\n", SRAM1_MEMORY_Size );
- //SRAM1_MEMORY_Base
- //SRAM1_MEMORY_Size
- // are we in RAM??
- if( ((UINT32)MemoryWalk_1 < (SRAM1_MEMORY_Base + SRAM1_MEMORY_Size)) &&
- ((UINT32)MemoryWalk_1 >= (SRAM1_MEMORY_Base )) )
- {
- if( (UINT32)MemoryWalk_1 < (UINT32)MemoryWalk_2 )
- {
- bRet &= MemoryWalk_2( SRAM1_MEMORY_Base );
- bRet &= MemoryWalk_1( (UINT32)MemoryWalk_2 );
- }
- else
- {
- bRet &= MemoryWalk_1( SRAM1_MEMORY_Base );
- bRet &= MemoryWalk_2( (UINT32)MemoryWalk_1 );
- }
- }
- else // not in ram
- {
- bRet &= MemoryWalk_1( SRAM1_MEMORY_Base );
- }
-
- HalTest_print_info("Doing RAM WalkTest\r\n");
-
- HalTest_print_info("WalkAddress");
- bRet &= Report(MemoryWalkingAddress(SRAM1_MEMORY_Base+SRAM1_MEMORY_Size/2,SRAM1_MEMORY_Size/1024));
-
- HalTest_print_info("WalkAlternate");
- bRet &= Report(MemoryAlternate(SRAM1_MEMORY_Base+SRAM1_MEMORY_Size/2,SRAM1_MEMORY_Size/1024));
-
- HalTest_print_info("WalkAddress");
- bRet &= Report(MemoryWalkingAddress(SRAM1_MEMORY_Base+SRAM1_MEMORY_Size/2,SRAM1_MEMORY_Size/1024));
-
- HalTest_print_info("WalkAlternate");
- bRet &= Report(MemoryAlternate(SRAM1_MEMORY_Base+SRAM1_MEMORY_Size/2,SRAM1_MEMORY_Size/1024));
-
- HalTest_print_info("WalkAddress16");
- bRet &= Report(MemoryWalkingAddress16(SRAM1_MEMORY_Base+SRAM1_MEMORY_Size/2,SRAM1_MEMORY_Size/1024));
-
- HalTest_print_info("WalkAddress8");
- bRet &= Report(MemoryWalkingAddress8(SRAM1_MEMORY_Base+SRAM1_MEMORY_Size/2,SRAM1_MEMORY_Size/1024));
-
- return bRet;
- }
- };