Пример #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);
        }
Пример #2
0
 public VideoHandler(Eth ethInst, Monitor monitorInst)
 {
     _enable                = false;
     _ethernet              = ethInst;
     _frameBuffer           = new Framebuffer();
     _acc                   = new Acc();
     _splashScreen          = new SplashScreen(monitorInst);
     _dashScreen            = new DashScreen(_acc);
     _updateTimer           = new System.Timers.Timer(16.666);
     _updateTimer.Elapsed  += TimerElapsed;
     _updateTimer.AutoReset = true;
     _updateTimer.Enabled   = true;
 }
Пример #3
0
 public I2c(Eth ethInst)
 {
     _ethInst = ethInst;
 }
Пример #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("---------- Test ----------");

            Eth     ethInst     = new Eth(_ipAddress, _udpPort);
            I2c     i2cInst     = new I2c(ethInst);
            Monitor monitorInst = new Monitor(i2cInst);

            // args = new string[] {"Q"};

            if (!(((args.Length == 3) && (Equals(args[0], "W"))) ||
                  ((args.Length == 2) && Equals(args[0], "R")) ||
                  ((args.Length == 1) && Equals(args[0], "I")) ||
                  ((args.Length == 1) && Equals(args[0], "T")) ||
                  ((args.Length == 1) && Equals(args[0], "Q")) ||
                  (args.Length == 0)))
            {
                Console.WriteLine("Usage: Lcd [R/W] [Address] ([Data]) <memory r/w>");
                Console.WriteLine("       Lcd [I]                      <I2C test>");
                Console.WriteLine("       Lcd [T]                      <memory test>");
                Console.WriteLine("       Lcd [Q]                      <video>");
            }
            else
            {
                if (args.Length == 0)
                {
                    // enable video output
                    UInt32 errorCode = 0;
                    ethInst.Write32(0x04, 0x07, out errorCode);
                    if (errorCode != Eth._errorSuccess)
                    {
                        Console.WriteLine("ErrorCode = " + errorCode);
                        return;
                    }
                    else
                    {
                        VideoHandler handle = new VideoHandler(ethInst, monitorInst);
                        while (true)
                        {
                            ;
                        }
                    }
                }
                if (Equals(args[0], "Q"))
                {
                    // video output
                    VideoHandler handle = new VideoHandler(ethInst, monitorInst);
                    while (true)
                    {
                        ;
                    }
                }
                else if (Equals(args[0], "W"))
                {
                    // write word
                    UInt32 errorCode = 0;
                    ethInst.Write32(Convert.ToUInt32(args[1], 16), Convert.ToUInt32(args[2], 16), out errorCode);
                    Console.WriteLine("ErrorCode = " + errorCode);
                }
                else if (Equals(args[0], "R"))
                {
                    // read word
                    UInt32 readData  = 0;
                    UInt32 errorCode = 0;
                    ethInst.Read32(Convert.ToUInt32(args[1], 16), out readData, out errorCode);
                    Console.WriteLine("ReadData = " + readData.ToString("X") + " , ErrorCode = " + errorCode);
                }
                else if (Equals(args[0], "I"))
                {
                    // I2C test
                    HwTest.i2cTest(i2cInst, monitorInst);
                }
                else if (Equals(args[0], "T"))
                {
                    // memory test
                    HwTest.memTest(ethInst, true);
                }
                else
                {
                    Console.WriteLine("Unknown argument (R,W,I,T,Q)");
                }
            }
        }
Пример #5
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"));
            }
        }