Hi
How you write your code depends on your level of paranoia
Assuming you dont want to block execution while test a large amount of RAM then you have do to it one (or a few) location(s) at a time. This implies that some variables will be kept in RAM - what if these locations have failed, or fail during the test?
The following is designed mainly for on-chip RAM as it isn't trying to pick up faults in shorted address lines etc.
Basic concept (and please read this as psuedo code):
Init:
uint8 volatile *testPtr = (uint8 *)(RAM_START_ADDRESS);
Process: // do this one or more times per pass
DISABLE_INTERRUPTS;
uint8 savedData = *testPtr;
*testPtr = 0x55; // try writing 0x55
if(*testPtr != 0x55) RamFault;
*testPtr ^= 0xFF; // complement
if(*testPtr != 0xAA) RamFault;
*testPtr = savedData;
testPtr++;
if(testPtr > (uint8 *) RAM_END_ADDRESS)
{
testPtr = (uint8 *)(RAM_START_ADDRESS)
}
ENABLE_INTERRUPTS