 1Content-type: application/x-Unknown; charset=UTF8package nmc.sidekick;

import java.io.IOException;
import com.ajile.util.PropUtils;
import com.ajile.jem.rawJEM;

/**
 * Example program which demonstrates how to use the RAMTest instruction to test a
 * block of read/write RAM memory.  Copied from Ajile distribution, with a few
 * minor changes.
 */
public class Ramtest {

    private static int RAMStart;
    private static int RAMSize;

    public static void main(String[] args) {

        Ramtest app = new Ramtest();
    }

    // RAM starts at 0x10, default is 1MB, but allow for non-default
    // RAM starts and sizes if the properties are set
    public Ramtest() {

        int RAMSize = 0;
        int RAMStart = 0x0;
        int TEST_PATTERN_1 = 0x55555555;
        int TEST_PATTERN_2 = 0xAAAAAAAA;

        DebugMessage.println("Starting test of SRAM^_^_^_^_^_^_^_^_^_^");

        boolean loopRAMTest = System.getProperty("repeat.test") != null;

        RAMStart = PropUtils.getIntProperty("ram.start", 0x10);

        DebugMessage.println("RAMStart= 0x" + Integer.toHexString(RAMStart));

        RAMSize = PropUtils.getIntProperty("ram.size", 0x120000);

        DebugMessage.println("RAMSize= 0x" +  Integer.toHexString(RAMSize));

        int RAMTestStart;

        // Don't start the RAM test at location 0x0
        if (RAMStart == 0x0) {
            RAMTestStart = 0x10;
        } else {
            RAMTestStart = RAMStart;
        }

        int numBytes = (RAMSize - RAMTestStart);

        do {

            DebugMessage.println("---------------------------------------");
            DebugMessage.println("RAM test starting at address 0x" + RAMTestStart);

            // Run a non-destructive pattern test pattern1 and pattern2 on physical RAM memory
            int failword = rawJEM.ramTest(RAMTestStart, numBytes/4, TEST_PATTERN_1, TEST_PATTERN_2);

            DebugMessage.println(numBytes + " bytes written");

            if (failword != 0)
                DebugMessage.println("Failed at word 0x" + Integer.toHexString(failword));
            else
                DebugMessage.println("RAM test passed");

            DebugMessage.println("---------------------------------------");

        } while (loopRAMTest);
    }
} // Ramtest
