arm_ucos/src/common/memtest.c
/**********************************************************************
 *
 * Function:    memTestAddressBus()
 *
 * Description: Test the address bus wiring in a memory region by
 *              performing a walking 1's test on the relevant bits
 *              of the address and checking for aliasing. This test
 *              will find single-bit address failures such as stuck
 *              -high, stuck-low, and shorted pins.  The base address
 *              and size of the region are selected by the caller.
 *
 * Notes:       For best results, the selected base address should
 *              have enough LSB 0's to guarantee single address bit
 *              changes.  For example, to test a 64-Kbyte region, 
 *              select a base address on a 64-Kbyte boundary.  Also, 
 *              select the region size as a power-of-two--if at all 
 *              possible.
 *
 * Returns:     NULL if the test succeeds.  
 *              A non-zero result is the first address at which an
 *              aliasing problem was uncovered.  By examining the
 *              contents of memory, it may be possible to gather
 *              additional information about the problem.
 *
 **********************************************************************/


Test the address bus wiring in a memory region by
performing a walking 1's test on the relevant bits
of the address and checking for aliasing. This test
will find single-bit address failures such as stuck
-high, stuck-low, and shorted pins.  The base address
and size of the region are selected by the caller.

For best results, the selected base address should
have enough LSB 0's to guarantee single address bit
changes.  For example, to test a 64-Kbyte region,
select a base address on a 64-Kbyte boundary.  Also,
select the region size as a power-of-two--if at all
possible.

NULL if the test succeeds.
A non-zero result is the first address at which an
aliasing problem was uncovered.  By examining the
contents of memory, it may be possible to gather
additional information about the problem.
Test the address bus wiring in a memory region by performing a walking 1 ' s test on the relevant bits of the address and checking for aliasing . This test will find single - bit address failures such as stuck - high stuck - low and shorted pins . The base address and size of the region are selected by the caller . For best results the selected base address should have enough LSB 0 ' s to guarantee single address bit changes . For example to test a 64 - Kbyte region select a base address on a 64 - Kbyte boundary . Also select the region size as a power - of - two -- if at all possible . NULL if the test succeeds . A non - zero result is the first address at which an aliasing problem was uncovered . By examining the contents of memory it may be possible to gather additional information about the problem .
datum * 
memTestAddressBus(volatile datum * baseAddress, unsigned long nBytes)
{
    unsigned long addressMask = (nBytes/sizeof(datum) - 1);
    unsigned long offset;
    unsigned long testOffset;
    datum pattern     = (datum) 0xAAAAAAAA;
    datum antipattern = (datum) 0x55555555;
    for (offset = 1; (offset & addressMask) != 0; offset <<= 1)
    {
        baseAddress[offset] = pattern;
    }
    testOffset = 0;
    baseAddress[testOffset] = antipattern;
    for (offset = 1; (offset & addressMask) != 0; offset <<= 1)
    {
        if (baseAddress[offset] != pattern)
        {
            return ((datum *) &baseAddress[offset]);
        }
    }
    baseAddress[testOffset] = pattern;
    for (testOffset = 1; (testOffset & addressMask) != 0; testOffset <<= 1)
    {
        baseAddress[testOffset] = antipattern;
		if (baseAddress[0] != pattern)
		{
			return ((datum *) &baseAddress[testOffset]);
		}
        for (offset = 1; (offset & addressMask) != 0; offset <<= 1)
        {
            if ((baseAddress[offset] != pattern) && (offset != testOffset))
            {
                return ((datum *) &baseAddress[testOffset]);
            }
        }
        baseAddress[testOffset] = pattern;
    }
    return (NULL);
}
datum * memTestAddressBus ( volatile datum * baseAddress , unsigned long nBytes ) { unsigned long addressMask = ( nBytes / sizeof ( datum ) - 1 ) ; unsigned long offset ; unsigned long testOffset ; datum pattern = ( datum ) 0xAAAAAAAA ; datum antipattern = ( datum ) 0x55555555 ; for ( offset = 1 ; ( offset & addressMask ) != 0 ; offset <<= 1 ) { baseAddress [ offset ] = pattern ; } testOffset = 0 ; baseAddress [ testOffset ] = antipattern ; for ( offset = 1 ; ( offset & addressMask ) != 0 ; offset <<= 1 ) { if ( baseAddress [ offset ] != pattern ) { return ( ( datum * ) & baseAddress [ offset ] ) ; } } baseAddress [ testOffset ] = pattern ; for ( testOffset = 1 ; ( testOffset & addressMask ) != 0 ; testOffset <<= 1 ) { baseAddress [ testOffset ] = antipattern ; if ( baseAddress [ 0 ] != pattern ) { return ( ( datum * ) & baseAddress [ testOffset ] ) ; } for ( offset = 1 ; ( offset & addressMask ) != 0 ; offset <<= 1 ) { if ( ( baseAddress [ offset ] != pattern ) && ( offset != testOffset ) ) { return ( ( datum * ) & baseAddress [ testOffset ] ) ; } } baseAddress [ testOffset ] = pattern ; } return ( NULL ) ; }
Function:    memTestAddressBus()
Function : memTestAddressBus ()
/*
     * Write the default pattern at each of the power-of-two offsets.
     */ /* 
     * Check for address bits stuck high.
     */ /*
     * Check for address bits stuck low or shorted.
     */