Пример #1
0
        public void I2CRetryTest()
        {
            Console.WriteLine("Starting I2C retry test...");

            Stopwatch timer = new Stopwatch();

            I2CPreamble pre = new I2CPreamble();

            pre.DeviceAddress = 0x0;
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0);
            pre.StartMask = 0;

            Console.WriteLine("Setting retry count to 0");
            FX3.I2CRetryCount = 0;
            Assert.AreEqual(0, FX3.I2CRetryCount, "ERROR: Setting not applied correctly");

            Console.WriteLine("Attempting to read non-existent device... (address 0)");
            timer.Start();
            try
            {
                FX3.I2CReadBytes(pre, 128, 1000);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            timer.Stop();
            Console.WriteLine("Elapsed time: " + timer.ElapsedMilliseconds.ToString() + "ms");
            CheckFirmwareResponsiveness();
        }
Пример #2
0
        public void I2CReadTest()
        {
            Console.WriteLine("Starting I2C read test...");

            byte[] InitialRead, SecondRead;

            I2CPreamble pre = new I2CPreamble();

            pre.DeviceAddress = 0xA0;
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0xA1);
            pre.StartMask = 4;

            for (uint readLen = 2; readLen < 256; readLen += 2)
            {
                Console.WriteLine("Testing " + readLen.ToString() + " byte read");
                InitialRead = FX3.I2CReadBytes(pre, readLen, 1000);
                SecondRead  = FX3.I2CReadBytes(pre, readLen, 1000);
                for (int i = 0; i < InitialRead.Count(); i++)
                {
                    Assert.AreEqual(InitialRead[i], SecondRead[i], "ERROR: Expected flash read data to match");
                }
            }
        }
Пример #3
0
        public void I2CStreamTest()
        {
            Console.WriteLine("Starting I2C data stream test...");

            I2CPreamble pre = new I2CPreamble();

            pre.DeviceAddress = 0xA0;
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0xA1);
            pre.StartMask = 4;

            TestI2CFunctionality();

            byte[] StreamData, InitialRead;

            for (int trial = 0; trial < 5; trial++)
            {
                Console.WriteLine("Starting stream...");
                FX3.StartI2CStream(pre, 64, 1000);
                FX3.WaitForStreamCompletion(10000);
                Console.WriteLine("Stream complete. Checking data...");
                InitialRead = FX3.GetI2CBuffer();
                for (int i = 1; i < 1000; i++)
                {
                    StreamData = FX3.GetI2CBuffer();
                    for (int j = 0; j < StreamData.Count(); j++)
                    {
                        Assert.AreEqual(InitialRead[j], StreamData[j], "ERROR: Invalid I2C read back data on buffer " + i.ToString());
                    }
                }
                TestI2CFunctionality();
            }
        }
Пример #4
0
        public void I2CStreamCancelTest()
        {
            Console.WriteLine("Starting I2C stream cancel test...");

            long firstCount;

            I2CPreamble pre = new I2CPreamble();

            pre.DeviceAddress = 0xA0;
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0);
            pre.StartMask = 4;

            for (int trial = 0; trial < 5; trial++)
            {
                Console.WriteLine("Starting trial " + trial.ToString());

                /* Start stream */
                FX3.StartI2CStream(pre, 64, 1000000);
                firstCount = FX3.GetNumBuffersRead;
                System.Threading.Thread.Sleep(100);
                Assert.Greater(FX3.GetNumBuffersRead, firstCount, "ERROR: Expected to have read buffers");

                /* Cancel stream (stop stream) */
                FX3.StopStream();
                System.Threading.Thread.Sleep(20);

                /* Test read functionality */
                TestI2CFunctionality();

                /* Start stream */
                FX3.StartI2CStream(pre, 64, 1000000);
                firstCount = FX3.GetNumBuffersRead;
                System.Threading.Thread.Sleep(100);
                Assert.Greater(FX3.GetNumBuffersRead, firstCount, "ERROR: Expected to have read buffers");

                /* Cancel stream (cancel stream) */
                FX3.CancelStreamAsync();
                System.Threading.Thread.Sleep(20);

                /* Test read functionality */
                TestI2CFunctionality();
            }
        }
Пример #5
0
        private void TestI2CFunctionality()
        {
            byte[] InitialRead, SecondRead;

            I2CPreamble pre = new I2CPreamble();

            pre.DeviceAddress = 0xA0;
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0xA1);
            pre.StartMask = 4;

            InitialRead = FX3.I2CReadBytes(pre, 64, 1000);
            SecondRead  = FX3.I2CReadBytes(pre, 64, 1000);
            for (int i = 0; i < InitialRead.Count(); i++)
            {
                Assert.AreEqual(InitialRead[i], SecondRead[i], "ERROR: Expected flash read data to match");
            }
        }
Пример #6
0
        public void ErrorLogRobustnessTest()
        {
            Console.WriteLine("Starting error log robustness test...");

            List <FX3ErrorLog> initialLog, log;

            I2CPreamble preRead = new I2CPreamble();

            preRead.DeviceAddress = 0xA0;
            preRead.PreambleData.Add(0);
            preRead.PreambleData.Add(0);
            preRead.PreambleData.Add(0xA1);
            preRead.StartMask = 4;

            I2CPreamble preWrite = new I2CPreamble();

            preWrite.DeviceAddress = 0;
            preWrite.PreambleData.Add(0);
            preWrite.StartMask = 0;

            Console.WriteLine("Rebooting FX3...");
            FX3.Disconnect();
            System.Threading.Thread.Sleep(500);
            Connect();

            Console.WriteLine("Getting initial error log...");
            initialLog = FX3.GetErrorLog();
            foreach (FX3ErrorLog entry in initialLog)
            {
                Console.WriteLine(entry.ToString());
            }

            Console.WriteLine("Starting I2C Read...");
            try
            {
                FX3.I2CReadBytes(preRead, 32, 1000);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Getting error log...");
            log = FX3.GetErrorLog();
            CheckLogEquality(initialLog, log, false);

            Console.WriteLine("Starting invalid I2C write...");
            try
            {
                FX3.I2CWriteBytes(preWrite, new byte[] { 1, 2, 3, 4 }, 1000);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Getting error log...");
            log = FX3.GetErrorLog();
            CheckLogEquality(initialLog, log, true);

            initialLog.Clear();
            foreach (FX3ErrorLog entry in log)
            {
                initialLog.Add(entry);
            }

            Console.WriteLine("Starting I2C stream...");
            FX3.StartI2CStream(preRead, 64, 10);
            System.Threading.Thread.Sleep(2000);

            Console.WriteLine("Getting error log...");
            log = FX3.GetErrorLog();
            CheckLogEquality(initialLog, log, false);

            Console.WriteLine("Rebooting FX3...");
            FX3.Disconnect();
            System.Threading.Thread.Sleep(500);
            Connect();

            Console.WriteLine("Getting error log...");
            log = FX3.GetErrorLog();
            CheckLogEquality(initialLog, log, false);

            Console.WriteLine("Starting I2C Read...");
            try
            {
                FX3.I2CReadBytes(preRead, 32, 1000);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Generating new error log...");
            GenerateErrorLog();

            Console.WriteLine("Getting error log...");
            log = FX3.GetErrorLog();
            Assert.AreEqual(initialLog.Count + 1, log.Count, "ERROR: Invalid log count");
            CheckLogEquality(initialLog, log, true);
        }
Пример #7
0
        public void I2CBitRateTest()
        {
            Console.WriteLine("Starting I2C bit rate test...");

            Console.WriteLine("Testing input validation...");
            uint startingBitRate;
            int  numExpections = 0;

            startingBitRate = FX3.I2CBitRate;
            Assert.AreEqual(100000, startingBitRate, "ERROR: Invalid default I2C bit rate");
            try
            {
                FX3.I2CBitRate = 99999;
            }
            catch (Exception e)
            {
                numExpections++;
                Console.WriteLine(e.Message);
            }
            Assert.AreEqual(1, numExpections, "ERROR: Expected exception to be thrown");
            Assert.AreEqual(startingBitRate, FX3.I2CBitRate, "ERROR: Expected I2C bit rate setting to be rejected");

            try
            {
                FX3.I2CBitRate = 1000001;
            }
            catch (Exception e)
            {
                numExpections++;
                Console.WriteLine(e.Message);
            }
            Assert.AreEqual(2, numExpections, "ERROR: Expected exception to be thrown");
            Assert.AreEqual(startingBitRate, FX3.I2CBitRate, "ERROR: Expected I2C bit rate setting to be rejected");

            Console.WriteLine("Testing reads across valid bit rate range...");

            I2CPreamble pre = new I2CPreamble();

            pre.DeviceAddress = 0xA0;
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0xA1);
            pre.StartMask = 4;

            byte[] InitialRead, SecondRead;

            Console.WriteLine("Performing initial flash read...");
            const uint READ_LEN = 1024;

            InitialRead = FX3.I2CReadBytes(pre, READ_LEN, 2000);
            for (uint bitrate = 100000; bitrate <= 1000000; bitrate += 100000)
            {
                Console.WriteLine("Testing " + bitrate.ToString() + "bits/s...");
                FX3.I2CBitRate = bitrate;
                Assert.AreEqual(bitrate, FX3.I2CBitRate, "ERROR: Setting bit rate failed");
                SecondRead = FX3.I2CReadBytes(pre, READ_LEN, 2000);
                for (int i = 0; i < InitialRead.Count(); i++)
                {
                    Assert.AreEqual(InitialRead[i], SecondRead[i], "ERROR: Expected flash read data to match");
                }
            }
        }