Beispiel #1
0
        public bool UpdateBuffer(Eth ethInst)
        {
            UInt32[] bufferNext;
            CreateBuffer(out bufferNext);

            // compare new buffer and write difference
            for (UInt32 addressOffset = 0; addressOffset < _bufferSize; addressOffset += _maxBytesPerPacket)
            {
                // check buffer for changes
                bool updateBuffer = CheckIfUpdateNeeded(bufferNext, addressOffset);

                // write buffer
                if (updateBuffer)
                {
                    UInt32        errorCode = 0;
                    UInt32        address   = _bufferAddress + addressOffset;
                    List <UInt32> writeData = new List <UInt32>();
                    for (UInt32 index = 0; index < _maxBytesPerPacket; index += 4)
                    {
                        if (_flipImage)
                        {
                            // flip image
                            writeData.Add(bufferNext[((_bufferSize - 1) - (addressOffset + index)) / 4]);
                        }
                        else
                        {
                            writeData.Add(bufferNext[(addressOffset + index) / 4]);
                        }
                    }
                    ethInst.Write(address, writeData, out errorCode, _maxBytesPerPacket);
                    if (errorCode != Eth._errorSuccess)
                    {
                        Console.WriteLine("\nErrorCode = " + errorCode);
                        return(false);
                    }
                    // workaround to handle 100mbit receiver (read id)
                    _sentBytes += _maxBytesPerPacket;
                    if (_sentBytes >= 10000)
                    {
                        _sentBytes = 0;
                        UInt32 receiveData;
                        if ((!ethInst.Read32(0, out receiveData, out errorCode)) ||
                            (errorCode != Eth._errorSuccess) || (receiveData != 0xBEEF0123))
                        {
                            Console.WriteLine("\nRead failed");
                        }
                    }
                }
            }

            // update buffer
            bufferNext.CopyTo(_bufferDisplay, 0);
            return(true);
        }
Beispiel #2
0
        public static void memTest(Eth ethInst, bool useRandomData)
        {
            Console.Write("\n");
            const UInt32 memorySize     = 8388608; // 8 MByte
            const UInt16 bytesPerPacket = 1024;    // number of bytes per eth packet
            UInt32       _sentBytes     = 0;

            UInt32[] testData = new uint[8388608 / 4];

            // create random test data
            if (useRandomData)
            {
                var rand = new Random();
                for (int wordIndex = 0; wordIndex < memorySize / 4; wordIndex++)
                {
                    testData[wordIndex] = (UInt32)rand.Next(-2147483648, 2147483647);
                }
            }

            // write complete memory
            for (UInt32 addressOffset = 0; addressOffset < memorySize; addressOffset += bytesPerPacket)
            {
                UInt32        errorCode = 0;
                UInt32        address   = 0x00800000 + addressOffset;
                List <UInt32> writeData = new List <UInt32>();
                for (UInt32 index = 0; index < bytesPerPacket; index += 4)
                {
                    if (useRandomData)
                    {
                        writeData.Add(testData[(addressOffset + index) / 4]);
                    }
                    else
                    {
                        writeData.Add(addressOffset + index);
                    }
                }
                ethInst.Write(address, writeData, out errorCode, bytesPerPacket);
                if (errorCode != Eth._errorSuccess)
                {
                    Console.WriteLine("\nErrorCode = " + errorCode);
                }
                // workaround to handle 100mbit receiver (read id)
                _sentBytes += bytesPerPacket;
                if (_sentBytes >= 10000)
                {
                    _sentBytes = 0;
                    UInt32 receiveData;
                    if ((!ethInst.Read32(0, out receiveData, out errorCode)) ||
                        (errorCode != Eth._errorSuccess) || (receiveData != 0xBEEF0123))
                    {
                        Console.WriteLine("\nRead failed");
                    }
                }

                Console.Write("\r -> write to address  0x" + addressOffset.ToString("X"));
            }
            Console.Write("\n");

            // read complete memory
            for (UInt32 addressOffset = 0; addressOffset < memorySize; addressOffset += bytesPerPacket)
            {
                UInt32        errorCode = 0;
                List <UInt32> dataArray;
                UInt32        address = 0x00800000 + addressOffset;

                ethInst.Read(address, out dataArray, out errorCode, bytesPerPacket);

                if (errorCode != Eth._errorSuccess)
                {
                    Console.WriteLine("\nErrorCode = " + errorCode + " at address " + addressOffset.ToString("X"));
                    break;
                }
                if (dataArray.Count != bytesPerPacket / 4)
                {
                    Console.WriteLine("\nReceived number of words wrong = " + dataArray.Count);
                    break;
                }
                for (UInt32 wordIndex = 0; wordIndex < bytesPerPacket / 4; wordIndex++)
                {
                    UInt32 expectedData;
                    if (useRandomData)
                    {
                        expectedData = testData[addressOffset / 4 + wordIndex];
                    }
                    else
                    {
                        expectedData = addressOffset + (wordIndex * 4);
                    }
                    if (dataArray[(int)wordIndex] != expectedData)
                    {
                        UInt32 diff = dataArray[(int)wordIndex] ^ expectedData;
                        Console.WriteLine("\nRead data wrong at address 0x" + addressOffset.ToString("X") + " diff 0x" + diff.ToString("X"));
                        break;
                    }
                }
                Console.Write("\r -> read from address 0x" + addressOffset.ToString("X"));
            }
        }